Skip to content

Instantly share code, notes, and snippets.

@faebser
Created October 6, 2014 15:30
Show Gist options
  • Save faebser/fbf73d2509ce318b1d52 to your computer and use it in GitHub Desktop.
Save faebser/fbf73d2509ce318b1d52 to your computer and use it in GitHub Desktop.
class BlogListWithPaginationPlugin(CMSPluginBase):
model = BlogListWithPagination
module = ps.module
render_template = path.join(ps.templatePath, 'article_list.html')
name = _(u'Blog Liste')
def render(self, context, instance, placeholder):
context['instance'] = instance
context['placeholder'] = placeholder
parameter = context['request'].GET.get('pagination', None)
objects = None
if parameter is None:
objects = ArticleIntro.objects.all().exclude(isPublic=False).order_by('date')[:instance.amount]
else:
queryset = ArticleIntro.objects.all().exclude(isPublic=False).order_by('date')
for index, item in enumerate(queryset):
if item.pk == parameter:
# found item
objects = queryset[index+1:index+1+instance.amount]
break
context.update({
'articles': objects
})
return context
class ArticleIntro(CMSPlugin):
title = models.CharField(max_length=256, verbose_name=u'Titel')
author = models.ManyToManyField(User, verbose_name=u'Autor', limit_choices_to={'is_active': True, 'is_staff': True})
date = models.DateField(verbose_name=u'Datum', default=datetime.datetime.now())
lead = HTMLField(verbose_name=u'Lead')
tags = models.ManyToManyField(ArticleTags, verbose_name=u'Schlagworte')
picBig = models.ImageField(upload_to=CMSPlugin.get_media_path, verbose_name=u'unteres Bild', blank=True, null=True)
picTop = models.ImageField(upload_to=CMSPlugin.get_media_path, verbose_name=u'Bild oben, im Kasten', blank=True, null=True)
isPublic = models.BooleanField(editable=False, default=False)
class Meta:
verbose_name = u'Article'
def __unicode__(self):
return unicode(self.isPublic) + " " + unicode(self.date) + " " + Truncator(strip_tags(self.lead)).words(5, truncate='...')
def copy_relations(self, old_instance):
self.author = old_instance.author.all()
self.tags = old_instance.tags.all()
self.isPublic = True
self.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment