python-docx==0.8.11
Wikidata==0.7
-librarian==24.5.9
+librarian==26.11
## Django
Django==4.1.9
@staticmethod
def standardize(code):
+ if code is None: return None
return code.split('.')[0]
class Audience(models.Model):
model = Image
exclude = ['download_url', 'use_file', 'example',]
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.fields['file'].required = False
+
def clean(self):
cleaned_data = super(ImageEditForm, self).clean()
uploaded_file = cleaned_data.get('file', None)
- width, height = PILImage.open(uploaded_file.file).size
- min_width, min_height = settings.MIN_COVER_SIZE
- if width < min_width or height < min_height:
- raise forms.ValidationError(gettext('Image too small: %sx%s, minimal dimensions %sx%s') %
- (width, height, min_width, min_height))
+ if uploaded_file is not None:
+ width, height = PILImage.open(uploaded_file.file).size
+ min_width, min_height = settings.MIN_COVER_SIZE
+ if width < min_width or height < min_height:
+ raise forms.ValidationError(gettext('Image too small: %sx%s, minimal dimensions %sx%s') %
+ (width, height, min_width, min_height))
class ReadonlyImageEditForm(ImageEditForm):
<div class="col-md-7">
+ {% if object.use_file %}
{% with perc=object.cut_percentages %}
<a href="{{ object.use_file.url }}" style="position: relative; display: block; width: {{ perc.width }}px; height: {{ perc.height }}px;">
{% thumbnail object.file perc.th as th %}
<div style="background: black; opacity: .5; display: block; position: absolute; top: {{ perc.top }}%; bottom: {{ perc.bottom }}%; left: 0; width: {{ perc.left }}%"></div>
<div style="background: black; opacity: .5; display: block; position: absolute; top: {{ perc.top }}%; bottom: {{ perc.bottom }}%; right: 0; width: {{ perc.right }}%"></div>
{% endlocalize %}
- {% endwith %}
+ {% endwith %}
+ {% endif %}
</a>
<br/><a href="{{ object.source_url }}">{{ object.title }}</a> by {{ object.author }},
{% if object.license_url %}<a href="{{ object.license_url }}">{% endif %}
</div>
</div>
-
+{% if object.use_file %}
<textarea style="width:100%" rows="6" class="form-control mt-4" disabled>
<dc:relation.coverImage.url xmlns:dc="http://purl.org/dc/elements/1.1/">{{ object.use_file.url|build_absolute_uri:request }}</dc:relation.coverImage.url>
<dc:relation.coverImage.attribution xmlns:dc="http://purl.org/dc/elements/1.1/">{{ object.attribution }}</dc:relation.coverImage.attribution>
<dc:relation.coverImage.source xmlns:dc="http://purl.org/dc/elements/1.1/">{{ object.get_full_url }}</dc:relation.coverImage.source></textarea>
+ {% endif %}
<div class="card mt-4">
<div class="card-header">
#
from datetime import date
from functools import wraps
-from os.path import join
+from os.path import join, exists
from os import listdir, stat
from shutil import move, rmtree
from django.conf import settings
return self.dest_size is not None
def merge(self):
- if not self.dest:
+ if not self.dest or not exists(self.path(self.dest)):
return self.src
- if not self.src:
+ if not self.src or not exists(self.path(self.src)):
return self.dest
files = listdir(self.path(self.dest))
return HttpResponseForbidden("Not authorized.")
doc = book.wldocument(parse_dublincore=False)
- html = doc.as_html(options={'gallery': "'%s'" % book.gallery_url()})
+ html = doc.as_html(
+ gallery_url='%stmp/html/' % settings.MEDIA_URL,
+ gallery_path='%s/tmp/html/' % settings.MEDIA_ROOT,
+ base_url=request.build_absolute_uri(book.gallery_url()),
+ options={'gallery': "'%s'" % book.gallery_url()})
html = html.get_bytes().decode('utf-8') if html is not None else ''
# response = http.HttpResponse(html, content_type='text/html')
doc = book.wldocument()
# TODO: error handling
customizations = ['26pt', 'nothemes', 'nomargins', 'notoc'] if mobile else None
- pdf_file = doc.as_pdf(cover=True, base_url=request.build_absolute_uri(book.gallery_path()), customizations=customizations)
+ pdf_file = doc.as_pdf(cover=True, base_url=request.build_absolute_uri(book.gallery_url()), customizations=customizations)
from .ebook_utils import serve_file
return serve_file(pdf_file.get_filename(),
book.slug + '.pdf', 'application/pdf')
cbook_by_slug = None
if book.dc_slug:
- audio_items = requests.get(f'https://audio.wolnelektury.pl/archive/book/{book.dc_slug}.json').json()['items']
- has_audio = bool(audio_items)
- can_sell_audio = has_audio and all(x['project']['can_sell'] for x in audio_items)
+ try:
+ audio_items = requests.get(f'https://audio.wolnelektury.pl/archive/book/{book.dc_slug}.json').json()['items']
+ except:
+ has_audio = None
+ can_sell_audio = None
+ else:
+ has_audio = bool(audio_items)
+ can_sell_audio = has_audio and all(x['project']['can_sell'] for x in audio_items)
if book.catalogue_book is None or book.dc_slug != book.catalogue_book.slug:
cbook_by_slug = catalogue.models.Book.objects.filter(slug=book.dc_slug).first()
LOGIN_REDIRECT_URL = '/documents/user'
-MIN_COVER_SIZE = (915, 1270)
-
LEGIMI_SMALL_WORDS = 2000
LEGIMI_BIG_WORDS = 10000
LEGIMI_SMALL_PRICE = 7
LEGIMI_PASSWORD = None
LEGIMI_PUBLISHER_ID = None
+MIN_COVER_SIZE = (800, 800)