<tbody>
{% for doc in docs.all %}
<tr>
- <td {% if forloop.first %}class="border-top"{% endif %} width="95%">{% if doc.file %}<a href="{% url teleforma-document-view doc.id %}" target="_blank" title="{% trans "View" %}"><img src="{{ STATIC_URL }}/teleforma/images/application-msword.png" style="vertical-align:middle" alt="" />{% endif %} {{ doc.title }}{% if doc.file %}</a>{% endif %}</td>
- <td {% if forloop.first %}class="border-top"{% endif %} width="5%" align="center">{% if doc.file %}<a href="{% url teleforma-document-download doc.id %}"><img src="{{ STATIC_URL }}teleforma/images/download.png" style="vertical-align:middle" alt="" title="{% trans "Download" %}" /></a>{% endif %}</td>
+ <td {% if forloop.first %}class="border-top"{% endif %} width="95%">{% if doc.file %}<a href="{% url teleforma-document-view seminar.id doc.id %}" target="_blank" title="{% trans "View" %}"><img src="{{ STATIC_URL }}/teleforma/images/application-msword.png" style="vertical-align:middle" alt="" />{% endif %} {{ doc.title }}{% if doc.file %}</a>{% endif %}</td>
+ <td {% if forloop.first %}class="border-top"{% endif %} width="5%" align="center">{% if doc.file %}<a href="{% url teleforma-document-download seminar.id doc.id %}"><img src="{{ STATIC_URL }}teleforma/images/download.png" style="vertical-align:middle" alt="" title="{% trans "Download" %}" /></a>{% endif %}</td>
</tr>
{% endfor %}
</tbody>
<tbody>
{% for doc in docs.all %}
<tr>
- <td {% if forloop.first %}class="border-top"{% endif %} width="95%">{% if doc.file %}<a href="{% url teleforma-document-view doc.id %}" target="_blank" title="{% trans "View" %}"><img src="{{ STATIC_URL }}/teleforma/images/application-msword.png" style="vertical-align:middle" alt="" />{% endif %} {{ doc.title }}{% if doc.file %}</a>{% endif %}</td>
+ <td {% if forloop.first %}class="border-top"{% endif %} width="95%">{% if doc.file %}<a href="{% url teleforma-document-view seminar.id doc.id %}" target="_blank" title="{% trans "View" %}"><img src="{{ STATIC_URL }}/teleforma/images/application-msword.png" style="vertical-align:middle" alt="" />{% endif %} {{ doc.title }}{% if doc.file %}</a>{% endif %}</td>
</tr>
{% endfor %}
</tbody>
htdocs_forma = os.path.dirname(__file__) + '/static/teleforma/'
user_export = UsersXLSExport()
profile_view = ProfileView()
-document = DocumentView()
+document = SeminarDocumentView()
media = MediaView()
urlpatterns = patterns('',
url(r'^desk/seminars/(?P<pk>.*)/detail/$', SeminarView.as_view(), name="teleforma-seminar-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/medias/(?P<pk>.*)/download/$', media.download, name="teleforma-media-download"),
url(r'^desk/seminars/(?P<id>.*)/media/(?P<pk>.*)/video/$',
SeminarMediaView.as_view(template_name='teleforma/seminar_media_video.html'),
SeminarMediaPreviewView.as_view(),
name="teleforma-media-preview-video"),
- 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/seminars/(?P<id>.*)/documents/(?P<pk>.*)/download/$', SeminarDocumentDownloadView.as_view(),
name="teleforma-document-download"),
- url(r'^desk/documents/(?P<pk>.*)/view/$', document.view,
+ url(r'^desk/seminars/(?P<id>.*)/documents/(?P<pk>.*)/view/$', SeminarDocumentView.as_view(),
name="teleforma-document-view"),
# url(r'^desk/documents/(?P<pk>.*)/view/$', document_view, name="teleforma-document-view"),
return periods
+class CourseAccessMixin(object):
+
+ def render_to_response(self, context):
+ course = context['course']
+ if not course in all_courses(self.request.user):
+ messages.warning(self.request, _("You do NOT have access to this resource and then have been redirected to your desk."))
+ return redirect('teleforma-desk')
+ return super(CourseAccessMixin, self).render_to_response(context)
+
+
class CourseView(DetailView):
model = Course
return super(CourseView, self).dispatch(*args, **kwargs)
+
class CoursesView(ListView):
model = Course
def dispatch(self, *args, **kwargs):
return super(DocumentView, self).dispatch(*args, **kwargs)
- def download(self, request, pk):
- document = Document.objects.get(id=pk)
- courses = get_courses(request.user)
- seminars = all_seminars(request)['all_seminars']
- if get_seminar_doc_access(document, seminars):
- document.readers.add(request.user)
- fsock = open(document.file.path, 'r')
- mimetype = mimetypes.guess_type(document.file.path)[0]
- extension = mimetypes.guess_extension(mimetype)
- response = HttpResponse(fsock, mimetype=mimetype)
- response['Content-Disposition'] = "attachment; filename=%s%s" % \
+
+class DocumentDownloadView(DocumentView):
+
+ def render_to_response(self, context):
+ document = self.get_object()
+ document.readers.add(self.request.user)
+ fsock = open(document.file.path, 'r')
+ mimetype = mimetypes.guess_type(document.file.path)[0]
+ extension = mimetypes.guess_extension(mimetype)
+ response = HttpResponse(fsock, mimetype=mimetype)
+ response['Content-Disposition'] = "attachment; filename=%s%s" % \
(document.title.encode('utf8'), extension)
- return response
- else:
- return redirect('teleforma-document-detail', document.id)
+ return super(DocumentDownloadView, self).render_to_response(context)
- def view(self, request, pk):
- courses = get_courses(request.user)
- seminars = all_seminars(request)['all_seminars']
- document = Document.objects.get(id=pk)
- if get_seminar_doc_access(document, seminars):
- document.readers.add(request.user)
- fsock = open(document.file.path, 'r')
- mimetype = mimetypes.guess_type(document.file.path)[0]
- extension = mimetypes.guess_extension(mimetype)
- response = HttpResponse(fsock, mimetype=mimetype)
- return response
- else:
- return redirect('teleforma-document-detail', document.id)
+
+class DocumentReadView(DocumentView):
+
+ def render_to_response(self, context):
+ courses = get_courses(self.request.user)
+ document = self.get_object()
+ document.readers.add(self.request.user)
+ fsock = open(document.file.path, 'r')
+ mimetype = mimetypes.guess_type(document.file.path)[0]
+ extension = mimetypes.guess_extension(mimetype)
+ response = HttpResponse(fsock, mimetype=mimetype)
+ return super(DocumentReadView, self).render_to_response(context)
class ConferenceView(DetailView):
set_revision(user, seminar)
return context
- def get_object(self, queryset=None):
- return Media.objects.get(id=self.pk)
-
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
- self.pk = kwargs.get('pk')
- media = self.get_object()
return super(SeminarMediaView, self).dispatch(*args, **kwargs)
+class SeminarDocumentView(SeminarAccessMixin, DocumentReadView):
+
+ def get_context_data(self, **kwargs):
+ context = super(SeminarDocumentView, self).get_context_data(**kwargs)
+ user = self.request.user
+ seminar = Seminar.objects.get(pk=self.kwargs['id'])
+ context['seminar'] = seminar
+ set_revision(user, seminar)
+ return context
+
+ @method_decorator(login_required)
+ def dispatch(self, *args, **kwargs):
+ return super(SeminarDocumentView, self).dispatch(*args, **kwargs)
+
+
+class SeminarDocumentDownloadView(SeminarAccessMixin, DocumentDownloadView):
+
+ def get_context_data(self, **kwargs):
+ context = super(SeminarDocumentDownloadView, self).get_context_data(**kwargs)
+ user = self.request.user
+ seminar = Seminar.objects.get(pk=self.kwargs['id'])
+ context['seminar'] = seminar
+ set_revision(user, seminar)
+ return context
+
+ @method_decorator(login_required)
+ def dispatch(self, *args, **kwargs):
+ return super(SeminarDocumentDownloadView, self).dispatch(*args, **kwargs)
+
+
class SeminarMediaPreviewView(DetailView):
model = Seminar
def dispatch(self, *args, **kwargs):
return super(SeminarMediaPreviewView, self).dispatch(*args, **kwargs)
+
class AnswersView(ListView):
model = Answer