<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 %}
user_export = UsersXLSExport()
profile_view = ProfileView()
document = DocumentView()
+media = MediaView()
urlpatterns = patterns('',
# url(r'^$', HomeView.as_view(), name='teleforma-home'),
# 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,
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"),
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):
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")