Changeset 587 for pagoda

Show
Ignore:
Timestamp:
11/02/07 19:23:36 (1 year ago)
Author:
ian
Message:

redoing templates, haven't even checked in the client-side code yet so here goes. this is just for historical purposes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pagoda/trunk/Pagoda/pagoda/controllers/admin.py

    r555 r587  
     1import os 
    12from urlparse import urljoin 
     3from itertools import groupby 
     4from operator import attrgetter 
     5import pkg_resources 
     6from sqlalchemy.util import OrderedDict 
    27import cherrypy 
    38from cherrypy import request, response, session 
     
    914from pagoda.controllers.util import * 
    1015from pagoda import config, models, widgets, plugins, validators, workflow 
     16from pagoda.view.engines import get_engine 
    1117 
    1218__all__ = ['EditController', 'LiveController', 'AdminContentController', 
     
    268274 
    269275 
     276class TemplatesController(Controller, identity.SecureResource): 
     277    #require = identity.has_permission('pagoda_admin') 
     278    #@expose(format='json') 
     279    #def default(self, template_id, *args, **kwargs): 
     280        #template = models.Template.get(template_id) 
     281        #package = ".".join(template.template_path.split(".")[:-1]) 
     282        #name = template.template_path.split(".")[:-1] 
     283        #pkg_resources.get_ 
     284 
     285    #require = identity.has_permission('pagoda_admin') 
     286    #@expose(format='json') 
     287    #def create(self, *args, **kwargs): 
     288    #    """Creates a new template using specified `template_engine`.""" 
     289    #    template_engine = kwargs.get('template_engine', None) 
     290    #    engine = get_engine(template_engine) 
     291    #    t = Template( 
     292    #        template_name="Untitled", 
     293    #        template_path=???, 
     294    #        template_engine=template_engine, 
     295    #        content_type=??? 
     296    #    ) 
     297 
     298    require = identity.has_permission('pagoda_admin') 
     299    @expose(format='json') 
     300    def get(self, *args, **kwargs): 
     301        """Return the unrendered template specified by `template_id` kwarg.""" 
     302        template_id = kwargs.get('template_id', None) 
     303        template = models.Template.get(template_id) 
     304        f = open(template.filepath) 
     305        return dict(template_data = f.read()) 
     306 
     307    require = identity.has_permission('pagoda_admin') 
     308    @expose(format='json') 
     309    def save(self, *args, **kwargs): 
     310        """Save the specified template. 
     311         
     312        Looks up the template specified by the `template_id` kwarg, opens 
     313        that file, and overwrites the file with the new template given 
     314        by the `template_data` kwarg. 
     315         
     316        """ 
     317        template_id = kwargs.get('template_id', None) 
     318        template_data = kwargs.get('template_data', None) 
     319        template = models.Template.get(template_id) 
     320        f = open(template.filepath, 'w') 
     321        f.write(template_data) 
     322        f.close() 
     323        return dict() 
     324 
     325    require = identity.has_permission('pagoda_admin') 
     326    @expose(template="genshi:pagoda.templates.admin.templates", format="html") 
     327    def index(self, *args, **kwargs): 
     328        # Get all templates and compute filename for each. 
     329        templates = models.Template.select() 
     330        for template in templates: 
     331            template.template_filename = os.path.basename(template.filepath) 
     332         
     333        # Construct a SelectField containing all known content types 
     334        from toscawidgets.widgets.forms import SingleSelectField, validators 
     335        content_types = [] 
     336        entry_point_id = 'pagoda.content_types.models' 
     337        for entry_point in pkg_resources.iter_entry_points(entry_point_id): 
     338            content_types.append(entry_point.name) 
     339        content_types_field = SingleSelectField( 
     340            label=None, 
     341            options=zip(content_types, content_types) 
     342        ) 
     343 
     344        # Group templates by content_type. 
     345        grouped_templates = OrderedDict() 
     346        for k, group in groupby(templates, attrgetter('content_type')): 
     347            grouped_templates[k] = list(group) 
     348        return dict( 
     349            grouped_templates=grouped_templates, 
     350            content_types_field=content_types_field 
     351        ) 
     352 
    270353class PagodaAdminController(RootController): 
    271354    edit = EditController() 
     
    277360    plugins = PluginsController() 
    278361    settings = SettingsController() 
     362    templates = TemplatesController() 
    279363 
    280364    @expose(template="genshi:pagoda.templates.admin.control_panel", format="html") 
  • pagoda/trunk/Pagoda/pagoda/models/template.py

    r555 r587  
    55from sqlalchemy.ext.assignmapper import assign_mapper 
    66from turbogears.database import metadata, session 
     7from pagoda.view.engines import get_engine 
    78 
    89__all__ = ['template_table', 'Template'] 
     
    1011template_table = Table('template', metadata, 
    1112    Column('template_id', Integer, primary_key=True), 
    12     Column('template_name', Unicode(75), nullable=True), 
     13    Column('template_name', Unicode(75), nullable=False), 
    1314    Column('template_path', Unicode, nullable=True), 
    14     Column('template_code', Unicode, nullable=True) 
     15    Column('template_engine', Unicode(75), nullable=True),  
     16    Column('content_type', Unicode(75), nullable=False) 
    1517) 
    1618 
    1719class Template(object): 
    18     pass 
     20    """ 
     21    Represents a template that content managers can use 
     22    to display content. 
     23 
     24    """ 
     25    def __repr__(self): 
     26        cls = self.__class__ 
     27        cols = cls.c.keys() 
     28        return "%s(%s)" % ( 
     29            cls.__name__, 
     30            ", ".join(["%s=%r" % (col, getattr(self, col)) for col in cols]) 
     31        ) 
     32 
     33    @property 
     34    def filepath(self): 
     35        template_uri = "%s:%s" % (self.template_engine, self.template_path) 
     36        engine = get_engine(template_uri) 
     37        return engine.filepath(template_uri) 
     38 
     39 
    1940 
    2041assign_mapper(session.context, Template, template_table) 
  • pagoda/trunk/Pagoda/pagoda/view/engines.py

    r582 r587  
    88 
    99engines = dict() 
    10  
    11 class MetaDeprecatedVariableProviders(type): 
    12     def __new__(cls, name, bases, dict): 
    13         for (key, value) in dict.items(): 
    14             if key == "__metaclass__": 
    15                 continue 
    16             if callable(value): 
    17                 dict[key] = print_warning(value) 
    18         return type.__new__(cls, name, bases, dict) 
    1910 
    2011def split_template_path(template_uri): 
     
    4132    return engine 
    4233 
    43  
    4434class PagodaTemplatePlugin(object): 
    4535    @property 
     
    4838        raise NotImplemented 
    4939 
    50     def filepath(self, template): 
    51         """Return actual filename for the template path given by `template`.""" 
    52         pieces = template.split(".") 
     40    def filepath(self, template_uri): 
     41        """Return actual filename for the template located at `template_uri`.""" 
     42        engine_name, template_path = split_template_path(template_uri) 
     43        pieces = template_path.split(".") 
    5344        package = ".".join(pieces[:-1]) 
    54         for extension in self.extensions 
     45        for extension in self.extensions: 
    5546            filename = pkg_resources.resource_filename( 
    5647                package, "%s.%s" % (pieces[-1], extension) 
     
    6152         
    6253    def safe_xml(self, data): 
    63         """Returns `data`, modified so the template engine won't escape xml.""" 
     54        """Return `data`, modified so the template engine won't escape xml.""" 
    6455        raise NotImplemented 
    65  
     56     
     57    def get_default_template(self): 
     58        """Return a basic get-yourself-started template as a string""" 
     59        raise NotImplemented 
    6660 
    6761class GenshiPlugin(PagodaTemplatePlugin): 
     
    7872    def safe_xml(self, data): 
    7973        return self.genshi.Markup(data) 
     74     
     75    def get_default_template(self): 
     76        path = pkg_resources.resource_filename( 
     77            'pagoda.view.templates', 'genshi.html' 
     78        ) 
     79        f = open(path) 
     80        return f.read() 
    8081 
    8182 
     
    9495        return self.kid.XML(data) 
    9596 
     97    def get_default_template(self): 
     98        path = pkg_resources.resource_filename( 
     99            'pagoda.view.templates', 'kid.kid' 
     100        ) 
     101        f = open(path) 
     102        return f.read() 
     103 
    96104ENGINE_MAP = { 
    97105    'genshi': GenshiPlugin, 
  • pagoda/trunk/Pagoda/setup.py

    r572 r587  
    3636        "TurboGears >= 1.0.3, < 1.0.4", 
    3737        "Genshi >= 0.4", 
    38         "ToscaWidgets == 0.1a2dev-r2937", 
     38        # Newer ToscaWidgets breaks ability to have multiple RootControllers. 
     39        # Waiting on fix for ticket 1403: http://trac.turbogears.org/ticket/1403 
     40        "ToscaWidgets == 0.1a2dev-r2937",  
     41        # Newer twForms depend on newer ToscaWidgets (see above!) 
     42        "twForms == 0.1a2dev_r2931", 
    3943        "SQLAlchemy >= 0.3.8, <= 0.3.10", 
    4044        "dateutil" 

Log in as guest/pagoda to create tickets