]> git.parisson.com Git - telemeta.git/commitdiff
add password form for EPUB download access
authorGuillaume Pellerin <yomguy@parisson.com>
Thu, 23 Jul 2015 13:42:18 +0000 (15:42 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Thu, 23 Jul 2015 13:42:35 +0000 (15:42 +0200)
12 files changed:
telemeta/forms/media.py
telemeta/static/telemeta/css/telemeta.css
telemeta/static/telemeta/css/telemeta_epub.css
telemeta/templates/telemeta/base.html
telemeta/templates/telemeta/inc/epub_list.html [new file with mode: 0644]
telemeta/templates/telemeta/resource_epub_list.html [new file with mode: 0644]
telemeta/templates/telemeta/resource_epub_login.html [new file with mode: 0644]
telemeta/templates/telemeta/resource_epub_password.html [new file with mode: 0644]
telemeta/urls.py
telemeta/views/collection.py
telemeta/views/epub.py
telemeta/views/resource.py

index d41aa13f6f483a9e9798aeb5ce1305dfabcc2e14..f9c3e11b8273d23e6ee2d2fcaa5900c22918d41a 100644 (file)
@@ -39,7 +39,7 @@ from telemeta.models import *
 from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet
 from extra_views.generic import GenericInlineFormSet
 from django.forms.widgets import HiddenInput
-
+from django.utils.translation import ugettext_lazy as _
 
 class MediaFondsForm(ModelForm):
 
@@ -163,3 +163,8 @@ class ItemIdentifierInline(InlineFormSet):
     model = MediaItemIdentifier
     max_num = 1
 
+
+class EpubPasswordForm(forms.Form):
+
+    password = forms.CharField(label=_('password'))
+
index 7af24b54dd958d86a45fa1ffbd5a650f66957cca..9eabe05d305d700c43f6108ad80e7dedf1e79985 100644 (file)
@@ -262,11 +262,12 @@ ul.continents ul li a { line-height: 1.8em; }
 /* Collection */
 #content .intro {
     font-size: 1em;
-    font-weight: bold;
+    /*font-weight: bold;*/
     color: #444;
     margin: 5px 0;
-    font-size: 0.8em;
+    width: 400px;
 }
+
 #content .intro span {
     padding: 3px;
 
index 6cafd50c41bcbdceba82f7952bd5b35bf8dcc332..a2367c82323201e46046b6c742991aaf48328d39 100644 (file)
@@ -70,4 +70,8 @@ img {
     padding-top : 18%;
     page-break-before: always;
     text-align: center;
-}
\ No newline at end of file
+}
+
+.error {
+    color: red;
+}
index 51dcb80c2b090cdf5c6dd0ecce9807d71e8cdd62..8450df616c74398c334e9208ef0a45ef53e10314 100644 (file)
@@ -91,6 +91,7 @@
 {% endif %}
 </div>
 
+{% block search %}
 <div id="quick_search">
 <form action="{% url "telemeta-search" %}" id="_quickSearchForm" method="get">
     <div class="input-group">
     </div>
 </form>
 </div>
+{% endblock search %}
 
 <div id="menu">
 {% block menu %}
 <div id="content">
     <table id="content_header"><tr>
             <td class="leftcol"><h1>{% block title %}{% endblock %}</h1></td>
+            {% block rightcol %}
             <td class="rightcol" {% if LANGUAGE_BIDI %}style="float : left;"{% else %}style="float : right;"{% endif %}>{% block title_buttons %}{% endblock %}</td>
+            {% endblock rightcol %}
     </tr></table>
 
   {% block content %}{% endblock %}
