# HG changeset patch # User cavaliet # Date 1355416040 -3600 # Node ID 5e50a61acf4c34291bc95b566ab256d2d5a12ec5 # Parent f60f05ce77fe8e4a107cd5c6ed501ed7945503d4 add dumpdata view in ldt_utils admin. diff -r f60f05ce77fe -r 5e50a61acf4c src/ldt/ldt/ldt_utils/admin.py --- a/src/ldt/ldt/ldt_utils/admin.py Thu Dec 13 14:33:48 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/admin.py Thu Dec 13 17:27:20 2012 +0100 @@ -8,6 +8,10 @@ from ldt.ldt_utils.models import Content, Project, Media, Author from ldt.ldt_utils.stat import update_stat_content from guardian.admin import GuardedModelAdmin +from django.http import HttpResponse +from StringIO import StringIO +from django.core.management import call_command +import logging class ProjectAdmin(GuardedModelAdmin): @@ -95,18 +99,38 @@ form = StatAnnotationForm() return render_to_response('admin/ldt_utils/content/stats_form.html', {'form': form, 'message':message, 'current_app': self.admin_site.name, 'current_action' : 'stats' }, context_instance=RequestContext(request)) - + + + def dumpdata(self, request): + # do we dump the datas ? + dump_str = request.REQUEST.get("dump") + app_str = request.REQUEST.get("app", "") + dump_bool = False + if dump_str: + dump_bool = {'true': True, 'false': False, "0": False, "1": True}.get(dump_str.lower()) + if dump_bool: + content = StringIO() + if app_str=="": + call_command("dumpdata", indent=1, stdout=content) + else: + call_command("dumpdata", app_str, indent=1, stdout=content) + content.seek(0) + out = content.getvalue() + content.close() + res = HttpResponse(out, mimetype='application/json') + res["Content-Disposition"] = "attachment; filename=dumpdata_ldt.json" + return res + return render_to_response('admin/ldt_utils/content/dumpdata.html', {}, context_instance=RequestContext(request)) + def get_urls(self): urls = super(ContentAdmin, self).get_urls() content_urls = patterns('', url(r'^reindex/$', self.admin_site.admin_view(self.reindex), name="ldt_content_reindex"), - # (r'^admin/ldt/content/import/upload/$', 'ldt.ldt_utils.views.uploadFile'), url(r'^import/$', self.admin_site.admin_view(self.import_file), name="ldt_content_import_file"), - url(r'^stats/$', self.admin_site.admin_view(self.stats_annotations), name="ldt_project_compute_stats") - + url(r'^stats/$', self.admin_site.admin_view(self.stats_annotations), name="ldt_project_compute_stats"), + url(r'^dumpdata/$', self.admin_site.admin_view(self.dumpdata), name="ldt_admin_dump_data"), ) - return content_urls + urls diff -r f60f05ce77fe -r 5e50a61acf4c src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/app_index.html --- a/src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/app_index.html Thu Dec 13 14:33:48 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/app_index.html Thu Dec 13 17:27:20 2012 +0100 @@ -14,26 +14,32 @@ Import Import - an ldt + an ldt + +   + + + Reindex + +   + + + Compute stats +   - - - Reindex - -   - - - Compute stats - -   - + +
+ + + + + + +
Data
Dump data +  
+
{% endblock %} diff -r f60f05ce77fe -r 5e50a61acf4c src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/content/dumpdata.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/content/dumpdata.html Thu Dec 13 17:27:20 2012 +0100 @@ -0,0 +1,16 @@ +{% extends "admin/ldt_utils/app_action.html" %} +{% load i18n %} +{% load absurl %} +{# DUMP DATA #} +{% block content %} +{% if message %} +
+

{{ message }}

+
+{% endif %} +
+

Click HERE if you want to download the dumpdata's json. It can be long to load. The dumpdata is full and raw, without natural keys.

+
+ +Back to administration page +{% endblock %}