Eine Menge Aufräumarbeiten.

* Eine Testsuite um Mahrjong Ranking Berechnungen zu testen
* Erste Arbeiten um die Workarounds aus dem "utils" Paket los zu werden.
* Vieles am Code umformatiert für PEP8 conformität
This commit is contained in:
2017-06-07 13:25:30 +02:00
parent cf0bbb4c8f
commit a26a91c360
93 changed files with 33531 additions and 2737 deletions

View File

@@ -1,33 +1,33 @@
"""
Created on 19.09.2011
@author: christian
"""
# import stuff we need from django
from django.contrib import admin
from . import models
class PageTabularInline(admin.TabularInline):
""" Displays the sub-pages of an page element. """
fields = ('title_de', 'menu_name_de', "position",)
model = models.Page
sortable_field_name = "position"
class ArticleAdmin(admin.ModelAdmin):
""" Admin interface for the news-articles. """
prepopulated_fields = {"slug": ("headline_de",)}
list_display = ('headline', 'category', 'date_created', 'author',)
list_editable = ('category', 'author')
class CategoryAdmin(admin.ModelAdmin):
""" Admin interface for categories of the news-aricles. """
list_display = ['name', 'slug', 'description']
list_display_links = ('name', 'slug',)
prepopulated_fields = {'slug': ('name_de',)}
class PageAdmin(admin.ModelAdmin):
"""
Admin interface for static pages that can contain HTML or PDF Content.
"""
prepopulated_fields = {"slug": ('menu_name_de',)}
inlines = [PageTabularInline, ]
list_display = ('position', 'menu_name', 'title', 'parent', 'path',)
@@ -54,6 +54,7 @@ class PageAdmin(admin.ModelAdmin):
}),
)
admin.site.register(models.Article, ArticleAdmin)
admin.site.register(models.Page, PageAdmin)
admin.site.register(models.Category, CategoryAdmin)

View File

