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.
 
 
 
 
 
 

88 lines
2.7 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
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(page_link_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
# from django.utils.translation import ugettext_lazy as _
# from cms.models.pluginmodel import CMSPlugin
# from cms.plugin_base import CMSPluginBase
# from cms.plugin_pool import plugin_pool
# from .models import ContextServicePlugin
# from .forms import ContextServiceForm
# from .settings import get_setting
# class SevicePlugin(CMSPluginBase):
# module = 'Sevice'
# class SeviceContextPlugin(SevicePlugin):
# """
# Non cached plugin which returns the latest posts taking into account the
# user / toolbar state
# """
# render_template = 'sevice/plugins/context_services.html'
# name = _('Context Services')
# model = ContextServicePlugin
# form = ContextServiceForm
# filter_horizontal = ('categories',)
# cache = False
# def render(self, context, instance, placeholder):
# context = super(SeviceContextPlugin, self).render(context, instance, placeholder)
# context['services_list'] = instance.get_services(context['request'])
# if instance.categories.exists():
# context['category'] = instance.categories.all()[0].slug
# else:
# context['category'] = "all"
# return context
# class SeviceContextPluginCached(SevicePlugin):
# """
# Cached plugin which returns the latest published posts
# """
# render_template = 'sevice/plugins/context_services.html'
# name = _('Context Services')
# model = ContextServicePlugin
# form = ContextServiceForm
# filter_horizontal = ('categories',)
# def render(self, context, instance, placeholder):
# context = super(SeviceContextPluginCached, self).render(context, instance, placeholder)
# context['posts_list'] = instance.get_posts()
# return context
# plugin_pool.register_plugin(SeviceContextPlugin)