Skip to content

Commit

Permalink
prepared video downloading in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
randomknowledge committed Apr 4, 2013
1 parent eefce83 commit 26f5efe
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
44 changes: 43 additions & 1 deletion django_webvideo/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def save_model(self, request, obj, form, change):
obj.save()

def queryset(self, request):
if request.user.is_superuser:
return super(OwnerAdmin, self).queryset(request)
return super(OwnerAdmin, self).queryset(request).filter(owner=request.user)


Expand Down Expand Up @@ -157,6 +159,19 @@ class WebVideoAdmin(OwnerAdmin):
'bitrate',
'framerate',
)

su_list_display = (
'video',
'owner',
'admin_thumb',
'admin_filesize',
'duration',
'width',
'height',
'bitrate',
'framerate',
)

list_display_links = (
'video',
'admin_filesize',
Expand All @@ -179,8 +194,23 @@ class WebVideoAdmin(OwnerAdmin):
'codecs',
'qualities',
)
su_edit_fields = (
'video',
'owner',
'admin_video',
'admin_filesize',
'duration',
'width',
'height',
'bitrate',
'framerate',
'converted_list_admin',
'codecs',
'qualities',
)
edit_readonly_fields = (
'admin_video',
'owner',
'admin_filesize',
'duration',
'width',
Expand All @@ -200,13 +230,25 @@ class WebVideoAdmin(OwnerAdmin):

form = WebVideoForm

def get_list_filter(self, request):
if request.user.is_superuser:
return ('owner',)
return ()

def get_list_display(self, request):
if request.user.is_superuser:
return self.su_list_display
return self.list_display

def get_readonly_fields(self, request, obj=None):
if obj: # Editing
return self.edit_readonly_fields
return ()#('admin_video', 'admin_filesize', 'converted_list_admin')

def get_fieldsets(self, request, obj=None):
if obj: # Editing
if request.user.is_superuser:
return [(None, {'fields': self.su_edit_fields})]
return [(None, {'fields': self.edit_fields})]
return [(None, {'fields': ('video', 'target_codecs', 'target_qualities',)})]

Expand Down Expand Up @@ -277,7 +319,7 @@ class ConvertedVideoAdmin(OwnerAdmin):
'bitrate',
'framerate',
)
list_filter = ('codec', 'quality', )
list_filter = ('codec', 'quality')

admin_thumb = admin_thumb_helper_video(width=50, height=30)
admin_video = admin_video_helper()
Expand Down
3 changes: 2 additions & 1 deletion django_webvideo/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
except ImportError:
pass
else:
TEMPLATE_CONTEXT_PROCESSORS += ('django_webvideo.context_processors.suit',)
INSTALLED_APPS = ['suit', ] + INSTALLED_APPS
SUIT_CONFIG = {
'ADMIN_NAME': _('Django Webvideo'),
Expand All @@ -124,4 +125,4 @@
('auth', ('user','group')),
('django_webvideo', ('webvideo','convertedvideo', 'videoscreen')),
),
}
}
5 changes: 5 additions & 0 deletions django_webvideo/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# coding: utf-8


def suit(request):
return {'has_django_suit': True}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "admin/change_form.html" %}
{% load i18n %}
{% block object-tools-items %}
{% if original.converted.all %}
{% for conv in original.converted.all %}
<li>
<a href="{{ conv.video.url }}">
{% if has_django_suit %}
<i class="icon-download icon-alpha75"></i>
{% else %}
{% trans 'Download' %}
{% endif %}
{{ conv.codec }}, {{ conv.quality }}
</a>
</li>
{% endfor %}
{% if has_django_suit %}
<li><br/></li>
{% endif %}
{% endif %}
{{ block.super }}
{% endblock %}

0 comments on commit 26f5efe

Please sign in to comment.