<s> from cms . plugin_pool import plugin_pool <EOL> from cms . plugin_base import CMSPluginBase <EOL> from django . template . loader import select_template <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from . import models <EOL> from . conf import settings <EOL> from filer . models . filemodels import File <EOL> from filer . models . foldermodels import Folder <EOL> from filer . models . imagemodels import Image <EOL> class FilerFolderPlugin ( CMSPluginBase ) : <EOL> module = '<STR_LIT>' <EOL> model = models . FilerFolder <EOL> name = _ ( "<STR_LIT>" ) <EOL> TEMPLATE_NAME = '<STR_LIT>' <EOL> render_template = TEMPLATE_NAME % '<STR_LIT:default>' <EOL> text_enabled = False <EOL> admin_preview = False <EOL> fieldsets = ( <EOL> ( None , { '<STR_LIT>' : [ '<STR_LIT:title>' , '<STR_LIT>' ] } ) , <EOL> ) <EOL> if settings . CMSPLUGIN_FILER_FOLDER_STYLE_CHOICES : <EOL> fieldsets [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] . append ( '<STR_LIT>' ) <EOL> def get_folder_files ( self , folder , user ) : <EOL> qs_files = folder . files . filter ( image__isnull = True ) <EOL> if user . is_staff : <EOL> return qs_files <EOL> else : <EOL> return qs_files . filter ( is_public = True ) <EOL> def get_folder_images ( self , folder , user ) : <EOL> qs_files = folder . files . instance_of ( Image ) <EOL> if user . is_staff : <EOL> return qs_files <EOL> else : <EOL> return qs_files . filter ( is_public = True ) <EOL> def get_children ( self , folder ) : <EOL> return folder . get_children ( ) <EOL> def render ( self , context , instance , placeholder ) : <EOL> self . render_template = select_template ( ( <EOL> '<STR_LIT>' , <EOL> self . TEMPLATE_NAME % instance . style , <EOL> self . TEMPLATE_NAME % '<STR_LIT:default>' ) <EOL> ) <EOL> user = context [ '<STR_LIT>' ] . user <EOL> if instance . folder_id : <EOL> folder_files = self . get_folder_files ( instance . folder , user ) <EOL> folder_images = self . get_folder_images ( instance . folder , user ) <EOL> folder_folders = self . get_children ( instance . folder ) <EOL> else : <EOL> folder_files = File . objects . none ( ) <EOL> folder_images = Image . objects . none ( ) <EOL> folder_folders = Folder . objects . none ( ) <EOL> context . update ( { <EOL> '<STR_LIT:object>' : instance , <EOL> '<STR_LIT>' : sorted ( folder_files ) , <EOL> '<STR_LIT>' : sorted ( folder_images ) , <EOL> '<STR_LIT>' : folder_folders , <EOL> '<STR_LIT>' : placeholder <EOL> } ) <EOL> return context <EOL> plugin_pool . register_plugin ( FilerFolderPlugin ) </s>
