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):
model = MediaItemIdentifier
max_num = 1
+
+class EpubPasswordForm(forms.Form):
+
+ password = forms.CharField(label=_('password'))
+
/* 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;
padding-top : 18%;
page-break-before: always;
text-align: center;
-}
\ No newline at end of file
+}
+
+.error {
+ color: red;
+}
{% 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 %}
--- /dev/null
+{% 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 %}
--- /dev/null
+{% 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 %}
--- /dev/null
+{% 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"> </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" />
+ <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"> </div>
+</div>
+{% endblock %}
--- /dev/null
+{% 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
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"),
from telemeta.views.core import *
-
+from telemeta.views.epub import *
class CollectionView(object):
"""Provide Collections web UI methods"""
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)
+
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):
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)
from telemeta.views.core import *
+from telemeta.views.epub import *
+from django.utils.translation import ugettext_lazy as _
class ResourceView(object):
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'
+