]> git.parisson.com Git - teleforma.git/commitdiff
add download buttons & views for media
authoryomguy <yomguy@parisson.com>
Wed, 20 Jun 2012 11:01:38 +0000 (13:01 +0200)
committeryomguy <yomguy@parisson.com>
Wed, 20 Jun 2012 11:01:38 +0000 (13:01 +0200)
teleforma/static/teleforma/images/down_arrow.png [new file with mode: 0644]
teleforma/static/teleforma/images/download_media.png [new file with mode: 0644]
teleforma/templates/teleforma/inc/media_list.html
teleforma/urls.py
teleforma/views.py

diff --git a/teleforma/static/teleforma/images/down_arrow.png b/teleforma/static/teleforma/images/down_arrow.png
new file mode 100644 (file)
index 0000000..50ed141
Binary files /dev/null and b/teleforma/static/teleforma/images/down_arrow.png differ
diff --git a/teleforma/static/teleforma/images/download_media.png b/teleforma/static/teleforma/images/download_media.png
new file mode 100644 (file)
index 0000000..e4ef0b5
Binary files /dev/null and b/teleforma/static/teleforma/images/download_media.png differ
index 6fc2200c5b38107d98af1c116f4e3a17491ee6f7..dced86bffb0566b345f036f84158e08ae46766a1 100644 (file)
@@ -14,7 +14,7 @@
             <td {% if forloop.counter0 == 0 %}class="border-top"{% endif %} width="40%"><a href="{% url teleforma-media-detail media.id %}" title="{% trans "View" %}"><img src="{{ STATIC_URL }}/teleforma/images/tool-animator.png" style="vertical-align:middle" alt="" /> {{ media.title }} - {{ media.conference.session }}</a></td>
             <td {% if forloop.counter0 == 0 %}class="border-top"{% endif %} width="20%">{% if media.conference.professor.user %}<a href="{% url teleforma-profile-detail media.conference.professor.user.username %}" target="_blank">{{ media.conference.professor }}</a>{% endif %}</td>
             <td {% if forloop.counter0 == 0 %}class="border-top"{% endif %} width="35%">{% if media.conference.date_begin %}{{ media.conference.date_begin }}{% endif %}</td>
-            <td {% if forloop.counter0 == 0 %}class="border-top"{% endif %} width="5%"></td>
+            <td {% if forloop.counter0 == 0 %}class="border-top"{% endif %} width="5%" align="center">{% if media.item.file %}<a href="{% url teleforma-media-download media.id %}"><img src="{{ STATIC_URL }}teleforma/images/download_media.png" style="vertical-align:middle" alt="" title="{% trans "Download" %}" /></a>{% endif %}</td>
             </tr>
          {% endif %}
         {% endfor %}
index 86af5fbdf9b97c3e6a4fc06899d4b904b2374387..0588529990bf0a5811f9d1965831648025392c02 100644 (file)
@@ -45,6 +45,7 @@ htdocs_forma = os.path.dirname(__file__) + '/static/teleforma/'
 user_export = UsersXLSExport()
 profile_view = ProfileView()
 document = DocumentView()
+media = MediaView()
 
 urlpatterns = patterns('',
 #    url(r'^$', HomeView.as_view(), name='teleforma-home'),
@@ -57,7 +58,10 @@ urlpatterns = patterns('',
     # Desk
     url(r'^desk/$', CoursesView.as_view(), name="teleforma-desk"),
     url(r'^desk/courses/(?P<pk>.*)/$', CourseView.as_view(), name="teleforma-course-detail"),
-    url(r'^desk/medias/(?P<pk>.*)/$', MediaView.as_view(), name="teleforma-media-detail"),
+
+    url(r'^desk/medias/(?P<pk>.*)/detail/$', MediaView.as_view(), name="teleforma-media-detail"),
+    url(r'^desk/medias/(?P<pk>.*)/download/$', media.download, name="teleforma-media-download"),
+
     url(r'^desk/documents/(?P<pk>.*)/detail/$', DocumentView.as_view(),
         name="teleforma-document-detail"),
     url(r'^desk/documents/(?P<pk>.*)/download/$', document.download,
@@ -65,6 +69,7 @@ urlpatterns = patterns('',
     url(r'^desk/documents/(?P<pk>.*)/view/$', document.view,
         name="teleforma-document-view"),
 #    url(r'^desk/documents/(?P<pk>.*)/view/$', document_view, name="teleforma-document-view"),
+
     url(r'^desk/conferences/(?P<pk>.*)/$', ConferenceView.as_view(),
         name="teleforma-conference-detail"),
 
index 2766d762d293b208b1e88e4dd595665577bfea95..0c357580b0b696e38cdc724c256a92a164b99c2d 100755 (executable)
@@ -223,6 +223,26 @@ class MediaView(DetailView):
     def dispatch(self, *args, **kwargs):
         return super(MediaView, self).dispatch(*args, **kwargs)
 
+    def download(self, request, pk):
+        courses = get_courses(request.user)
+        media = Media.objects.get(id=pk)
+        if get_access(media, courses):
+            path = media.item.file.path
+            filename, ext = os.path.splitext(path)
+            filename = filename.split(os.sep)[-1]
+            fsock = open(media.item.file.path, 'r')
+            view = ItemView()
+            mimetype = view.item_analyze(media.item)
+            extension = mimetypes.guess_extension(mimetype)
+            if not extension:
+                extension = ext
+            response = HttpResponse(fsock, mimetype=mimetype)
+
+            response['Content-Disposition'] = "attachment; filename=%s%s" % \
+                                             (filename.encode('utf8'), extension)
+            return response
+        else:
+            return redirect('teleforma-media-detail', media.id)
 
 class DocumentView(DetailView):
 
@@ -235,7 +255,6 @@ class DocumentView(DetailView):
         all_courses = get_courses(self.request.user)
         context['all_courses'] = all_courses
         document = self.get_object()
-#        context['mime_type'] = view.item_analyze(media.item)
         context['course'] = document.course
         context['notes'] = document.notes.all().filter(author=self.request.user)
         content_type = ContentType.objects.get(app_label="teleforma", model="document")