Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions cmsplugin_randomquote/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
from django.utils.translation import ugettext_lazy as _
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from .models import Quote
from .models import Quote, RandomQuotePlugin


class QuotePlugin(CMSPluginBase):
"""This plugin randomly renders a quote from the database."""
name = _('Quote')
render_template = 'cmsplugin_randomquote/quote.html'
render_template = 'cmsplugin_randomquote/randomquotes.html'
model = RandomQuotePlugin

def render(self, context, instance, placeholder):
try:
t_obj = Quote.objects.order_by('?')[0]
context['quote'] = t_obj.quote_text
context['author'] = t_obj.author
context['author_url'] = t_obj.author_url
context['quotes'] = Quote.objects.order_by('?')[:instance.amount]
except IndexError:
pass

Expand Down
26 changes: 26 additions & 0 deletions cmsplugin_randomquote/migrations/0002_randomquoteplugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('cms', '0011_auto_20150419_1006'),
('cmsplugin_randomquote', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='RandomQuotePlugin',
fields=[
('cmsplugin_ptr', models.OneToOneField(primary_key=True, parent_link=True, to='cms.CMSPlugin', auto_created=True, serialize=False)),
('amount', models.IntegerField(default=1, help_text='The number of random quotes to be displayed.')),
],
options={
'abstract': False,
},
bases=('cms.cmsplugin',),
),
]
11 changes: 11 additions & 0 deletions cmsplugin_randomquote/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from cms.models.pluginmodel import CMSPlugin

@python_2_unicode_compatible
class Quote(models.Model):
Expand All @@ -11,3 +12,13 @@ class Quote(models.Model):

def __str__(self):
return '[%s] %s...' % (self.author, self.quote_text[:20])

@python_2_unicode_compatible
class RandomQuotePlugin(CMSPlugin):
amount = models.IntegerField(
default=1,
help_text=_('The number of random quotes to be displayed.')
)

def __str__(self):
return 'displaying %s' % (self.amount)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% for quote in quotes %}
<div class="quote">
<blockquote>{{ quote.quote_text }}</blockquote>
<p class="author">{% if quote.author %}&ndash;
{% if quote.author_url %}<a href="{{ quote.author_url }}">{{ quote.author }}</a>{% else %}{{ quote.author }}{% endif %}
{% endif %}</p>
</div>
{% endfor %}