Pinned Django on < 2.0 for better compatibility.
Mainlined traslation code for better DRY workflow. Fixed the EventDetail Mixin.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
django
|
django < 2.0
|
||||||
django-appconf
|
django-appconf
|
||||||
django-ckeditor
|
django-ckeditor
|
||||||
django-contrib-comments
|
django-contrib-comments
|
||||||
@@ -18,4 +18,4 @@ pytz
|
|||||||
requests
|
requests
|
||||||
requests-oauthlib
|
requests-oauthlib
|
||||||
social-auth-app-django
|
social-auth-app-django
|
||||||
social-auth-core
|
social-auth-core
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ def get_upload_path(instance, filename):
|
|||||||
return "categories/%s.%s" % (instance.slug, extension)
|
return "categories/%s.%s" % (instance.slug, extension)
|
||||||
|
|
||||||
|
|
||||||
|
def get_localized(obj, attr):
|
||||||
|
""" Return the localilzed field, or the fallback if the localized is empty.
|
||||||
|
"""
|
||||||
|
fallback = attr + '_de'
|
||||||
|
localized = attr + '_' + get_language()[:2]
|
||||||
|
return getattr(obj, localized) or getattr(obj, fallback)
|
||||||
|
|
||||||
|
|
||||||
class ArticleManager(models.Manager):
|
class ArticleManager(models.Manager):
|
||||||
"""Adds some predifined querys and joins some tables for faster querys."""
|
"""Adds some predifined querys and joins some tables for faster querys."""
|
||||||
|
|
||||||
@@ -118,16 +126,12 @@ class Article(models.Model):
|
|||||||
@property
|
@property
|
||||||
def headline(self):
|
def headline(self):
|
||||||
"""Return the localized headline, fallback to german if necessary."""
|
"""Return the localized headline, fallback to german if necessary."""
|
||||||
return mark_safe(
|
return mark_safe(get_localized(self, 'headline'))
|
||||||
getattr(self, "headline_%s" % get_language(), self.headline_de)
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def content(self):
|
def content(self):
|
||||||
"""Return the localized content, fallback to german if necessary."""
|
"""Return the localized content, fallback to german if necessary."""
|
||||||
return mark_safe(
|
return mark_safe(get_localized(self, 'content'))
|
||||||
getattr(self, "content_%s" % get_language(), self.content_de)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Category(models.Model):
|
class Category(models.Model):
|
||||||
@@ -149,13 +153,12 @@ class Category(models.Model):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the localized name, fallback to german if necessary."""
|
"""Return the localized name, fallback to german if necessary."""
|
||||||
return getattr(self, "name_%s" % get_language(), self.name_de)
|
return get_localized(self, 'name')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def description(self):
|
def description(self):
|
||||||
"""Return the localized description, fallback to german if necessary."""
|
"""Return the localized description, fallback to german if necessary."""
|
||||||
return getattr(self, "description_%s" % get_language(),
|
return get_localized(self, 'description')
|
||||||
self.description_de)
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
"""Return the URL of the article archive, filtered on this category."""
|
"""Return the URL of the article archive, filtered on this category."""
|
||||||
@@ -264,9 +267,7 @@ class Page(models.Model):
|
|||||||
@property
|
@property
|
||||||
def content(self):
|
def content(self):
|
||||||
"""Return the localized content, fallback to german if necessary."""
|
"""Return the localized content, fallback to german if necessary."""
|
||||||
return mark_safe(
|
return mark_safe(get_localized(self, 'content'))
|
||||||
getattr(self, "content_%s" % get_language()) or self.content_de
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def css_class(self):
|
def css_class(self):
|
||||||
@@ -278,24 +279,22 @@ class Page(models.Model):
|
|||||||
@property
|
@property
|
||||||
def description(self):
|
def description(self):
|
||||||
"""Return the localized description, fallback to german if necessary."""
|
"""Return the localized description, fallback to german if necessary."""
|
||||||
return getattr(self,
|
return get_localized(self, 'description')
|
||||||
"description_%s" % get_language()) or self.description_de
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def menu_name(self):
|
def menu_name(self):
|
||||||
"""Return the localized menu name, fallback to german if necessary."""
|
"""Return the localized menu name, fallback to german if necessary."""
|
||||||
return getattr(self,
|
return get_localized(self, 'menu_name')
|
||||||
"menu_name_%s" % get_language()) or self.menu_name_de
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pdf_file(self):
|
def pdf_file(self):
|
||||||
"""Return the localized PDF file, fallback to german if necessary."""
|
"""Return the localized PDF file, fallback to german if necessary."""
|
||||||
return getattr(self, "pdf_%s" % get_language(), self.pdf_de)
|
return get_localized(self, 'pdf_file')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
"""Return the localized title, fallback to german if necessary."""
|
"""Return the localized title, fallback to german if necessary."""
|
||||||
return getattr(self, "title_%s" % get_language()) or self.title_de
|
return get_localized(self, 'title')
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""set the URL path, the right content type, and scrub the HTML code."""
|
"""set the URL path, the right content type, and scrub the HTML code."""
|
||||||
|
|||||||
@@ -48,9 +48,13 @@ class EventDetailMixin(object):
|
|||||||
|
|
||||||
:return: a django QuerySets
|
:return: a django QuerySets
|
||||||
"""
|
"""
|
||||||
try:
|
if self.model == models.Event:
|
||||||
self.event = models.Event.objects.get(pk=self.kwargs['event'])
|
self.event = models.Event.objects.get(pk=self.kwargs['pk'])
|
||||||
queryset = self.model.objects.filter(event=self.event)
|
queryset = self.model.objects.all()
|
||||||
except models.Event.DoesNotExist:
|
else:
|
||||||
raise Http404(_('Event does not exist'))
|
try:
|
||||||
|
self.event = models.Event.objects.get(pk=self.kwargs['event'])
|
||||||
|
queryset = self.model.objects.filter(event=self.event)
|
||||||
|
except models.Event.DoesNotExist:
|
||||||
|
raise Http404(_('Event does not exist'))
|
||||||
return queryset.prefetch_related()
|
return queryset.prefetch_related()
|
||||||
|
|||||||
Reference in New Issue
Block a user