Skip to content

Commit

Permalink
revert: Remove export to JSON button from section change form
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor committed Jan 22, 2024
1 parent 938f756 commit e41873b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 27 deletions.
20 changes: 1 addition & 19 deletions backend/section/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PlaylistAdmin(InlineActionsModelAdminMixin, admin.ModelAdmin):
list_display = ('name', 'section_count', 'experiment_count')
search_fields = ['name', 'section__song__artist', 'section__song__name']
inline_actions = ['add_sections',
'edit_sections', 'export_json', 'export_csv']
'edit_sections', 'export_csv']

def save_model(self, request, obj, form, change):

Expand Down Expand Up @@ -160,19 +160,6 @@ def edit_sections(self, request, obj, parent_obj=None):
'sections': sections}
)

def export_json(self, request, obj, parent_obj=None):
"""Export playlist data in JSON, force download"""

response = JsonResponse(
obj.export_admin(), json_dumps_params={'indent': 4})

# force download attachment
response['Content-Disposition'] = 'attachment; filename="playlist_' + \
str(obj.id)+'.json"'
return response

export_json.short_description = "Export JSON"

def export_csv(self, request, obj, parent_obj=None):
"""Export playlist sections to csv, force download"""

Expand All @@ -193,15 +180,10 @@ def export_csv_view(self, request, pk):
obj = self.get_object(request, pk)
return self.export_csv(request, obj)

def export_json_view(self, request, pk):
obj = self.get_object(request, pk)
return self.export_json(request, obj)

def get_urls(self):
urls = super().get_urls()
custom_urls = [
path('<int:pk>/export_csv/', self.export_csv_view, name='section_playlist_export_csv'),
path('<int:pk>/export_json/', self.export_json_view, name='section_playlist_export_json'),
]
return custom_urls + urls

Expand Down
1 change: 0 additions & 1 deletion backend/section/templates/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@
{% block after_field_sets %}
<div class="custom-actions">
<a href="{% url 'admin:section_playlist_export_csv' original.pk %}" class="button">Export to CSV</a>
<a href="{% url 'admin:section_playlist_export_json' original.pk %}" class="button">Export to JSON</a>
</div>
{% endblock %}
7 changes: 0 additions & 7 deletions backend/section/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@ def test_export_csv(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'text/csv')

def test_export_json(self):
url = reverse('admin:section_playlist_export_json', args=[self.playlist.pk])
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'application/json')


class PlaylistAdminFormTest(TestCase):

def setUp(self):
Expand Down

0 comments on commit e41873b

Please sign in to comment.