You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
31 lines
1.0 KiB
# # -*- coding: utf-8 -*-
|
|
|
|
from cms.plugin_base import CMSPluginBase
|
|
from cms.plugin_pool import plugin_pool
|
|
from django.utils.translation import ugettext as _
|
|
from .models import Promo
|
|
from django.db.models import Q
|
|
|
|
class PromoPluginPublisher(CMSPluginBase):
|
|
# model = PollPluginModel # model where plugin data are saved
|
|
module = _("Promos")
|
|
name = _("Promo Plugin") # name of the plugin in the interface
|
|
render_template = "promo/index.html"
|
|
|
|
def render(self, context, instance, placeholder):
|
|
request = context['request']
|
|
|
|
history = request.session['history']
|
|
|
|
promos = Promo.objects.filter(Q(page_link_id__in=history) | Q(page_link__publisher_public_id__in=history)).order_by('?')
|
|
|
|
if promos.exists():
|
|
promo = promos[0]
|
|
promo.text = promo.text.replace('#promo', promo.page_link.get_absolute_url())
|
|
context.update({
|
|
'instance': promo,
|
|
|
|
})
|
|
return context
|
|
|
|
plugin_pool.register_plugin(PromoPluginPublisher) # register the plugin
|
|
|