- Timestamp:
- 11/02/07 19:23:36 (1 year ago)
- Files:
-
- pagoda/trunk/Pagoda/pagoda/controllers/admin.py (modified) (4 diffs)
- pagoda/trunk/Pagoda/pagoda/models/template.py (modified) (2 diffs)
- pagoda/trunk/Pagoda/pagoda/templates/admin/templates.html (added)
- pagoda/trunk/Pagoda/pagoda/view/engines.py (modified) (6 diffs)
- pagoda/trunk/Pagoda/pagoda/widgets/admin/static/css/templates.css (added)
- pagoda/trunk/Pagoda/pagoda/widgets/admin/static/javascript/templates.js (added)
- pagoda/trunk/Pagoda/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pagoda/trunk/Pagoda/pagoda/controllers/admin.py
r555 r587 1 import os 1 2 from urlparse import urljoin 3 from itertools import groupby 4 from operator import attrgetter 5 import pkg_resources 6 from sqlalchemy.util import OrderedDict 2 7 import cherrypy 3 8 from cherrypy import request, response, session … … 9 14 from pagoda.controllers.util import * 10 15 from pagoda import config, models, widgets, plugins, validators, workflow 16 from pagoda.view.engines import get_engine 11 17 12 18 __all__ = ['EditController', 'LiveController', 'AdminContentController', … … 268 274 269 275 276 class 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 270 353 class PagodaAdminController(RootController): 271 354 edit = EditController() … … 277 360 plugins = PluginsController() 278 361 settings = SettingsController() 362 templates = TemplatesController() 279 363 280 364 @expose(template="genshi:pagoda.templates.admin.control_panel", format="html") pagoda/trunk/Pagoda/pagoda/models/template.py
r555 r587 5 5 from sqlalchemy.ext.assignmapper import assign_mapper 6 6 from turbogears.database import metadata, session 7 from pagoda.view.engines import get_engine 7 8 8 9 __all__ = ['template_table', 'Template'] … … 10 11 template_table = Table('template', metadata, 11 12 Column('template_id', Integer, primary_key=True), 12 Column('template_name', Unicode(75), nullable= True),13 Column('template_name', Unicode(75), nullable=False), 13 14 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) 15 17 ) 16 18 17 19 class 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 19 40 20 41 assign_mapper(session.context, Template, template_table) pagoda/trunk/Pagoda/pagoda/view/engines.py
r582 r587 8 8 9 9 engines = 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 continue16 if callable(value):17 dict[key] = print_warning(value)18 return type.__new__(cls, name, bases, dict)19 10 20 11 def split_template_path(template_uri): … … 41 32 return engine 42 33 43 44 34 class PagodaTemplatePlugin(object): 45 35 @property … … 48 38 raise NotImplemented 49 39 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(".") 53 44 package = ".".join(pieces[:-1]) 54 for extension in self.extensions 45 for extension in self.extensions: 55 46 filename = pkg_resources.resource_filename( 56 47 package, "%s.%s" % (pieces[-1], extension) … … 61 52 62 53 def safe_xml(self, data): 63 """Return s`data`, modified so the template engine won't escape xml."""54 """Return `data`, modified so the template engine won't escape xml.""" 64 55 raise NotImplemented 65 56 57 def get_default_template(self): 58 """Return a basic get-yourself-started template as a string""" 59 raise NotImplemented 66 60 67 61 class GenshiPlugin(PagodaTemplatePlugin): … … 78 72 def safe_xml(self, data): 79 73 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() 80 81 81 82 … … 94 95 return self.kid.XML(data) 95 96 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 96 104 ENGINE_MAP = { 97 105 'genshi': GenshiPlugin, pagoda/trunk/Pagoda/setup.py
r572 r587 36 36 "TurboGears >= 1.0.3, < 1.0.4", 37 37 "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", 39 43 "SQLAlchemy >= 0.3.8, <= 0.3.10", 40 44 "dateutil"