diff --git a/telemeta/templates/telemeta/inc/epub_list.html b/telemeta/templates/telemeta/inc/epub_list.html
new file mode 100644 (file)
index 0000000..7beddec
--- /dev/null
@@ -0,0 +1,36 @@
+{% load telemeta_utils %}
+{% load i18n %}
+
+{% if children %}
+
+{% if hits %}
+<p class="pagination">
+{% blocktrans %}{{ resource.children_type|capitalize }} {{ first_on_page }} to {{ last_on_page }} on {{ hits }}{% endblocktrans %}
+| Pages : {% if pages == 1 %}1{% else %}{% if is_paginated %}{% load paginator %}{% paginator 5 %}{% endif %}{% endif %}
+</p>
+{% endif %}
+
+<table class="listing">
+{% for child in children %}
+{% if child.code %}
+<tr {% if not forloop.counter0|divisibleby:"2" %}class="odd"{% endif %}>
+    <td class="highlight">
+        <a href="{% url "telemeta-resource-detail" resource.children_type child.public_id %}">{{ child.title }}</a>
+    </td>
+    <td>
+       <center><a href="{% url "telemeta-collection-epub" child.public_id %}">
+        <button type="button" class="btn btn-default">
+            <span class="glyphicon glyphicon-book"></span> {% trans "Download" %}
+        </button>
+        </a>
+        </center>
+    </td>
+</tr>
+{% endif %}
+{% endfor %}
+</table>
+
+{% else %}
+    <p>{% trans "No resource" %}</p>
+
+{% endif %}
diff --git a/telemeta/templates/telemeta/resource_epub_list.html b/telemeta/templates/telemeta/resource_epub_list.html
new file mode 100644 (file)
index 0000000..13bc7ef
--- /dev/null
@@ -0,0 +1,31 @@
+{% extends "telemeta/resource_detail.html" %}
+{% load i18n %}
+{% load telemeta_utils %}
+
+
+{% block search %}
+{% endblock search %}
+
+{% block rightcol %}
+{% endblock rightcol %}
+
+{% block content %}
+{% block infos %}
+        <div class="extraInfos">
+        <h4><img src="{{ STATIC_URL }}telemeta/images/item_title.png" style="vertical-align:middle" />{% trans "Livre complet" %}</h4>
+        <a href="{% url "telemeta-resource-epub" type resource.public_id %}">
+        <button type="button" class="btn btn-default">
+            <span class="glyphicon glyphicon-book"></span> {% trans "Download" %}
+        </button>
+        </a>
+        </div>
+
+        <div class="extraInfos">
+        <h4><img src="{{ STATIC_URL }}telemeta/images/item_title.png" style="vertical-align:middle" />{% trans "Chapitres" %}</h4>
+        {% with resource.children.all as children %}
+            {% include "telemeta/inc/epub_list.html" %}
+        {% endwith %}
+        </div>
+
+{% endblock infos %}
+{% endblock %}
diff --git a/telemeta/templates/telemeta/resource_epub_login.html b/telemeta/templates/telemeta/resource_epub_login.html
new file mode 100644 (file)
index 0000000..e3b0989
--- /dev/null
@@ -0,0 +1,59 @@
+{% extends "telemeta/base.html" %}
+{% load i18n %}
+
+{% block content %}
+<script>
+$(document).ready(function() {
+    $(this).keydown(function(e) {
+        if (e.keyCode == '13') {
+            $("#_loginForm").submit();
+        }
+    });
+});
+</script>
+
+
+<div id="module-set-left" class="row">
+{{ block.super }}
+<div class="large-4 columns">&nbsp;</div>
+<div class="module large-4 columns">
+    <span class="module-title">
+    <img src="{{ STATIC_URL }}telemeta/images/user_tr.png" width="30px" style="margin: 3px;" alt="rss" style="vertical-align:middle" />
+    &nbsp;<h3>{% trans "User authentication" %}</h3></span>
+
+<div style="background-color: white; align: center; padding: 1em;">
+
+<form id="_loginForm" method="post" action="{% url "telemeta-login" %}">{% csrf_token %}
+
+{% if form.errors %}
+<p class="login-error">{% trans "Your username and password didn't match. Please try again." %}</p>
+{% endif %}
+
+<table>
+<tr>
+    <td><label>{{ form.username.label_tag }}</label></td>
+       <td>{{ form.username }}</td>
+</tr>
+<tr>
+       <td><label>{{ form.password.label_tag }}</label></td>
+       <td>{{ form.password }}</td>
+</tr>
+</table>
+
+<p style="margin-top: 0.5em;">
+<a href="#" onclick="$('#_loginForm').submit();" style="float: right;">
+  <button type="button" class="btn btn-default">
+    <span class="glyphicon glyphicon-log-in"></span> {% trans "Sign in" %}
+  </button>
+</a>
+
+<input type="hidden" name="next" value="{{ next }}" />
+<span><a href="{% url "password_reset" %}">{% trans "Password forgotten" %} ?</a></span>
+</p>
+
+</form>
+</div>
+</div>
+<div class="large-4 columns">&nbsp;</div>
+</div>
+{% endblock %}
diff --git a/telemeta/templates/telemeta/resource_epub_password.html b/telemeta/templates/telemeta/resource_epub_password.html
new file mode 100644 (file)
index 0000000..6614059
--- /dev/null
@@ -0,0 +1,47 @@
+{% extends "telemeta/resource_detail.html" %}
+{% load i18n %}
+
+{% block search %}
+{% endblock search %}
+
+{% block rightcol %}
+{% endblock rightcol %}
+
+{% block infos %}
+<script>
+$(document).ready(function() {
+    $(this).keydown(function(e) {
+        if (e.keyCode == '13') {
+            $("#_loginForm").submit();
+        }
+    });
+});
+</script>
+
+
+<div class="intro">
+{% trans "Pour télécharger les livrets de sonores au format EPUB3, merci de fournir le premier mot de la page 411 du livre." %}
+</div>
+
+<div style="background-color: white; align: center; padding: 1em;">
+
+<form id="_loginForm" method="post" action="">{% csrf_token %}
+    {% for message in messages %}
+    <span class="login-error">{{ message }}</span>
+    {% endfor %}
+
+    {{ form.as_p }}
+
+<a href="#" onclick="$('#_loginForm').submit();" style="float: left;">
+  <button type="button" class="btn btn-default">
+    <span class="glyphicon glyphicon-log-in"></span> {% trans "Envoyer" %}
+  </button>
+</a>
+
+</form>
+<br/><br/>
+</div>
+{% endblock infos %}
+
+{% block dublincore %}
+{% endblock dublincore %}
\ No newline at end of file
index 59e18d066bac88fe980db6b6cdd1494d2b4ca257..583aa9a49e50bf3f66d4c12cd3cc8b506f8186cd 100644 (file)
@@ -134,7 +134,9 @@ urlpatterns = patterns('',
     url(r'^archives/(?P<type>[A-Za-z0-9._-]+)/(?P<public_id>[A-Za-z0-9._-]+)/delete/$', ResourceDeleteView.as_view(), name="telemeta-resource-delete"),
     url(r'^archives/(?P<type>[A-Za-z0-9._-]+)/(?P<public_id>[A-Za-z0-9._-]+)/related/(?P<media_id>[A-Za-z0-9._-]+)/view/$', resource_view.related_stream, name="telemeta-resource-related"),
     url(r'^archives/(?P<type>[A-Za-z0-9._-]+)/(?P<public_id>[A-Za-z0-9._-]+)/related/(?P<media_id>[A-Za-z0-9._-]+)/download/$', resource_view.related_download, name="telemeta-resource-related-download"),
-    url(r'^archives/corpus/(?P<public_id>[A-Za-z0-9._-]+)/epub/$', CorpusEpubView.as_view(), name="telemeta-corpus-epub"),
+    url(r'^archives/(?P<type>[A-Za-z0-9._-]+)/(?P<public_id>[A-Za-z0-9._-]+)/epub/download/$', ResourceEpubView.as_view(), name="telemeta-resource-epub"),
+    url(r'^archives/(?P<type>[A-Za-z0-9._-]+)/(?P<public_id>[A-Za-z0-9._-]+)/epub/list/$', ResourceEpubListView.as_view(), name="telemeta-resource-epub-list"),
+    url(r'^archives/(?P<type>[A-Za-z0-9._-]+)/(?P<public_id>[A-Za-z0-9._-]+)/epub/$', ResourceEpubPasswordView.as_view(), name="telemeta-resource-password-epub"),
 
     # search
     # url(r'^archives/$', home_view.search, name="telemeta-archives"),
index 614e0a7bff0a5010bd0b532c42faa3add5ebe300..cd9c9d13a52e8dfdfd3517447e25303ec67f6fdd 100644 (file)
@@ -36,7 +36,7 @@
 
 
 from telemeta.views.core import *
-
+from telemeta.views.epub import *
 
 class CollectionView(object):
     """Provide Collections web UI methods"""
@@ -372,3 +372,26 @@ class CollectionCopyView(CollectionAddView):
         return super(CollectionCopyView, self).dispatch(*args, **kwargs)
 
 
+
+class CollectionEpubView(BaseEpubMixin, View):
+    "Download collection data embedded in an EPUB3 file"
+
+    model = MediaCollection
+
+    def get_object(self):
+        return MediaCollection.objects.get(public_id=self.kwargs['public_id'])
+
+    def get(self, request, *args, **kwargs):
+        collection = self.get_object()
+        corpus = collection.corpus.all()[0]
+        self.write_book(corpus, collection=collection)
+        epub_file = open(self.path, 'rb')
+        response = HttpResponse(epub_file.read(), content_type='application/epub+zip')
+        response['Content-Disposition'] = "attachment; filename=%s" % self.filename + '.epub'
+        return response
+
+    @method_decorator(login_required)
+    @method_decorator(permission_required('telemeta.can_download_collection_epub'))
+    def dispatch(self, *args, **kwargs):
+        return super(CollectionEpubView, self).dispatch(*args, **kwargs)
+
index b05521ba7e3ba6fd213e03ec4611b05839561590..76e21d300d883414831dbc09c58a757be2e98aa4 100644 (file)
@@ -38,6 +38,7 @@ from telemeta.models import *
 from collections import OrderedDict
 from ebooklib import epub
 from django.template.loader import render_to_string
+from django.utils.translation import ugettext_lazy as _
 
 
 class BaseEpubMixin(TelemetaBaseMixin):
@@ -215,46 +216,4 @@ class BaseEpubMixin(TelemetaBaseMixin):
         epub.write_epub(self.path, self.book, {})
 
 
-class CorpusEpubView(BaseEpubMixin, View):
-    "Download corpus data embedded in an EPUB3 file"
-
-    model = MediaCorpus
-
-    def get_object(self):
-        return MediaCorpus.objects.get(public_id=self.kwargs['public_id'])
-
-    def get(self, request, *args, **kwargs):
-        self.write_book(self.get_object())
-        epub_file = open(self.path, 'rb')
-        response = HttpResponse(epub_file.read(), content_type='application/epub+zip')
-        response['Content-Disposition'] = "attachment; filename=%s" % self.filename + '.epub'
-        return response
-
-    @method_decorator(login_required)
-    @method_decorator(permission_required('telemeta.can_download_corpus_epub'))
-    def dispatch(self, *args, **kwargs):
-        return super(CorpusEpubView, self).dispatch(*args, **kwargs)
-
-
-class CollectionEpubView(BaseEpubMixin, View):
-    "Download collection data embedded in an EPUB3 file"
-
-    model = MediaCollection
-
-    def get_object(self):
-        return MediaCollection.objects.get(public_id=self.kwargs['public_id'])
-
-    def get(self, request, *args, **kwargs):
-        collection = self.get_object()
-        corpus = collection.corpus.all()[0]
-        self.write_book(corpus, collection=collection)
-        epub_file = open(self.path, 'rb')
-        response = HttpResponse(epub_file.read(), content_type='application/epub+zip')
-        response['Content-Disposition'] = "attachment; filename=%s" % self.filename + '.epub'
-        return response
-
-    @method_decorator(login_required)
-    @method_decorator(permission_required('telemeta.can_download_collection_epub'))
-    def dispatch(self, *args, **kwargs):
-        return super(CollectionEpubView, self).dispatch(*args, **kwargs)
 
index 11ac4415247a835497097a81278ee5dda46f7bc7..b308962e883764631b86da2be7609fdea8fa70e8 100644 (file)
@@ -36,6 +36,8 @@
 
 
 from telemeta.views.core import *
+from telemeta.views.epub import *
+from django.utils.translation import ugettext_lazy as _
 
 
 class ResourceView(object):
@@ -338,3 +340,44 @@ class ResourceEditView(ResourceSingleMixin, UpdateWithInlinesView):
     def dispatch(self, *args, **kwargs):
         return super(ResourceEditView, self).dispatch(*args, **kwargs)
 
+
+class ResourceEpubView(ResourceSingleMixin, BaseEpubMixin, View):
+    "Download corpus data embedded in an EPUB3 file"
+
+    def get(self, request, *args, **kwargs):
+        self.write_book(self.get_object())
+        epub_file = open(self.path, 'rb')
+        response = HttpResponse(epub_file.read(), content_type='application/epub+zip')
+        response['Content-Disposition'] = "attachment; filename=%s" % self.filename + '.epub'
+        return response
+
+    def dispatch(self, *args, **kwargs):
+        return super(ResourceEpubView, self).dispatch(*args, **kwargs)
+
+
+class ResourceEpubPasswordView(ResourceSingleMixin, FormView):
+
+    template_name = 'telemeta/resource_epub_password.html'
+    form_class = EpubPasswordForm
+
+    def get_success_url(self):
+        return reverse_lazy('telemeta-resource-epub-list', kwargs={'type': self.kwargs['type'], 'public_id': self.kwargs['public_id']})
+
+    def form_valid(self, form):
+        self.password = form.cleaned_data['password']
+        if self.password != unicode('melodie'):
+            messages.info(self.request, _("Bad password, please try again."))
+            return redirect('telemeta-resource-password-epub', self.kwargs['type'], self.kwargs['public_id'])
+        else:
+            return redirect('telemeta-resource-epub-list', self.kwargs['type'], self.kwargs['public_id'])
+
+        return super(ResourceEpubPasswordView, self).form_valid(form)
+
+    def dispatch(self, *args, **kwargs):
+        return super(ResourceEpubPasswordView, self).dispatch(*args, **kwargs)
+
+
+class ResourceEpubListView(ResourceDetailView):
+
+    template_name = 'telemeta/resource_epub_list.html'
+