Skip to content

Commit

Permalink
- [WIP] Hide non processed resources
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Apr 1, 2021
1 parent 7b46b2f commit 10e7041
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
8 changes: 2 additions & 6 deletions geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,8 @@ def apply_filters(self, request, applicable_filters):

# Hide Dirty State Resources
user = request.user if request else None
if not user or not user.is_superuser:
if user:
filtered = filtered.exclude(Q(dirty_state=True) & ~(
Q(owner__username__iexact=str(user))))
else:
filtered = filtered.exclude(Q(dirty_state=True))
if not user or not user.is_authenticated or not user.is_superuser:
filtered = filtered.exclude(Q(dirty_state=True))
return filtered

def filter_published(self, queryset, request):
Expand Down
3 changes: 2 additions & 1 deletion geonode/base/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ def __init__(self, *args, **kwargs):
self.fields['raw_supplemental_information'] = serializers.CharField(read_only=True)
self.fields['raw_data_quality_statement'] = serializers.CharField(read_only=True)
self.fields['metadata_only'] = serializers.BooleanField()
self.fields['processed'] = serializers.BooleanField(read_only=True)

self.fields['embed_url'] = EmbedUrlField()
self.fields['thumbnail_url'] = ThumbnailUrlField()
Expand Down Expand Up @@ -290,7 +291,7 @@ class Meta:
'popular_count', 'share_count', 'rating', 'featured', 'is_published', 'is_approved',
'detail_url', 'embed_url', 'created', 'last_updated',
'raw_abstract', 'raw_purpose', 'raw_constraints_other',
'raw_supplemental_information', 'raw_data_quality_statement', 'metadata_only'
'raw_supplemental_information', 'raw_data_quality_statement', 'metadata_only', 'processed'
# TODO
# csw_typename, csw_schema, csw_mdsource, csw_insert_date, csw_type, csw_anytext, csw_wkt_geometry,
# metadata_uploaded, metadata_uploaded_preserve, metadata_xml,
Expand Down
8 changes: 6 additions & 2 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,12 +1235,16 @@ def spatial_representation_type_string(self):
def set_dirty_state(self):
if not self.dirty_state:
self.dirty_state = True
self.save()
ResourceBase.objects.filter(id=self.id).update(dirty_state=True)

def clear_dirty_state(self):
if self.dirty_state:
self.dirty_state = False
self.save()
ResourceBase.objects.filter(id=self.id).update(dirty_state=False)

@property
def processed(self):
return not self.dirty_state

@property
def keyword_csv(self):
Expand Down
2 changes: 2 additions & 0 deletions geonode/geoserver/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ def geoserver_post_save_layers(

geonode_upload_sessions = UploadSession.objects.filter(resource=instance)
geonode_upload_sessions.update(processed=False)
instance.set_dirty_state()

gs_resource = None
values = None
Expand Down Expand Up @@ -637,6 +638,7 @@ def geoserver_post_save_layers(
try:
geonode_upload_sessions = UploadSession.objects.filter(resource=instance)
geonode_upload_sessions.update(processed=True)
instance.clear_dirty_state()
except Exception as e:
logger.exception(e)

Expand Down
8 changes: 6 additions & 2 deletions geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,13 @@ def get_upload_session(self):
def processed(self):
self.upload_session = UploadSession.objects.filter(resource=self).first()
if self.upload_session:
return self.upload_session.processed
if self.upload_session.processed:
self.clear_dirty_state()
else:
self.set_dirty_state()
else:
return True
self.clear_dirty_state()
return not self.dirty_state

@property
def display_type(self):
Expand Down
7 changes: 1 addition & 6 deletions geonode/security/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ def get_visible_resources(queryset,
filter_set = filter_set.exclude(group__in=private_groups)

# Hide Dirty State Resources
if user and user.is_authenticated:
filter_set = filter_set.exclude(
Q(dirty_state=True) & ~(
Q(owner__username__iexact=str(user)) | Q(group__in=group_list_all))
)
else:
if not user or not user.is_authenticated or not user.is_superuser:
filter_set = filter_set.exclude(Q(dirty_state=True))

if admin_approval_required or unpublished_not_visible or private_groups_not_visibile:
Expand Down

0 comments on commit 10e7041

Please sign in to comment.