Skip to content

Commit

Permalink
fix: change API for new sidebar design
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley committed Sep 16, 2024
1 parent f8d8913 commit 55076e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 0 additions & 8 deletions uvdat/core/models/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ def run(self, **kwargs):
{
'name': 'network',
'type': Network,
'options_annotations': {
'nodes_count': models.Count('nodes'),
'edges_count': models.Count('edges'),
},
'options_query': {
'nodes_count__gte': 1,
'edges_count__gte': 1,
},
},
{
'name': 'elevation_data',
Expand Down
2 changes: 1 addition & 1 deletion uvdat/core/rest/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def filter_queryset(self, request, queryset, view):
user = request.user
valid_ids = [o.id for o in queryset]
if project_id:
valid_ids = [o.id for o in queryset if o.is_in_project(project_id)]
valid_ids = [o.id for o in queryset if o.is_in_project(int(project_id))]

if request.method == 'GET':
valid_ids = [o.id for o in queryset if o.readable_by(user) and o.id in valid_ids]
Expand Down
9 changes: 9 additions & 0 deletions uvdat/core/rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@ class ProjectSerializer(serializers.ModelSerializer):
owner = UserSerializer(allow_null=True, required=False)
collaborators = UserSerializer(many=True, required=False)
followers = UserSerializer(many=True, required=False)
item_counts = serializers.SerializerMethodField('get_item_counts')

def get_center(self, obj):
# Web client expects Lon, Lat
if obj.default_map_center:
return [obj.default_map_center.y, obj.default_map_center.x]

def get_item_counts(self, obj):
return {
'datasets': obj.datasets.count(),
'regions': obj.derived_regions.count(),
'charts': obj.charts.count(),
'simulations': obj.simulation_results.count(),
}

def to_internal_value(self, data):
center = data.get('default_map_center')
data = super().to_internal_value(data)
Expand Down

0 comments on commit 55076e1

Please sign in to comment.