Upload for T4U is fixed
parent
25d9923337
commit
4948a7961f
|
@ -2,6 +2,7 @@
|
|||
external library imports
|
||||
"""
|
||||
import logging
|
||||
import zipfile
|
||||
|
||||
from datetime import timedelta, datetime, date
|
||||
from decimal import Decimal as D
|
||||
|
@ -26,6 +27,9 @@ from selectable.forms import (
|
|||
AutoCompleteSelectField
|
||||
)
|
||||
|
||||
from PyPDF2 import PdfFileReader
|
||||
|
||||
|
||||
"""
|
||||
regluit imports
|
||||
"""
|
||||
|
@ -139,13 +143,15 @@ class EditionForm(forms.ModelForm):
|
|||
}
|
||||
|
||||
class EbookFileForm(forms.ModelForm):
|
||||
file = EpubFileField(max_length=16777216)
|
||||
file = forms.FileField(max_length=16777216)
|
||||
|
||||
def __init__(self, campaign_type=BUY2UNGLUE, *args, **kwargs):
|
||||
super(EbookFileForm, self).__init__(*args, **kwargs)
|
||||
self.campaign_type = campaign_type
|
||||
if campaign_type == BUY2UNGLUE:
|
||||
self.fields['format'].widget=forms.HiddenInput
|
||||
self.fields['format'].widget=forms.HiddenInput()
|
||||
if campaign_type == THANKS:
|
||||
self.fields['format'].widget=forms.Select(choices=(('pdf','PDF'),( 'epub','EPUB'), ('mobi','MOBI')))
|
||||
|
||||
def clean_format(self):
|
||||
if self.campaign_type is BUY2UNGLUE:
|
||||
|
@ -153,6 +159,23 @@ class EbookFileForm(forms.ModelForm):
|
|||
else:
|
||||
logger.info("EbookFileForm "+self.cleaned_data.get('format',''))
|
||||
return self.cleaned_data.get('format','')
|
||||
|
||||
def clean(self):
|
||||
format = self.cleaned_data['format']
|
||||
the_file = self.cleaned_data.get('file',None)
|
||||
if the_file and the_file.name:
|
||||
if format == 'epub':
|
||||
if not zipfile.is_zipfile(the_file.file):
|
||||
raise forms.ValidationError(_('%s is not a valid EPUB file' % the_file.name) )
|
||||
elif format == 'mobi':
|
||||
if not zipfile.is_zipfile(the_file.file):
|
||||
raise forms.ValidationError(_('%s is not a valid MOBI file' % the_file.name) )
|
||||
elif format == 'pdf':
|
||||
try:
|
||||
doc = PdfFileReader(the_file.file)
|
||||
except Exception, e:
|
||||
raise forms.ValidationError(_('%s is not a valid PDF file' % the_file.name) )
|
||||
return self.cleaned_data
|
||||
|
||||
class Meta:
|
||||
model = EbookFile
|
||||
|
|
|
@ -49,22 +49,30 @@ Any questions not covered here? Please email us at <a href="mailto:rights@gluej
|
|||
<div class="work_campaigns clearfix">
|
||||
<div class="campaign_info">
|
||||
{% ifequal campaign.type 1 %}
|
||||
<b>Pledge Campaign</b><br />
|
||||
Campaign status: {{ campaign.status }} <br />
|
||||
Created: {{ campaign.created }}<br />
|
||||
${{ campaign.current_total }} pledged of ${{ campaign.target }}, {{ campaign.supporters_count }} supporters
|
||||
<b>Pledge Campaign</b><br />
|
||||
Campaign status: {{ campaign.status }} <br />
|
||||
Created: {{ campaign.created }}<br />
|
||||
${{ campaign.current_total }} pledged of ${{ campaign.target }}, {{ campaign.supporters_count }} supporters
|
||||
{% endifequal %}
|
||||
{% ifequal campaign.type 2 %}
|
||||
<b>Buy-to-Unglue Campaign</b><br />
|
||||
Campaign status: {{ campaign.status }} <br />
|
||||
Created: {{ campaign.created }}<br />
|
||||
${{ campaign.current_total }} sold. ${{ campaign.target }} to go. Ungluing Date: {{ campaign.cc_date }}
|
||||
<b>Buy-to-Unglue Campaign</b><br />
|
||||
Campaign status: {{ campaign.status }} <br />
|
||||
Created: {{ campaign.created }}<br />
|
||||
${{ campaign.current_total }} sold. ${{ campaign.target }} to go. Ungluing Date: {{ campaign.cc_date }}<br />
|
||||
{% with campaign.work.preferred_edition as edition %}
|
||||
<a href="{% url new_edition edition.work.id edition.id %}"> Edit </a> the preferred edition<br />
|
||||
You can also <a href="{% url edition_uploads edition.id %}"> Load a file</a> for this edition.<br />
|
||||
{% endwith %}
|
||||
{% endifequal %}
|
||||
{% ifequal campaign.type 3 %}
|
||||
<b>Thanks-for-Ungluing Campaign</b><br />
|
||||
Campaign status: {{ campaign.status }} <br />
|
||||
Created: {{ campaign.created }}<br />
|
||||
${{ campaign.current_total }} raised from {{ campaign.supporters_count }} supporters.
|
||||
<b>Thanks-for-Ungluing Campaign</b><br />
|
||||
Campaign status: {{ campaign.status }} <br />
|
||||
Created: {{ campaign.created }}<br />
|
||||
${{ campaign.current_total }} raised from {{ campaign.supporters_count }} supporters.
|
||||
{% with campaign.work.preferred_edition as edition %}
|
||||
<a href="{% url new_edition edition.work.id edition.id %}"> Edit </a> the preferred edition<br />
|
||||
You can also <a href="{% url edition_uploads edition.id %}"> Load a file</a> for this edition.<br />
|
||||
{% endwith %}
|
||||
{% endifequal %}
|
||||
</div>
|
||||
{% if campaign.status = 'ACTIVE' or campaign.status = 'INITIALIZED' %}
|
||||
|
|
|
@ -2,6 +2,7 @@ Django==1.4.5
|
|||
Fabric==1.4.3
|
||||
MySQL-python==1.2.3
|
||||
Pillow==1.7.7
|
||||
PyPDF2==1.20
|
||||
Pyzotero==0.9.51
|
||||
South==0.7.6
|
||||
WebOb==1.2.3
|
||||
|
|
Loading…
Reference in New Issue