summaryrefslogtreecommitdiff
path: root/app/lib/upload/admin.py
diff options
context:
space:
mode:
authorlxf <sng@luxagraf.net>2022-05-14 16:38:07 -0400
committerlxf <sng@luxagraf.net>2022-05-14 16:38:07 -0400
commitbb3973ffb714c932e9ec6dd6a751228dc71fe1d3 (patch)
tree6fa32f9392ad2ec32271349b86a4c1388fd6ba95 /app/lib/upload/admin.py
initial commit
Diffstat (limited to 'app/lib/upload/admin.py')
-rw-r--r--app/lib/upload/admin.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/app/lib/upload/admin.py b/app/lib/upload/admin.py
new file mode 100644
index 0000000..9d8a2b2
--- /dev/null
+++ b/app/lib/upload/admin.py
@@ -0,0 +1,50 @@
+from django.contrib import admin
+from django.utils.translation import ugettext as _
+from django.http import Http404, HttpResponse, HttpResponseRedirect
+from django.utils.encoding import force_unicode
+from django.utils.html import escape
+from upload.models import FileUpload
+from django.conf import settings
+
+
+class UploadAdmin(admin.ModelAdmin):
+ list_display = ('title','upload_date','upload', 'content_type')
+ search_fields = ['title',]
+ list_filter = ('upload_date', 'content_type')
+ fieldsets = (
+ (None, {'fields': ('upload','title','description')}),
+ )
+ class Media:
+ js = ['%s/admin/jquery/jquery-1.3.2.min.js' % (settings.MEDIA_URL), '%s/admin/custom/photo-edit.js' % (settings.MEDIA_URL)]
+
+ def response_change(self, request, obj):
+ """
+ Determines the HttpResponse for the change_view stage.
+ """
+ opts = obj._meta
+ pk_value = obj._get_pk_val()
+
+ msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj)}
+ if request.POST.has_key("_continue"):
+ self.message_user(request, msg + ' ' + _("You may edit it again below."))
+ if request.REQUEST.has_key('_popup'):
+ return HttpResponseRedirect(request.path + "?_popup=1")
+ else:
+ return HttpResponseRedirect(request.path)
+ elif request.POST.has_key("_saveasnew"):
+ msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': obj}
+ self.message_user(request, msg)
+ return HttpResponseRedirect("../%s/" % pk_value)
+ elif request.POST.has_key("_addanother"):
+ self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)))
+ return HttpResponseRedirect("../add/")
+ elif request.POST.has_key("_popup"):
+ return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' % \
+ # escape() calls force_unicode.
+ (escape(pk_value), escape(obj)))
+ else:
+ self.message_user(request, msg)
+ return HttpResponseRedirect("../")
+
+
+admin.site.register(FileUpload, UploadAdmin) \ No newline at end of file