<s> from django import forms <EOL> from django . db import models <EOL> from django . template import RequestContext <EOL> from django . template . loader import render_to_string <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from portlets . models import Portlet <EOL> from lfs . catalog . models import Category <EOL> from lfs . marketing . models import FeaturedProduct <EOL> class FeaturedPortlet ( Portlet ) : <EOL> """<STR_LIT>""" <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> name = _ ( "<STR_LIT>" ) <EOL> limit = models . IntegerField ( _ ( u"<STR_LIT>" ) , default = <NUM_LIT:5> ) <EOL> current_category = models . BooleanField ( _ ( u"<STR_LIT>" ) , default = False ) <EOL> slideshow = models . BooleanField ( _ ( u"<STR_LIT>" ) , default = False ) <EOL> @ property <EOL> def rendered_title ( self ) : <EOL> return self . title or self . name <EOL> def render ( self , context ) : <EOL> """<STR_LIT>""" <EOL> request = context . get ( "<STR_LIT>" ) <EOL> if self . current_category : <EOL> obj = context . get ( "<STR_LIT>" ) or context . get ( "<STR_LIT>" ) <EOL> if obj : <EOL> category = obj if isinstance ( obj , Category ) else obj . get_current_category ( request ) <EOL> categories = [ category ] <EOL> categories . extend ( category . get_all_children ( ) ) <EOL> filters = { "<STR_LIT>" : categories } <EOL> products = [ x . product for x in FeaturedProduct . objects . filter ( ** filters ) [ : self . limit ] ] <EOL> else : <EOL> products = None <EOL> else : <EOL> products = [ x . product for x in FeaturedProduct . objects . all ( ) [ : self . limit ] ] <EOL> return render_to_string ( "<STR_LIT>" , RequestContext ( request , { <EOL> "<STR_LIT:title>" : self . rendered_title , <EOL> "<STR_LIT>" : self . slideshow , <EOL> "<STR_LIT>" : products , <EOL> "<STR_LIT>" : context . get ( "<STR_LIT>" ) , <EOL> } ) ) <EOL> def form ( self , ** kwargs ) : <EOL> """<STR_LIT:U+0020>""" <EOL> return FeaturedForm ( instance = self , ** kwargs ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT:%s>" % self . id <EOL> class FeaturedForm ( forms . ModelForm ) : <EOL> """<STR_LIT:U+0020>""" <EOL> class Meta : <EOL> model = FeaturedPortlet <EOL> exclude = ( ) </s>
