# # -*- 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, Count from .models import Search class TrademarkSearchPluginPublisher(CMSPluginBase): # model = PollPluginModel # model where plugin data are saved module = _("Trademark") name = _("Search Form Plugin") # name of the plugin in the interface render_template = "trademark/form.html" cache = False def render(self, context, instance, placeholder): search = Search.objects.annotate(results_count=Count('results')) \ .filter(similarity=146, results_count__gt=0).order_by('?')[0] keyword = search.keyword.request context.update({ 'keyword_request': keyword, }) return context plugin_pool.register_plugin(TrademarkSearchPluginPublisher) # register the plugin