View fixes
This commit is contained in:
parent
0cbc314068
commit
ed6e331f62
2 changed files with 8 additions and 29 deletions
|
@ -66,8 +66,8 @@ class Post(TranslatableModel):
|
|||
related_name='blog_post_thumbnail',
|
||||
blank=True, null=True)
|
||||
main_image_full = models.ForeignKey(ThumbnailOption,
|
||||
related_name='blog_post_full',
|
||||
blank=True, null=True)
|
||||
related_name='blog_post_full',
|
||||
blank=True, null=True)
|
||||
|
||||
translations = TranslatedFields(
|
||||
title=models.CharField(max_length=255),
|
||||
|
@ -104,13 +104,13 @@ class Post(TranslatableModel):
|
|||
|
||||
def thumbnail_options(self):
|
||||
if self.main_image_thumbnail_id:
|
||||
return self.main_image_thumbnail.as_dict()
|
||||
return self.main_image_thumbnail.as_dict
|
||||
else:
|
||||
return settings.BLOG_IMAGE_THUMBNAIL_SIZE
|
||||
|
||||
def full_image_options(self):
|
||||
if self.main_image_fulll_id:
|
||||
return self.main_image_full.as_dict()
|
||||
return self.main_image_full.as_dict
|
||||
else:
|
||||
return settings.BLOG_IMAGE_FULL_SIZE
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import datetime
|
|||
|
||||
from django.core.urlresolvers import resolve
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic import ListView, DetailView, ArchiveIndexView
|
||||
from django.views.generic import ListView, DetailView
|
||||
from hvad.admin import TranslatableModelAdminMixin
|
||||
|
||||
from .models import Post
|
||||
|
@ -11,27 +11,6 @@ from .models import Post
|
|||
|
||||
class BaseBlogView(TranslatableModelAdminMixin):
|
||||
|
||||
def _get_object(self, queryset=None):
|
||||
if not queryset:
|
||||
queryset = self.get_queryset()
|
||||
model = self.model
|
||||
try:
|
||||
obj = queryset.get(**self.filter_kwargs())
|
||||
except self.model.DoesNotExist:
|
||||
obj = None
|
||||
if obj:
|
||||
return obj
|
||||
queryset = self.model.objects.untranslated()
|
||||
try:
|
||||
obj = queryset.get(**self.filter_kwargs())
|
||||
except model.DoesNotExist:
|
||||
return None
|
||||
new_translation = model._meta.translations_model()
|
||||
new_translation.language_code = self._language(self.request)
|
||||
new_translation.master = obj
|
||||
setattr(obj, model._meta.translations_cache, new_translation)
|
||||
return obj
|
||||
|
||||
def get_queryset(self):
|
||||
language = self._language(self.request)
|
||||
manager = self.model._default_manager.language(language)
|
||||
|
@ -56,7 +35,7 @@ class PostDetailView(BaseBlogView, DetailView):
|
|||
template_name = "djangocms_blog/post_detail.html"
|
||||
|
||||
|
||||
class PostArchiveView(BaseBlogView, ArchiveIndexView):
|
||||
class PostArchiveView(BaseBlogView, ListView):
|
||||
model = Post
|
||||
context_object_name = 'post_list'
|
||||
template_name = "djangocms_blog/post_list.html"
|
||||
|
@ -67,9 +46,9 @@ class PostArchiveView(BaseBlogView, ArchiveIndexView):
|
|||
def get_queryset(self):
|
||||
qs = super(PostArchiveView, self).get_queryset()
|
||||
if 'month' in self.kwargs:
|
||||
qs = qs.filter(date_published__month=self.kwargs['month'])
|
||||
qs = qs.filter(**{"%s__month" % self.date_field: self.kwargs['month']})
|
||||
if 'year' in self.kwargs:
|
||||
qs = qs.filter(date_published__year=self.kwargs['year'])
|
||||
qs = qs.filter(**{"%s__year" % self.date_field: self.kwargs['year']})
|
||||
return qs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
|
Loading…
Reference in a new issue