@@ -3,11 +3,10 @@ Created on 04.10.2011
@author: christian
"""
import django.forms
from django import forms
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext as _
from utils.html5 import forms
from . import models
@@ -35,9 +34,9 @@ class ArticleForm(forms.ModelForm):
class PageForm(forms.ModelForm):
error_css_class = 'error'
required_css_class = 'required'
content_type = django.forms.ChoiceField(
content_type = forms.ChoiceField(
choices=models.CONTENT_CHOICES,
widget=django.forms.RadioSelect
widget=forms.RadioSelect
)
class Meta(object):
@@ -47,7 +46,7 @@ class PageForm(forms.ModelForm):
def clean(self):
cleaned_data = super(PageForm, self).clean()
content_type = cleaned_data.get("content_type")
pdf_de = cleaned_data.get("pdf_de")
cleaned_data.get("pdf_de")
if content_type == "2" and not cleaned_data.get("pdf_de"):
msg = _('Please upload a PDF-File to this PDF-Page.')
self._errors["content_type"] = self.error_class([msg])

View File

@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: kasu.content\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-09-28 00:25+0200\n"
"POT-Creation-Date: 2017-05-10 23:16+0200\n"
"PO-Revision-Date: 2016-09-28 00:24+0200\n"
"Last-Translator: Christian Berg <xeniac@posteo.at>\n"
"Language-Team: Deutsch <>\n"
@@ -20,235 +20,265 @@ msgstr ""
"X-Translated-Using: django-rosetta 0.7.2\n"
"X-Generator: Poedit 1.8.9\n"
#: src/content/feeds.py:14
#: content/feeds.py:14
msgid "Current news from Kasu"
msgstr "Aktuelle Nachrichten von Kasu"
#: src/content/feeds.py:42
#: content/feeds.py:42
msgid "Latest comments on kasu.at"
msgstr "Neueste Kommentare auf Kasu.at "
#: src/content/feeds.py:43
#: content/feeds.py:43
msgid "Kasu - latest comments"
msgstr "Kasu - neue Kommentare"
#: src/content/forms.py:52 src/content/models.py:204
#: content/forms.py:52 content/models.py:249
msgid "Please upload a PDF-File to this PDF-Page."
msgstr "Bitte eine PDF Datei für diese PDF Seite hochladen."
#: src/content/models.py:51
#: content/models.py:51
msgid "Headline"
msgstr "Schlagzeile"
#: src/content/models.py:53
#: content/models.py:53
msgid "Content"
msgstr "Inhalt"
#: src/content/models.py:55 src/content/models.py:234
#: src/content/templates/content/article_detail.html:25
#: content/models.py:55 content/models.py:279
#: content/templates/content/article_detail.html:25
msgid "Category"
msgstr "Kategorie"
#: src/content/models.py:56 src/content/models.py:228
#: content/models.py:56 content/models.py:273
msgid "Image"
msgstr "Bild"
#: src/content/models.py:58 src/content/models.py:230
#: content/models.py:58 content/models.py:275
msgid "Slug"
msgstr "Slug"
#: src/content/models.py:60
#: src/content/templates/content/article_detail.html:23
#: content/models.py:60 content/templates/content/article_detail.html:23
msgid "Author"
msgstr "Autor"
#: src/content/models.py:61
#: content/models.py:61
msgid "Status"
msgstr "Status"
#: src/content/models.py:63
#: content/models.py:63
msgid "Created"
msgstr "Erstellt"
#: src/content/models.py:64
#: content/models.py:64
msgid "Modified"
msgstr "Bearbeitet"
#: src/content/models.py:68
#: content/models.py:68
msgid "Article"
msgstr "Artikel"
#: src/content/models.py:69
#: content/models.py:69
msgid "Articles"
msgstr "Artikel"
#: src/content/models.py:126 src/content/models.py:132
#: content/models.py:126 content/models.py:132
msgid "The short name for the menu-entry of this page"
msgstr "Ein kurzer Name für den Menüeintrag"
#: src/content/models.py:136 src/content/models.py:139
msgid "This title appears in the HTML header"
msgstr "Der Titel erscheint im HTML Header"
#: content/models.py:137 content/models.py:142
msgid "The page title as you'd like it to be seen by the public"
msgstr ""
#: src/content/models.py:140
#: content/models.py:144
msgid "slug"
msgstr "Slug"
#: src/content/models.py:141
#: content/models.py:146
msgid ""
"The name of the page as it will appear in URLs e.g http://domain.com/blog/"
"[my-slug]/"
msgstr ""
#: content/models.py:153
msgid "Path"
msgstr "Pfad"
#: src/content/models.py:147
#: content/models.py:165
msgid "Position"
msgstr "Position"
#: src/content/models.py:149
#: content/models.py:170
msgid "status"
msgstr "Status"
#: src/content/models.py:155
#: content/models.py:172 content/models.py:173
#, fuzzy
#| msgid "Description"
msgid "search description"
msgstr "Beschreibung"
#: content/models.py:176
#, fuzzy
#| msgid "Content"
msgid "content type"
msgstr "Inhalt"
#: content/models.py:181
msgid "enable comments"
msgstr "Kommentare möglich"
#: src/content/models.py:156
#: content/models.py:186
msgid "Template"
msgstr "Vorlage"
#: src/content/models.py:219
#: content/models.py:194
#, fuzzy
#| msgid "created on"
msgid "first created at"
msgstr "erstellt am"
#: content/models.py:199
msgid "latest updated at"
msgstr ""
#: content/models.py:264
msgid "Page"
msgstr "Seite"
#: src/content/models.py:220
#: content/models.py:265
msgid "Pages"
msgstr "Seiten"
#: src/content/models.py:224 src/content/models.py:225
#: content/models.py:269 content/models.py:270
msgid "Name"
msgstr "Name"
#: src/content/models.py:226 src/content/models.py:227
#: content/models.py:271 content/models.py:272
msgid "Description"
msgstr "Beschreibung"
#: src/content/models.py:235
#: content/models.py:280
msgid "Categories"
msgstr "Kategorien"
#: src/content/templates/content/article_archive.html:5
#: src/content/templates/content/article_archive.html:20
#: content/templates/content/article_archive.html:5
#: content/templates/content/article_archive.html:20
msgid "Article Archive"
msgstr "Nachrichtenarchiv"
#: src/content/templates/content/article_archive.html:35
#: src/content/templates/content/article_archive_month.html:5
#: src/content/templates/content/article_archive_year.html:7
#: content/templates/content/article_archive.html:35
#: content/templates/content/article_archive_month.html:5
#: content/templates/content/article_archive_year.html:7
msgid "Archive"
msgstr "Archiv"
#: src/content/templates/content/article_archive.html:52
#: content/templates/content/article_archive.html:52
msgid "All Categories"
msgstr "Alle Kategorien"
#: src/content/templates/content/article_archive.html:67
#: content/templates/content/article_archive.html:67
msgid "created on"
msgstr "erstellt am"
#: src/content/templates/content/article_archive.html:68
#: content/templates/content/article_archive.html:68
msgid "by"
msgstr "von"
#: src/content/templates/content/article_archive.html:69
#: content/templates/content/article_archive.html:69
msgid "comments"
msgstr "Kommentare"
#: src/content/templates/content/article_archive.html:73
#: content/templates/content/article_archive.html:73
msgid "Read More"
msgstr "Mehr lesen"
#: src/content/templates/content/article_archive.html:76
#: content/templates/content/article_archive.html:76
msgid "We're sorry. Your search yielded no results."
msgstr "Es tut uns leid. Deine Suche ergab keine Treffer."
#: src/content/templates/content/article_archive.html:94
#: content/templates/content/article_archive.html:94
msgid "Add Article"
msgstr "neuer Artikel "
#: src/content/templates/content/article_archive_month.html:7
#: content/templates/content/article_archive_month.html:7
msgid "back"
msgstr "Zurück"
#: src/content/templates/content/article_detail.html:24
#: content/templates/content/article_detail.html:24
msgid "Created on"
msgstr "Erstellt am"
#: src/content/templates/content/article_detail.html:36
#: content/templates/content/article_detail.html:36
msgid "share on"
msgstr "Teile auf"
#: src/content/templates/content/article_detail.html:51
#: src/content/templates/content/article_form.html:17 src/content/views.py:88
#: content/templates/content/article_detail.html:51
#: content/templates/content/article_form.html:24 content/views.py:88
msgid "Edit Article"
msgstr "Artikel bearbeiten"
#: src/content/templates/content/article_form.html:17 src/content/views.py:90
#: content/templates/content/article_form.html:24 content/views.py:90
msgid "Create Article"
msgstr "Artikel erstellen"
#: src/content/templates/content/article_form.html:22
#: src/content/templates/content/page_form.html:39
#: src/content/templates/content/page_form.html:46
#: content/templates/content/article_form.html:29
#: content/templates/content/page_form.html:49
#: content/templates/content/page_form.html:56
msgid "German"
msgstr "Deutsch"
#: src/content/templates/content/article_form.html:23
#: src/content/templates/content/page_form.html:40
#: src/content/templates/content/page_form.html:54
#: content/templates/content/article_form.html:30
#: content/templates/content/page_form.html:50
#: content/templates/content/page_form.html:64
msgid "English"
msgstr "Englisch"
#: src/content/templates/content/article_form.html:42
#: src/content/templates/content/page_form.html:63
#: content/templates/content/article_form.html:49
#: content/templates/content/page_form.html:73
msgid "reset"
msgstr "Zurücksetzen"
#: src/content/templates/content/article_form.html:43
#: src/content/templates/content/page_form.html:64
#: content/templates/content/article_form.html:50
#: content/templates/content/page_form.html:74
msgid "save"
msgstr "Speichern"
#: src/content/templates/content/page_form.html:5
#: src/content/templates/content/page_form.html:32
#: content/templates/content/page_form.html:5
#: content/templates/content/page_form.html:42
msgid "Edit Page"
msgstr "Seite bearbeiten"
#: src/content/templates/content/page_form.html:5
#: src/content/templates/content/page_form.html:18
#: src/content/templates/content/page_form.html:32
#: content/templates/content/page_form.html:5
#: content/templates/content/page_form.html:28
#: content/templates/content/page_form.html:42
msgid "Add Page"
msgstr "Seite hinzufügen"
#: src/content/templates/content/page_form.html:17
#: content/templates/content/page_form.html:27
msgid "Edit"
msgstr "Bearbeiten"
#: src/content/templates/content/page_form.html:34
#: content/templates/content/page_form.html:44
msgid "HTML Specific"
msgstr "HTML spezifisch"
#: src/content/views.py:23
#: content/views.py:23
msgid "This Category does not exist."
msgstr "Diese Kategorie existiert nicht."
#: src/content/views.py:157
#: content/views.py:157
#, python-format
msgid "No Page found matching the Path %s"
msgstr "Keine Seite unter dem Pfad %s gefunden"
#: src/content/views.py:172
#: content/views.py:172
#, python-format
msgid "No PDF Document found matching the Path %s"
msgstr "Kein PDF Dokument unter dem Pfad %s gefunden."
#~ msgid "This title appears in the HTML header"
#~ msgstr "Der Titel erscheint im HTML Header"
#~ msgid "Share on Google+"
#~ msgstr "Auf Google+ teilen"

View File

@@ -148,6 +148,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='page',
unique_together=set([('slug', 'parent')]),
unique_together={('slug', 'parent')},
),
]

View File

@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
from django.db import models
import ckeditor.fields

View File

@@ -15,46 +15,55 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='page',
name='date_created',
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='first created at', editable=False, db_index=True),
field=models.DateTimeField(default=django.utils.timezone.now,
verbose_name='first created at', editable=False, db_index=True),
),
migrations.AddField(
model_name='page',
name='date_modified',
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='latest updated at', editable=False),
field=models.DateTimeField(
default=django.utils.timezone.now, verbose_name='latest updated at', editable=False),
),
migrations.AlterField(
model_name='article',
name='date_created',
field=models.DateTimeField(auto_now_add=True, verbose_name='Erstellt'),
field=models.DateTimeField(
auto_now_add=True, verbose_name='Erstellt'),
),
migrations.AlterField(
model_name='page',
name='content_type',
field=models.IntegerField(verbose_name='Inhaltstyp', choices=[(0, 'Django View'), (1, 'HTML'), (2, 'PDF')]),
field=models.IntegerField(verbose_name='Inhaltstyp', choices=[
(0, 'Django View'), (1, 'HTML'), (2, 'PDF')]),
),
migrations.AlterField(
model_name='page',
name='path',
field=models.CharField(verbose_name='Pfad', unique=True, max_length=255, editable=False, db_index=True),
field=models.CharField(
verbose_name='Pfad', unique=True, max_length=255, editable=False, db_index=True),
),
migrations.AlterField(
model_name='page',
name='slug',
field=models.SlugField(help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=100, verbose_name='Slug'),
field=models.SlugField(
help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=100, verbose_name='Slug'),
),
migrations.AlterField(
model_name='page',
name='template',
field=models.CharField(default=b'content/page.html', max_length=255, verbose_name='Vorlage'),
field=models.CharField(
default=b'content/page.html', max_length=255, verbose_name='Vorlage'),
),
migrations.AlterField(
model_name='page',
name='title_de',
field=models.CharField(help_text="The page title as you'd like it to be seen by the public", max_length=255, verbose_name=b'Titel'),
field=models.CharField(
help_text="The page title as you'd like it to be seen by the public", max_length=255, verbose_name=b'Titel'),
),
migrations.AlterField(
model_name='page',
name='title_en',
field=models.CharField(help_text="The page title as you'd like it to be seen by the public", max_length=255, verbose_name=b'Title', blank=True),
field=models.CharField(help_text="The page title as you'd like it to be seen by the public",
max_length=255, verbose_name=b'Title', blank=True),
),
]

View File

@@ -14,11 +14,13 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='page',
name='date_created',
field=models.DateTimeField(auto_now_add=True, verbose_name='first created at', db_index=True),
field=models.DateTimeField(
auto_now_add=True, verbose_name='first created at', db_index=True),
),
migrations.AlterField(
model_name='page',
name='date_modified',
field=models.DateTimeField(auto_now=True, verbose_name='latest updated at'),
field=models.DateTimeField(
auto_now=True, verbose_name='latest updated at'),
),
]

View File

@@ -14,11 +14,13 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='page',
name='description_de',
field=models.TextField(verbose_name='search description', blank=True),
field=models.TextField(
verbose_name='search description', blank=True),
),
migrations.AddField(
model_name='page',
name='description_en',
field=models.TextField(verbose_name='search description', blank=True),
field=models.TextField(
verbose_name='search description', blank=True),
),
]

View File

@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from os import path
from ckeditor.fields import RichTextField
from django.conf import settings
from django.core.cache import cache
@@ -12,8 +10,7 @@ from django.utils import timezone
from django.utils.safestring import mark_safe
from django.utils.translation import get_language, ugettext as _
from utils import STATUS_CHOICES, STATUS_WAITING, STATUS_PUBLISHED, \
cleaner
from utils import STATUS_CHOICES, STATUS_WAITING, STATUS_PUBLISHED, CLEANER
CONTENT_CHOICES = (
(0, u'Django View'),
@@ -44,7 +41,10 @@ class ArticleManager(models.Manager):
'author', 'category')
def published(self):
return self.filter(status=STATUS_PUBLISHED, date_created__lte=timezone.now())
return self.filter(
status=STATUS_PUBLISHED,
date_created__lte=timezone.now()
)
class Article(models.Model):
@@ -74,8 +74,8 @@ class Article(models.Model):
self.date_created = timezone.now()
if not self.slug:
self.slug = slugify(self.headline_de)[:50]
self.content_de = cleaner.clean_html(self.content_de)
self.content_en = cleaner.clean_html(self.content_en)
self.content_de = CLEANER.clean_html(self.content_de)
self.content_en = CLEANER.clean_html(self.content_en)
def __str__(self):
return self.headline
@@ -120,6 +120,7 @@ class Page(models.Model):
Ist keine englische Übersetzung vorhanden, wird die deutsche Version
angeboten.
"""
menu_name_de = models.CharField(
max_length=255,
verbose_name='Menü Name',
@@ -143,7 +144,10 @@ class Page(models.Model):
slug = models.SlugField(
verbose_name=_('slug'),
max_length=100,
help_text=_("The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/")
help_text=_(
'The name of the page as it will appear in URLs e.g '
'http://domain.com/blog/[my-slug]/'
)
)
path = models.CharField(
max_length=255,
@@ -169,8 +173,10 @@ class Page(models.Model):
default=STATUS_WAITING,
verbose_name=_('status')
)
description_de = models.TextField(verbose_name=_('search description'), blank=True)
description_en = models.TextField(verbose_name=_('search description'), blank=True)
description_de = models.TextField(
verbose_name=_('search description'), blank=True)
description_en = models.TextField(
verbose_name=_('search description'), blank=True)
content_type = models.IntegerField(
choices=CONTENT_CHOICES,
verbose_name=_('content type'))
@@ -213,26 +219,34 @@ class Page(models.Model):
@property
def description(self):
return getattr(self, "description_%s" % get_language()) or self.description_de
lang_attr = "description_%s" % get_language()
return getattr(self, lang_attr, self.description_de)
@property
def menu_name(self):
return getattr(self,
"menu_name_%s" % get_language()) or self.menu_name_de
lang_attr = "menu_name_%s" % get_language()
return getattr(self, lang_attr, self.menu_name_de)
@property
def pdf_file(self):
return getattr(self, "pdf_%s" % get_language()) or self.pdf_de
lang_attr = "pdf_%s" % get_language()
return getattr(self, lang_attr, self.pdf_de)
@property
def title(self):
return getattr(self, "title_%s" % get_language()) or self.title_de
""" Return the translated title if available """
lang_attr = "title_%s" % get_language()
return getattr(self, lang_attr, self.title_de)
def clean(self):
"""
:return:
"""
if self.parent is None:
self.path = self.slug
else:
self.path = path.join(self.parent.path, self.slug)
self.path = '/'.join([self.parent.path, self.slug])
if self.content_type is None:
if self.pdf_de:
@@ -242,8 +256,8 @@ class Page(models.Model):
else:
self.content_type = 0
if self.content_type == 1:
self.content_de = cleaner.clean_html(self.content_de)
self.content_en = cleaner.clean_html(self.content_en)
self.content_de = CLEANER.clean_html(self.content_de)
self.content_en = CLEANER.clean_html(self.content_en)
elif self.content_type == 2 and not self.pdf_de.name:
raise ValidationError(
_(u'Please upload a PDF-File to this PDF-Page.'))

View File

@@ -1,6 +1,7 @@
from django.contrib.sitemaps import Sitemap
from .models import Article, Page
class ArticleSitemap(Sitemap):
changefreq = "never"
priority = 0.6
@@ -17,8 +18,7 @@ class PageSitemap(Sitemap):
priority = 0.4
def items(self):
return Page.objects.all() #filter(status__gt=0)
return Page.objects.all() # filter(status__gt=0)
def lastmod(self, page):
return page.date_modified

View File

@@ -49,10 +49,10 @@
{% block navigation %}
<ul id="navigation">
<li><a href="{{current_top_page.get_absolute_url}}" {% if not active_category %}class="active"{% endif %}>{% trans 'All Categories' %}</a></li>
<li><a href="{{current_top_page.get_absolute_url}}" {% if not active_category %} class="active"{% endif %}>{% trans 'All Categories' %}</a></li>
{% for category in categories %}
<li><a href="{% url 'article-archive' category=category.slug %}"
{% ifequal category.slug active_category.slug %}class="active"{% endifequal %}>{{ category.name }}</a></li>
{% ifequal category.slug active_category.slug %} class="active"{% endifequal %}>{{ category.name }}</a></li>
{% endfor %}
</ul>
{% endblock %}

View File

@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load i18n fieldset_extras %}
{% load i18n %}
{% block extra_head %}
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.min.js"></script>
@@ -15,11 +15,7 @@ window.onload = function () {
{% endblock %}
{% block maincontent %}
{% get_fieldset "category, image" from form as fieldset_common %}
{% get_fieldset "headline_en, content_en" from form as fieldset_en %}
{% get_fieldset "headline_en, content_en" from form as fieldset_en %}
<form action="" method="post" enctype="multipart/formdata">
<form action="" method="post" enctype="multipart/form-data">
<fieldset class="grid_12">
<legend>{% if object.pk %}{% trans "Edit Article" %}{% else %}{% trans "Create Article" %}{% endif %}</legend>
{% csrf_token %}

View File

@@ -50,7 +50,7 @@ window.onload = function () {
<li><a href="#en">{% trans "English" %}</a></li>
</ul>
<div class="tab_container"">
<div class="tab_container">
<section id="de" class="tab_content">
<fieldset class="grid_12">
<legend>{% trans "German" %}</legend>
@@ -67,7 +67,7 @@ window.onload = function () {
<br>
{{form.content_en}}
</section>
</div>
</div>
<p></p>
<p class="buttonbar grid_12">
<button type="reset"><span class="fa fa-undo"></span> {% trans 'reset' %}</button>

View File

@@ -60,7 +60,7 @@ body {
</div>
<div id="page_footer">
{{ page.title }} Seite:
<pdf:pagenumber>
<pdf:pagenumber />
</div>
</body>
</html>

View File

@@ -1,46 +0,0 @@
"""
Created on 10.06.2012
@author: christian
"""
import copy
from collections import OrderedDict
from django import template
register = template.Library()
class FieldSetNode(template.Node):
def __init__(self, form_variable, variable_name, fields):
self.fields = fields
self.variable_name = variable_name
self.form_variable = form_variable
def render(self, context):
form = template.Variable(self.form_variable).resolve(context)
new_form = copy.copy(form)
# new_form.fields = SortedDict([(key, value) for key, value in
# form.fields.items() if key in self.fields])
new_form.fields = OrderedDict(
[(key, form.fields[key]) for key in self.fields]
)
context[self.variable_name] = new_form
return u''
def get_fieldset(parser, token):
try:
_name_, fields, _from_, form, _as_, variable_name = \
token.split_contents()
fields = fields[1:-1]
fields = [field.strip() for field in fields.split(',')]
except ValueError:
raise template.TemplateSyntaxError(
'bad arguments for %r' % token.split_contents()[0]
)
return FieldSetNode(form, variable_name, fields)
get_fieldset = register.tag(get_fieldset)

View File

@@ -1,14 +0,0 @@
# -*- encoding: utf-8 -*-
"""
Created on 03.10.2011
@author: christian
"""
from django.conf.urls import url
from .views import ImageList, PageList
urlpatterns = [
url(r'^image_list.js$', ImageList.as_view(), name='content-image-list'),
url(r'^link_list.js$', PageList.as_view(), name='content-page-list'),
]

View File

@@ -1,31 +1,48 @@
# Create your views here.
import os
import django_comments as comments
import os
from csp.decorators import csp_update
from django.conf import settings
from django.http import HttpResponse, Http404
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from django.views import generic
from . import models, forms
from events.models import Photo
from utils.mixins import PermissionRequiredMixin
from . import models, forms
class ArticleArchiveMixin(object):
"""
Mixin View to add common context data to Views of the news article archive.
"""
def get_category(self, queryset):
try:
self.category = models.Category.objects.get(
slug=self.kwargs['category'])
return queryset.filter(category=self.category)
except models.Category.DoesNotExist:
raise Http404(_("This Category does not exist."))
except KeyError:
"""
Filter the queryset by category if one has been specified in the URL
:param queryset: an model.Article.objects Queryset
:return: an model.Article.objects Queryset filterd by category
"""
category_slug = self.kwargs.get('category')
if not category_slug:
self.category = None
return self.queryset
try:
self.category = models.Category.objects.get(slug=category_slug)
except models.Category.DoesNotExist:
raise Http404(_("This Category does not exist."))
return queryset.filter(category=self.category)
def get_context_data(self, **kwargs):
"""
Adds the categories and the active category to the template context.
:return: an django.template.context
"""
context = super(ArticleArchiveMixin, self).get_context_data(**kwargs)
context['categories'] = models.Category.objects.all()
context['active_category'] = self.category
@@ -33,6 +50,10 @@ class ArticleArchiveMixin(object):
class ArticleArchiveIndex(ArticleArchiveMixin, generic.ArchiveIndexView):
"""
Displays the latest news and the filters to browse the archives.
"""
queryset = models.Article.objects.filter(status=models.STATUS_PUBLISHED)
date_field = 'date_created'
paginate_by = 5
@@ -40,12 +61,21 @@ class ArticleArchiveIndex(ArticleArchiveMixin, generic.ArchiveIndexView):
allow_empty = True
def get_queryset(self):
queryset = generic.ArchiveIndexView.get_queryset(self)
queryset = self.get_category(queryset)
return queryset
"""
Filter the Queryset by category.
:return: models.Article.objects queryset
"""
return self.get_category(
super(ArticleArchiveIndex, self).get_queryset()
)
class ArticleYearArchive(ArticleArchiveMixin, generic.YearArchiveView):
"""
Displays the Articles filterd by a specific year
"""
queryset = models.Article.objects.filter(status=models.STATUS_PUBLISHED)
date_field = 'date_created'
paginate_by = 5
@@ -54,12 +84,21 @@ class ArticleYearArchive(ArticleArchiveMixin, generic.YearArchiveView):
allow_empty = True
def get_queryset(self):
queryset = generic.YearArchiveView.get_queryset(self)
queryset = self.get_category(queryset)
return queryset
"""
Filter the Queryset by category.
:return: models.Article.objects queryset
"""
return self.get_category(
super(ArticleYearArchive, self).get_queryset()
)
class ArticleMonthArchive(ArticleArchiveMixin, generic.MonthArchiveView):
"""
Displays the Articles filterd by a specific month
"""
queryset = models.Article.objects.filter(status=models.STATUS_PUBLISHED)
date_field = 'date_created'
month_format = '%m'
@@ -68,16 +107,28 @@ class ArticleMonthArchive(ArticleArchiveMixin, generic.MonthArchiveView):
allow_empty = True
def get_queryset(self):
queryset = generic.MonthArchiveView.get_queryset(self)
queryset = self.get_category(queryset)
return queryset
"""
Filter the Queryset by category.
:return: models.Article.objects queryset
"""
return self.get_category(
super(ArticleMonthArchive, self).get_queryset()
)
class ArticleDetail(generic.DetailView):
"""
Render the news Article, but only if it got published.
"""
queryset = models.Article.objects.filter(status=models.STATUS_PUBLISHED)
class ArticleForm(PermissionRequiredMixin, generic.UpdateView):
"""
View to add or edit an Article
"""
model = models.Article
form_class = forms.ArticleForm
permission_required = 'content.change_article'
@@ -97,28 +148,11 @@ class ArticleForm(PermissionRequiredMixin, generic.UpdateView):
return models.Article(author=self.request.user)
class ImageList(generic.View):
# noinspection PyMethodMayBeStatic
def get(self, kwargs):
image_list = []
response = HttpResponse(content_type='text/javascript')
response.write('var tinyMCEImageList = new Array(')
os.chdir(settings.MEDIA_ROOT)
for dirpath, dirnames, filenames in os.walk(
'images'): # @UnusedVariable @IgnorePep8
filenames.sort()
for filename in filenames:
image_list.append('["%(name)s", "%(path)s"]' % {
'name': os.path.join(dirpath, filename),
'path': os.path.join(settings.MEDIA_URL, dirpath, filename)
})
response.write(', '.join(image_list))
response.write(');')
return response
class PageAddForm(PermissionRequiredMixin, generic.CreateView):
"""
Renders an Form to create a new page for users with conforming permissions.
"""
form_class = forms.PageForm
template_name = 'content/page_form.html'
permission_required = 'content.add_page'
@@ -132,8 +166,16 @@ class PageAddForm(PermissionRequiredMixin, generic.CreateView):
parent = models.Page.objects.get(path=path)
return {'parent': parent}
@method_decorator(csp_update(SCRIPT_SRC="'unsafe-eval'"))
def dispatch(self, *args, **kwargs):
return super(PageAddForm, self).dispatch(*args, **kwargs)
class PageEditForm(PermissionRequiredMixin, generic.UpdateView):
"""
Renders an Form to edit a page for users with conforming permissions.
"""
form_class = forms.PageForm
permission_required = 'content.change_page'
@@ -145,6 +187,10 @@ class PageEditForm(PermissionRequiredMixin, generic.UpdateView):
path = path[:-1]
return models.Page.objects.get(path=path)
@method_decorator(csp_update(SCRIPT_SRC="'unsafe-eval'"))
def dispatch(self, *args, **kwargs):
return super(PageEditForm, self).dispatch(*args, **kwargs)
class PageHtml(generic.DetailView):
@@ -184,23 +230,6 @@ class PagePdf(generic.DeleteView):
raise Http404('File not Found %s.pdf' % self.kwargs['path'])
class PageList(generic.View):
# noinspection PyMethodMayBeStatic
def get(self, kwargs):
response = HttpResponse(content_type='text/javascript')
response.write('var tinyMCELinkList = new Array(')
page_list = []
for page in models.Page.objects.filter(status=models.STATUS_PUBLISHED):
page_list.append('["%(name)s", "%(path)s"]' % {
'name': page.menu_name,
'path': page.get_absolute_url()
})
response.write(', '.join(page_list))
response.write(');')
return response
class StartPage(generic.TemplateView):
template_name = 'index.html'