"""
db.executescript(schema)
- db.execute("INSERT INTO state VALUES (:last_checked)", locals())
+ db.execute("INSERT INTO state VALUES (:last_checked)", {'last_checked': last_checked})
return db
def add_book(db, book):
- title = book.title
if book.html_file:
html_file = book.html_file.url
html_file_size = book.html_file.size
else:
html_file = html_file_size = None
- if book.cover:
- cover = book.cover.url
- else:
- cover = None
- parent = book.parent_id
- parent_number = book.parent_number
- sort_key = book.sort_key
- size_str = pretty_size(html_file_size)
- authors = ", ".join(t.name for t in book.tags.filter(category='author'))
- db.execute(book_sql, locals())
+ db.execute(book_sql, {
+ 'title': book.title,
+ 'cover': book.cover.url if book.cover else None,
+ 'html_file': html_file,
+ 'html_file_size': html_file_size,
+ 'parent': book.parent_id,
+ 'parent_number': book.parent_number,
+ 'sort_key': book.sort_key,
+ 'size_str': pretty_size(html_file_size),
+ 'authors': ", ".join(t.name for t in book.tags.filter(category='author')),
+ })
def add_tag(db, tag):
- category = categories[tag.category]
- name = tag.name
- sort_key = tag.sort_key
-
books = Book.tagged_top_level([tag])
- book_ids = ','.join(str(b.id) for b in books)
- db.execute(tag_sql, locals())
+ book_ids = ','.join(str(book_id) for book_id in books.values_list('id', flat=True))
+ db.execute(tag_sql, {
+ 'category': categories[tag.category],
+ 'name': tag.name,
+ 'sort_key': tag.sort_key,
+ 'book_ids': book_ids,
+ })
{% extends "catalogue/book_short.html" %}
{% load i18n %}
-{% load choose_fragment download_audio tag_list custom_pdf_link_li license_icon source_name from catalogue_tags %}
+{% load choose_fragment download_audio custom_pdf_link_li license_icon source_name from catalogue_tags %}
{% load choose_cite from social_tags %}
{% load ssi_include from ssify %}
return reverse('book_list')
-@register.inclusion_tag('catalogue/tag_list.html')
+# @register.inclusion_tag('catalogue/tag_list.html')
def tag_list(tags, choices=None, category=None, gallery=False):
- print(tags, choices, category)
+ # print(tags, choices, category)
if choices is None:
choices = []
if len(tags) == 1 and category not in [t.category for t in choices]:
one_tag = tags[0]
+ else:
+ one_tag = None
if category is not None:
other = Tag.objects.filter(category=category).exclude(pk__in=[t.pk for t in tags])\
# Filter out empty tags.
ct = ContentType.objects.get_for_model(Picture if gallery else Book)
other = other.filter(items__content_type=ct).distinct()
+ else:
+ other = []
- return locals()
+ return {
+ 'one_tag': one_tag,
+ 'choices': choices,
+ 'tags': tags,
+ 'other': other,
+ }
@register.inclusion_tag('catalogue/inline_tag_list.html')
@register.inclusion_tag('catalogue/collection_list.html')
def collection_list(collections):
- return locals()
+ return {'collections': collections}
@register.inclusion_tag('catalogue/book_info.html')
@register.inclusion_tag('catalogue/work-list.html', takes_context=True)
def work_list(context, object_list):
request = context.get('request')
- return locals()
+ return {'object_list': object_list, 'request': request}
@register.inclusion_tag('catalogue/plain_list.html', takes_context=True)
last_initial = initial
names.append((obj.author_str() if by_author else initial, []))
names[-1][1].append(obj)
- return locals()
+ return {
+ 'paged': paged,
+ 'names': names,
+ 'initial_blocks': initial_blocks,
+ 'book': book,
+ 'gallery': gallery,
+ 'choice': choice,
+ }
# TODO: These are no longer just books.
staff_required = user_passes_test(lambda user: user.is_staff)
-def catalogue(request, as_json=False):
- books = models.Book.objects.filter(parent=None).order_by('sort_key_author', 'sort_key')
- pictures = Picture.objects.order_by('sort_key_author', 'sort_key')
- collections = models.Collection.objects.all()
- return render(request, 'catalogue/catalogue.html', locals())
+def catalogue(request):
+ return render(request, 'catalogue/catalogue.html', {
+ 'books': models.Book.objects.filter(parent=None).order_by('sort_key_author', 'sort_key'),
+ 'pictures': Picture.objects.order_by('sort_key_author', 'sort_key'),
+ 'collections': models.Collection.objects.all(),
+ })
def book_list(request, filter=None, get_filter=None, template_name='catalogue/book_list.html',
for tag in books_by_author:
if books_by_author[tag]:
books_nav.setdefault(tag.sort_key[0], []).append(tag)
- rendered_nav = render_to_string(nav_template_name, locals())
- rendered_book_list = render_to_string(list_template_name, locals())
- return render_to_response(template_name, locals(), context_instance=RequestContext(request))
+ # WTF: dlaczego nie include?
+ return render_to_response(template_name, {
+ 'rendered_nav': render_to_string(nav_template_name, {'books_nav': books_nav}),
+ 'rendered_book_list': render_to_string(list_template_name, {
+ 'books_by_author': books_by_author,
+ 'orphans': orphans,
+ 'books_by_parent': books_by_parent,
+ })
+ }, context_instance=RequestContext(request))
def audiobook_list(request):
fragments = models.Fragment.tagged.with_all([theme]).filter(
Q(book=book) | Q(book__ancestor=book))
- return render_to_response('catalogue/book_fragments.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/book_fragments.html', {
+ 'book': book,
+ 'theme': theme,
+ 'fragments': fragments,
+ }, context_instance=RequestContext(request))
def book_detail(request, slug):
except models.Book.DoesNotExist:
return pdcounter_views.book_stub_detail(request, slug)
- tags = book.tags.exclude(category__in=('set', 'theme'))
- book_children = book.children.all().order_by('parent_number', 'sort_key')
- return render_to_response('catalogue/book_detail.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/book_detail.html', {
+ 'book': book,
+ 'tags': book.tags.exclude(category__in=('set', 'theme')),
+ 'book_children': book.children.all().order_by('parent_number', 'sort_key'),
+ }, context_instance=RequestContext(request))
def get_audiobooks(book):
return audiobooks, projects, have_oggs
+# używane tylko do audiobook_tree, które jest używane tylko w snippets/audiobook_list.html, które nie jest używane
def player(request, slug):
book = get_object_or_404(models.Book, slug=slug)
if not book.has_media('mp3'):
audiobooks, projects, have_oggs = get_audiobooks(book)
- extra_info = book.extra_info
+ # extra_info = book.extra_info
- return render_to_response('catalogue/player.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/player.html', {
+ 'book': book,
+ 'audiobook': '',
+ 'audiobooks': audiobooks,
+ 'projects': projects,
+ }, context_instance=RequestContext(request))
def book_text(request, slug):
if not book.has_html_file():
raise Http404
- return render_to_response('catalogue/book_text.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/book_text.html', {'book': book,}, context_instance=RequestContext(request))
# ==========
book = get_object_or_404(models.Book, id=book_id)
# set language by hand
translation.activate(lang)
- return render_to_response('catalogue/book_info.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/book_info.html', {'book': book}, context_instance=RequestContext(request))
def tag_info(request, tag_id):
try:
right_column = Template(page.right_column).render(rc)
except TemplateSyntaxError:
- left_column = ''
+ right_column = ''
- return render_to_response('infopages/infopage.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('infopages/infopage.html', {
+ 'page': page,
+ 'left_column': left_column,
+ 'right_columns': right_column,
+ }, context_instance=RequestContext(request))
book = get_object_or_404(models.BookStub, slug=slug)
if book.pd and not book.in_pd():
pd_counter = datetime(book.pd, 1, 1)
+ else:
+ pd_counter = None
form = PublishingSuggestForm(initial={"books": u"%s — %s, \n" % (book.author, book.title)})
- return render_to_response('pdcounter/book_stub_detail.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('pdcounter/book_stub_detail.html', {
+ 'book': book,
+ 'pd_counter': pd_counter,
+ 'form': form,
+ }, context_instance=RequestContext(request))
@cache.never_cache
author = get_object_or_404(models.Author, slug=slug)
if not author.alive():
pd_counter = datetime(author.goes_to_pd(), 1, 1)
+ else:
+ pd_counter = None
form = PublishingSuggestForm(initial={"books": author.name + ", \n"})
- return render_to_response('pdcounter/author_detail.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('pdcounter/author_detail.html', {
+ 'author': author,
+ 'pd_counter': pd_counter,
+ 'form': form,
+ }, context_instance=RequestContext(request))
<div class="other-tools">
<h2 class="mono">{% trans "See" %}</h2>
<ul class="plain">
- {% if extra_info.source_url %}
- <li><a href="{{ extra_info.source_url }}">{% trans "Source" %}</a> {% trans "of the picture" %}</li>
+ {% if picture.extra_info.source_url %}
+ <li><a href="{{ picture.extra_info.source_url }}">{% trans "Source" %}</a> {% trans "of the picture" %}</li>
{% endif %}
<li><a href="{{ picture.xml_file.url }}">{% trans "Source XML file" %}</a></li>
- {% if extra_info.about and not hide_about %}
- <li>{% trans "Picture on" %} <a href="{{ extra_info.about }}">{% trans "Editor's Platform" %}</a></li>
+ {% if picture.extra_info.about and not hide_about %}
+ <li>{% trans "Picture on" %} <a href="{{ picture.extra_info.about }}">{% trans "Editor's Platform" %}</a></li>
{% endif %}
{% if picture.wiki_link %}
<li><a href="{{ picture.wiki_link }}">{% trans "Picture description on Wikipedia" %}</a></li>
book_list = book_list.filter(get_filter())
book_list = book_list.order_by('sort_key_author')
book_list = list(book_list)
- return render_to_response(template_name, locals(), context_instance=RequestContext(request))
+ return render_to_response(template_name, {'book_list': book_list}, context_instance=RequestContext(request))
def picture_detail(request, slug):
# for tag in picture.tags.iterator():
# categories.setdefault(tag.category, []).append(tag)
- themes = theme_things.get('theme', [])
- things = theme_things.get('thing', [])
-
- extra_info = picture.extra_info
-
- return render_to_response("picture/picture_detail.html", locals(),
- context_instance=RequestContext(request))
+ return render_to_response("picture/picture_detail.html", {
+ 'picture': picture,
+ 'themes': theme_things.get('theme', []),
+ 'things': theme_things.get('thing', []),
+ }, context_instance=RequestContext(request))
def picture_viewer(request, slug):
have_sponsors = Sponsor.objects.filter(name=sponsor)
if have_sponsors.exists():
sponsors.append(have_sponsors[0])
- return render_to_response("picture/picture_viewer.html", locals(),
- context_instance=RequestContext(request))
+ return render_to_response("picture/picture_viewer.html", {
+ 'picture': picture,
+ 'sponsors': sponsors,
+ }, context_instance=RequestContext(request))
# =========
@ssi_included
def picturearea_short(request, pk):
area = get_object_or_404(PictureArea, pk=pk)
- theme = area.tags.filter(category='theme')
- theme = theme and theme[0] or None
- thing = area.tags.filter(category='thing')
- thing = thing and thing[0] or None
- return render(request, 'picture/picturearea_short.html', locals())
+ themes = area.tags.filter(category='theme')
+ things = area.tags.filter(category='thing')
+ return render(request, 'picture/picturearea_short.html', {
+ 'area': area,
+ 'theme': themes[0] if themes else None,
+ 'thing': things[0] if things else None,
+ })
@staff_member_required
def stats_page(request):
- media = BookMedia.objects.count()
media_types = BookMedia.objects.values('type').annotate(count=Count('type')).order_by('type')
for mt in media_types:
mt['size'] = sum(b.file.size for b in BookMedia.objects.filter(type=mt['type']).iterator())
else:
mt['deprecated'] = '-'
- licenses = set((
+ licenses = set(
(b.extra_info.get('license'), b.extra_info.get('license_description'))
- for b in Book.objects.all().iterator() if b.extra_info.get('license')))
+ for b in Book.objects.all().iterator() if b.extra_info.get('license'))
- return render_to_response('reporting/main.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('reporting/main.html', {
+ 'media_types': media_types,
+ 'licenses': licenses,
+ }, context_instance=RequestContext(request))
@generated_file_view('reports/katalog.pdf', 'application/pdf',
send_name=lambda: 'wolnelektury_%s.pdf' % date.today(), signals=[Book.published])
def catalogue_pdf(path):
books_by_author, orphans, books_by_parent = Book.book_list()
- render_to_pdf(path, 'reporting/catalogue.texml', locals(), {
+ render_to_pdf(path, 'reporting/catalogue.texml', {
+ 'books_by_author': books_by_author,
+ 'orphans': orphans,
+ 'book_by_parent': books_by_parent,
+ }, {
"wl-logo.png": os.path.join(settings.STATIC_ROOT, "img/logo-big.png"),
})
send_name=lambda: 'wolnelektury_%s.csv' % date.today(), signals=[Book.published])
def catalogue_csv(path):
books_by_author, orphans, books_by_parent = Book.book_list()
- render_to_csv(path, 'reporting/catalogue.csv', locals())
+ render_to_csv(path, 'reporting/catalogue.csv', {
+ 'books_by_author': books_by_author,
+ 'orphans': orphans,
+ 'book_by_parent': books_by_parent,
+ })
@login_required
def my_shelf(request):
- books = Book.tagged.with_any(request.user.tag_set.all())
- return render(request, 'social/my_shelf.html', locals())
+ return render(request, 'social/my_shelf.html', {
+ 'books': Book.tagged.with_any(request.user.tag_set.all())
+ })
class ObjectSetsFormView(AjaxableFormView):
def wait(request, path):
if WaitedFile.exists(path):
file_url = join(WAITER_URL, path)
+ waiting = None
else:
- file_url = ""
+ file_url = None
waiting = get_object_or_404(WaitedFile, path=path)
if request.is_ajax():
return HttpResponse(file_url)
else:
- return render(request, "waiter/wait.html", locals())
+ return render(request, "waiter/wait.html", {
+ 'waiting': waiting,
+ 'file_url': file_url,
+ })