MAIN_PAGE_ENTRY = None
- TYPES_DICT = None
def _more_TYPES_DICT(self, value):
return dict((t.db, t) for t in self.TYPES)
+ TYPES_DICT = None
- TYPES_ON_MAIN = None
def _more_TYPES_ON_MAIN(self, value):
return tuple(t.db for t in self.TYPES if t.on_main)
+ TYPES_ON_MAIN = None
- TYPES_PROMOTABLE = None
def _more_TYPES_PROMOTABLE(self, value):
return tuple(t.db for t in self.TYPES if t.promotable)
+ TYPES_PROMOTABLE = None
- OBLIGATORY_LANGUAGES = None
def _more_OBLIGATORY_LANGUAGES(self, value):
- return value or tuple(lang for lang in settings.LANGUAGES
- if lang[0] == settings.LANGUAGE_CODE)
+ return value or tuple(lang for lang in settings.LANGUAGES if lang[0] == settings.LANGUAGE_CODE)
+ OBLIGATORY_LANGUAGES = None
- OPTIONAL_LANGUAGES = None
def _more_OPTIONAL_LANGUAGES(self, value):
- return tuple(lang for lang in settings.LANGUAGES
- if lang not in self.OBLIGATORY_LANGUAGES)
+ return tuple(lang for lang in settings.LANGUAGES if lang not in self.OBLIGATORY_LANGUAGES)
+ OPTIONAL_LANGUAGES = None
app_settings = Settings('MIGDAL')
for lang_code, lang_name in settings.LANGUAGES
])
- list_display = translated_fields(('title',),
- app_settings.OBLIGATORY_LANGUAGES) + \
- ('date', 'author') + \
- _promo_if_necessary + \
- ('in_stream', 'first_published_at',) + \
- translated_fields(('published_at',)) + \
- translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
+ list_display = translated_fields(('title',), app_settings.OBLIGATORY_LANGUAGES) + \
+ ('date', 'author') + \
+ _promo_if_necessary + \
+ ('in_stream', 'first_published_at',) + \
+ translated_fields(('published_at',)) + \
+ translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
list_filter = _promo_if_necessary + \
- translated_fields(('published',)) + \
- translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
+ translated_fields(('published',)) + \
+ translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
inlines = (AttachmentInline,)
search_fields = ('title_pl', 'title_en')
return EntryAdmin
# This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
-from itertools import chain
from migdal.models import Entry
from migdal import app_settings
from django.utils.translation import get_language
-def entry_list(entry_type=None, category=None, promobox=False,
- for_feed=False):
+def entry_list(entry_type=None, category=None, promobox=False, for_feed=False):
lang = get_language()
object_list = Entry.objects.filter(**{"published_%s" % lang: True})
if category:
object_list = object_list.filter(categories=category)
- if promobox:
- promo = list(object_list.filter(promo=True)[:promobox])
- #object_list = object_list.exclude(pk__in=[p.pk for p in promo])
-
object_list = object_list.filter(in_stream=True)
if promobox:
+ promo = list(object_list.filter(promo=True)[:promobox])
+ # object_list = object_list.exclude(pk__in=[p.pk for p in promo])
object_list.promobox = promo
return object_list
#
from django.db import models
+
class SlugNullField(models.SlugField):
description = "SlugField that stores NULL instead of blank value."
- def to_python(self, value, **kwargs):
- value = super(SlugNullField, self).to_python(value, **kwargs)
+ def to_python(self, value):
+ value = super(SlugNullField, self).to_python(value)
return value if value is not None else u""
def get_prep_value(self, value, **kwargs):
- value = super(SlugNullField, self).get_prep_value(value, **kwargs)
+ value = super(SlugNullField, self).get_prep_value(value)
return value or None
from django import forms
from django import template
from django.utils.translation import ugettext_lazy as _, get_language
-from fnpdjango.utils.text.slughifi import slughifi
+from slugify import slugify
from migdal.models import Entry
from migdal import app_settings
class SubmitForm(forms.ModelForm):
class Meta:
model = Entry
- fields = ['title_%s' % lang, 'lead_%s' % lang,
- 'author', 'author_email', 'categories']
+ fields = ['title_%s' % lang, 'lead_%s' % lang, 'author', 'author_email', 'categories']
required = ['title_%s' % lang]
def __init__(self, *args, **kwargs):
def clean(self):
data = super(SubmitForm, self).clean()
data['type'] = app_settings.TYPE_SUBMIT
- orig_slug = slughifi(data.get('title_%s' % lang, ''))[:47]
+ orig_slug = slugify(data.get('title_%s' % lang, ''))[:47]
slug = orig_slug
number = 2
while Entry.objects.filter(**{'slug_%s' % lang: slug}).exists():
setattr(entry, f, self.cleaned_data[f])
entry.save()
entry = super(SubmitForm, self).save(*args, **kwargs)
- mail_managers(u"Nowy wpis",
+ mail_managers(
+ u"Nowy wpis",
template.loader.get_template(
'migdal/mail/manager_new_entry.txt').render(
template.Context({
'site': Site.objects.get_current(),
})))
- return SubmitForm(*args, **kwargs)
\ No newline at end of file
+ return SubmitForm(*args, **kwargs)
# This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
+
+
class EntryType(object):
- def __init__(self, db, slug, commentable=False, on_main=False,
- promotable=False, categorized=False):
+ def __init__(self, db, slug, commentable=False, on_main=False, promotable=False, categorized=False):
self.db = db
self.slug = slug
self.commentable = commentable
import re
from datetime import datetime
from django.conf import settings
-from django.contrib.comments.signals import comment_will_be_posted
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.core.mail import mail_managers, send_mail
from django.db import models
from django.template import loader, Context
-from django.utils.translation import get_language, ugettext_lazy as _, ugettext
+from django.utils.translation import ugettext_lazy as _, ugettext
from django_comments_xtd.models import XtdComment
from markupfield.fields import MarkupField
from fnpdjango.utils.models.translation import add_translatable, tQ
from migdal import app_settings
from migdal.fields import SlugNullField
+
class Category(models.Model):
- taxonomy = models.CharField(_('taxonomy'), max_length=32,
- choices=app_settings.TAXONOMIES)
+ taxonomy = models.CharField(_('taxonomy'), max_length=32, choices=app_settings.TAXONOMIES)
class Meta:
verbose_name = _('category')
@models.permalink
def get_absolute_url(self):
- return ('migdal_category', [self.slug])
+ return 'migdal_category', [self.slug]
add_translatable(Category, {
tQ(published=True)
)
+
class Entry(models.Model):
- type = models.CharField(max_length=16,
- choices=((t.db, t.slug) for t in app_settings.TYPES),
- db_index=True)
+ type = models.CharField(
+ max_length=16,
+ choices=((t.db, t.slug) for t in app_settings.TYPES),
+ db_index=True)
date = models.DateTimeField(_('created at'), auto_now_add=True, db_index=True)
changed_at = models.DateTimeField(_('changed at'), auto_now=True, db_index=True)
author = models.CharField(_('author'), max_length=128)
- author_email = models.EmailField(_('author email'), max_length=128, null=True, blank=True,
- help_text=_('Used only to display gravatar and send notifications.'))
+ author_email = models.EmailField(
+ _('author email'), max_length=128, null=True, blank=True,
+ help_text=_('Used only to display gravatar and send notifications.'))
image = models.ImageField(_('image'), upload_to='entry/image/', null=True, blank=True)
promo = models.BooleanField(_('promoted'), default=False)
in_stream = models.BooleanField(_('in stream'), default=True)
categories = models.ManyToManyField(Category, null=True, blank=True, verbose_name=_('categories'))
first_published_at = models.DateTimeField(_('published at'), null=True, blank=True)
- canonical_url = models.URLField(_('canonical link'), null = True, blank = True)
+ canonical_url = models.URLField(_('canonical link'), null=True, blank=True)
objects = models.Manager()
published_objects = PublishedEntryManager()
@models.permalink
def get_absolute_url(self):
- return ('migdal_entry_%s' % self.type, [self.slug])
+ return 'migdal_entry_%s' % self.type, [self.slug]
def get_type(self):
return dict(app_settings.TYPES_DICT)[self.type]
add_translatable(Entry, {
'slug': SlugNullField(unique=True, db_index=True, null=True, blank=True),
'title': models.CharField(_('title'), max_length=255, null=True, blank=True),
- 'lead': MarkupField(_('lead'), markup_type='textile_pl', null=True, blank=True,
- help_text=_('Use <a href="http://textile.thresholdstate.com/">Textile</a> syntax.')),
- 'body': MarkupField(_('body'), markup_type='textile_pl', null=True, blank=True,
- help_text=_('Use <a href="http://textile.thresholdstate.com/">Textile</a> syntax.')),
+ 'lead': MarkupField(
+ _('lead'), markup_type='textile_pl', null=True, blank=True,
+ help_text=_('Use <a href="http://textile.thresholdstate.com/">Textile</a> syntax.')),
+ 'body': MarkupField(
+ _('body'), markup_type='textile_pl', null=True, blank=True,
+ help_text=_('Use <a href="http://textile.thresholdstate.com/">Textile</a> syntax.')),
'published': models.BooleanField(_('published'), default=False),
'published_at': models.DateTimeField(_('published at'), null=True, blank=True),
})
return self.file.url if self.file else ''
-
def notify_new_comment(sender, instance, created, **kwargs):
- if (created and isinstance(instance.content_object, Entry) and
- instance.content_object.author_email):
+ if created and isinstance(instance.content_object, Entry) and instance.content_object.author_email:
site = Site.objects.get_current()
mail_text = loader.get_template('migdal/mail/new_comment.txt').render(
Context({
def spamfilter(sender, comment, **kwargs):
"""Very simple spam filter. Just don't let any HTML links go through."""
if re.search(r"<a\s+href=", comment.comment):
- fields = (comment.user, comment.user_name, comment.user_email,
+ fields = (
+ comment.user, comment.user_name, comment.user_email,
comment.user_url, comment.submit_date, comment.ip_address,
comment.followup, comment.comment)
- mail_managers(u"Spam filter report",
+ mail_managers(
+ u"Spam filter report",
(u"""This comment was turned down as SPAM: \n""" +
- """\n%s""" * len(fields) +
- """\n\nYou don't have to do anything.""") % fields)
+ """\n%s""" * len(fields) +
+ """\n\nYou don't have to do anything.""") % fields)
return False
return True
-comment_will_be_posted.connect(spamfilter)
+# comment_will_be_posted.connect(spamfilter)
-import datetime
+# -*- coding: utf-8 -*-
+# This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
from django.conf import settings
from haystack import indexes
from fnpdjango.utils.models.translation import add_translatable_index, localize_field
class EntryIndex(indexes.SearchIndex, indexes.Indexable):
- text = indexes.CharField(null=True,
+ text = indexes.CharField(
+ null=True,
model_attr=localize_field('body', settings.LANGUAGE_CODE),
document=True)
date = indexes.DateTimeField(indexed=True, model_attr="date")
+# -*- coding: utf-8 -*-
+# This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
from django.contrib.sitemaps import Sitemap
from django.utils.translation import override
from .models import Entry
from django.conf import settings
+
class MigdalSitemap(Sitemap):
changefreq = "never"
priority = 0.5
from django.contrib import comments
from django import template
from migdal import app_settings
-from migdal.models import Category, Entry
-from django.utils.translation import ugettext_lazy as _
+from migdal.models import Category
register = template.Library()
def categories(context, taxonomy):
context = {
'request': context['request'],
- 'object_list': Category.objects.filter(taxonomy=taxonomy
- ).exclude(entry__isnull=True)
+ 'object_list': Category.objects.filter(taxonomy=taxonomy).exclude(entry__isnull=True)
}
return context
@register.inclusion_tag('migdal/last_comments.html')
def last_comments(limit=app_settings.LAST_COMMENTS):
- return {'object_list':
- XtdComment.objects.filter(is_public=True, is_removed=False).order_by('-submit_date')[:limit]}
+ return {
+ 'object_list': XtdComment.objects.filter(is_public=True, is_removed=False).order_by('-submit_date')[:limit]}
@register.inclusion_tag(['comments/form.html'])
+# -*- coding: utf-8 -*-
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.conf import settings
-from django.conf.urls import patterns, include, url, handler404
+from django.conf.urls import patterns, url
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import string_concat
from migdal import feeds, app_settings
]
-urlpatterns = i18n_patterns('',
+urlpatterns = i18n_patterns(
+ '',
# main page
url(r'^$', 'migdal.views.main', name='migdal_main'),
url(r'^rss.xml$', feeds.EntriesFeed(), name='migdal_main_feed'),
# submit new entry
url(string_concat(r'^', _('submit'), r'/$'), 'migdal.views.submit', name='migdal_submit'),
- url(string_concat(r'^', _('submit'), r'/', _('thanks'), r'$'), 'migdal.views.submit_thanks', name='migdal_submit_thanks'),
+ url(string_concat(r'^', _('submit'), r'/', _('thanks'), r'$'), 'migdal.views.submit_thanks',
+ name='migdal_submit_thanks'),
# category
url(string_concat(r'^', _('categories'), r'/(?P<category_slug>[^/]*)/$'),
'migdal.views.entry_list', name='migdal_category'),
if 'django.contrib.sitemaps' in settings.INSTALLED_APPS:
from .sitemap import sitemaps
- urlpatterns += patterns('',
+ urlpatterns += patterns(
+ '',
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {
'sitemaps': sitemaps
}),
)
-
promobox = 5 if entry_type is None and category is None else None
- object_list = api.entry_list(entry_type=entry_type, category=category,
- promobox=promobox)
+ object_list = api.entry_list(entry_type=entry_type, category=category, promobox=promobox)
return render(request, templates, {
'object_list': object_list,
'submit_form': submit_form,
})
+
def submit_thanks(request):
return render(request, "migdal/entry/submit_thanks.html")
def get_results(self):
results = super(SearchPublishedView, self).get_results()
lang_code = get_language()
+
def is_published(entity):
if isinstance(entity, Entry):
- return getattr(entity, "published_%s" % lang_code) == True
+ return getattr(entity, "published_%s" % lang_code)
else:
return True
results = filter(lambda r: is_published(r.object), results)
import os.path
from setuptools import setup, find_packages
+
def whole_trees(package_dir, paths):
def whole_tree(prefix, path):
files = []
- for f in (f for f in os.listdir(os.path.join(prefix, path)) if not f[0]=='.'):
+ for f in (f for f in os.listdir(os.path.join(prefix, path)) if f[0] != '.'):
new_path = os.path.join(path, f)
if os.path.isdir(os.path.join(prefix, new_path)):
files.extend(whole_tree(prefix, new_path))
version='0.4',
author='Radek Czajka',
author_email='radoslaw.czajka@nowoczesnapolska.org.pl',
- url = '',
+ url='',
packages=find_packages(),
- package_data={'migdal': whole_trees('migdal',
- ['templates', 'locale'])},
+ package_data={'migdal': whole_trees('migdal', ['templates', 'locale'])},
license='LICENSE',
description='.',
long_description="",