Skip to content

Commit c24abb2

Browse files
authored
[ENG-6223] chore: remove 'old' institution dashboard stuff (#11365)
1 parent 30b96ab commit c24abb2

File tree

17 files changed

+113
-1190
lines changed

17 files changed

+113
-1190
lines changed

api/base/pagination.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ def paginate_queryset(self, queryset, request, view=None):
167167
return super().paginate_queryset(queryset, request, view=None)
168168

169169

170+
class JSONAPINoPagination(pagination.BasePagination):
171+
'''do not accept page params nor paginate the queryset, but (for consistency with
172+
JSONAPIPagination) do format the data into a jsonapi doc
173+
174+
possible future improvement: format jsonapi docs somewhere more reasonable
175+
(like the renderer?) and delete this pagination class
176+
'''
177+
def paginate_queryset(self, queryset, request, view=None):
178+
return queryset # let it be
179+
180+
def get_paginated_response(self, data):
181+
return Response({
182+
'data': data,
183+
'meta': {'total': len(data)},
184+
})
185+
186+
170187
class MaxSizePagination(JSONAPIPagination):
171188
page_size = 1000
172189
max_page_size = None

api/base/utils.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -266,27 +266,6 @@ def assert_resource_type(obj, resource_tuple):
266266
assert isinstance(obj, resource_tuple), f'obj must be {a_or_an} {error_message}; got {obj}'
267267

268268

269-
class MockQueryset(list):
270-
"""
271-
This class is meant to convert a simple list into a filterable queryset look-a-like.
272-
"""
273-
274-
def __init__(self, items, search, default_attrs=None, **kwargs):
275-
self.search = search
276-
277-
for item in items:
278-
if default_attrs:
279-
item.update(default_attrs)
280-
self.add_dict_as_item(item)
281-
282-
def __len__(self):
283-
return self.search.count()
284-
285-
def add_dict_as_item(self, dict):
286-
item = type('item', (object,), dict)
287-
self.append(item)
288-
289-
290269
def toggle_view_by_flag(flag_name, old_view, new_view):
291270
'''toggle between view implementations based on a feature flag
292271

api/institutions/renderers.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

api/institutions/serializers.py

Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from api.base.serializers import YearmonthField
2222
from api.nodes.serializers import CompoundIDField
2323
from api.base.exceptions import RelationshipPostMakesNoChanges
24-
from api.base.utils import absolute_reverse
2524

2625

2726
class InstitutionSerializer(JSONAPISerializer):
@@ -205,30 +204,6 @@ def create(self, validated_data):
205204
}
206205

207206

208-
class InstitutionSummaryMetricSerializer(JSONAPISerializer):
209-
210-
class Meta:
211-
type_ = 'institution-summary-metrics'
212-
213-
id = IDField(source='institution_id', read_only=True)
214-
public_project_count = ser.IntegerField(read_only=True)
215-
private_project_count = ser.IntegerField(read_only=True)
216-
user_count = ser.IntegerField(read_only=True)
217-
218-
links = LinksField({
219-
'self': 'get_absolute_url',
220-
})
221-
222-
def get_absolute_url(self, obj):
223-
return absolute_reverse(
224-
'institutions:institution-summary-metrics',
225-
kwargs={
226-
'institution_id': self.context['request'].parser_context['kwargs']['institution_id'],
227-
'version': 'v2',
228-
},
229-
)
230-
231-
232207
class UniqueDeptIDField(CompoundIDField):
233208
"""Creates a unique department ID of the form "<institution-id>-<dept-id>"."""
234209

@@ -255,74 +230,9 @@ class Meta:
255230
name = ser.CharField(read_only=True)
256231
number_of_users = ser.IntegerField(read_only=True)
257232

258-
links = LinksField({
259-
'self': 'get_absolute_url',
260-
})
261-
262-
filterable_fields = frozenset([
263-
'id',
264-
'name',
265-
'number_of_users',
266-
])
267233

268-
def get_absolute_url(self, obj):
269-
return absolute_reverse(
270-
'institutions:institution-department-metrics',
271-
kwargs={
272-
'institution_id': self.context['request'].parser_context['kwargs']['institution_id'],
273-
'version': 'v2',
274-
},
275-
)
276-
277-
278-
class OldInstitutionUserMetricsSerializer(JSONAPISerializer):
234+
class InstitutionUserMetricsSerializer(JSONAPISerializer):
279235
'''serializer for institution-users metrics
280-
281-
used only when the INSTITUTIONAL_DASHBOARD_2024 feature flag is NOT active
282-
(and should be removed when that flag is permanently active)
283-
'''
284-
285-
class Meta:
286-
type_ = 'institution-users'
287-
288-
id = IDField(source='user_id', read_only=True)
289-
user_name = ser.CharField(read_only=True)
290-
public_projects = ser.IntegerField(source='public_project_count', read_only=True)
291-
private_projects = ser.IntegerField(source='private_project_count', read_only=True)
292-
department = ser.CharField(read_only=True)
293-
294-
user = RelationshipField(
295-
related_view='users:user-detail',
296-
related_view_kwargs={'user_id': '<user_id>'},
297-
)
298-
299-
links = LinksField({
300-
'self': 'get_absolute_url',
301-
})
302-
303-
filterable_fields = frozenset([
304-
'id',
305-
'user_name',
306-
'public_projects',
307-
'private_projects',
308-
'department',
309-
])
310-
311-
def get_absolute_url(self, obj):
312-
return absolute_reverse(
313-
'institutions:institution-user-metrics',
314-
kwargs={
315-
'institution_id': self.context['request'].parser_context['kwargs']['institution_id'],
316-
'version': 'v2',
317-
},
318-
)
319-
320-
321-
class NewInstitutionUserMetricsSerializer(JSONAPISerializer):
322-
'''serializer for institution-users metrics
323-
324-
used only when the INSTITUTIONAL_DASHBOARD_2024 feature flag is active
325-
(and should be renamed without "New" when that flag is permanently active)
326236
'''
327237

328238
class Meta:
@@ -360,11 +270,6 @@ class Meta:
360270
)
361271
contacts = ser.SerializerMethodField()
362272

363-
links = LinksField({})
364-
365-
def get_absolute_url(self):
366-
return None # there is no detail view for institution-users
367-
368273
def get_contacts(self, obj):
369274
user = OSFUser.load(obj._d_['user_id'])
370275
if not user:
@@ -381,11 +286,8 @@ def get_contacts(self, obj):
381286
return list(results)
382287

383288

384-
class NewInstitutionSummaryMetricsSerializer(JSONAPISerializer):
289+
class InstitutionSummaryMetricsSerializer(JSONAPISerializer):
385290
'''serializer for institution-summary metrics
386-
387-
used only when the INSTITUTIONAL_DASHBOARD_2024 feature flag is active
388-
(and should be renamed without "New" when that flag is permanently active)
389291
'''
390292

391293
class Meta:
@@ -414,11 +316,6 @@ class Meta:
414316
related_view_kwargs={'institution_id': '<institution_id>'},
415317
)
416318

417-
links = LinksField({})
418-
419-
def get_absolute_url(self):
420-
return None # there is no detail view for institution-users
421-
422319

423320
class InstitutionRelated(JSONAPIRelationshipSerializer):
424321
id = ser.CharField(source='_id', required=False, allow_null=True)

api/institutions/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
re_path(r'^(?P<institution_id>\w+)/relationships/registrations/$', views.InstitutionRegistrationsRelationship.as_view(), name=views.InstitutionRegistrationsRelationship.view_name),
1414
re_path(r'^(?P<institution_id>\w+)/relationships/nodes/$', views.InstitutionNodesRelationship.as_view(), name=views.InstitutionNodesRelationship.view_name),
1515
re_path(r'^(?P<institution_id>\w+)/users/$', views.InstitutionUserList.as_view(), name=views.InstitutionUserList.view_name),
16-
re_path(r'^(?P<institution_id>\w+)/metrics/summary/$', views.institution_summary_metrics_detail_view, name=views.institution_summary_metrics_detail_view.view_name),
16+
re_path(r'^(?P<institution_id>\w+)/metrics/summary/$', views.InstitutionSummaryMetricsDetail.as_view(), name=views.InstitutionSummaryMetricsDetail.view_name),
1717
re_path(r'^(?P<institution_id>\w+)/metrics/departments/$', views.InstitutionDepartmentList.as_view(), name=views.InstitutionDepartmentList.view_name),
18-
re_path(r'^(?P<institution_id>\w+)/metrics/users/$', views.institution_user_metrics_list_view, name=views.institution_user_metrics_list_view.view_name),
18+
re_path(r'^(?P<institution_id>\w+)/metrics/users/$', views.InstitutionUserMetricsList.as_view(), name=views.InstitutionUserMetricsList.view_name),
1919
]

0 commit comments

Comments
 (0)