def _delete(self, id): c.db_content = DbContent.find_by_id(id) meta.Session.delete(c.db_content) meta.Session.commit() h.flash("Content Deleted.") redirect_to('index')
def list_press(self): if c.db_content_types: page = request.GET.get('page', 1) pagination = paginate.Page(DbContent.find_all_by_type("In the press"), page = page, items_per_page = 10) c.db_content_pages = pagination c.db_content_collection = pagination.items c.result = True else: c.result = False return render('/db_content/list_press.mako')
def list_news(self): if c.db_content_types: page = request.GET.get('page', 1) pagination = paginate.Page(DbContent.find_all_by_type("News"), page=page, items_per_page=10) c.db_content_pages = pagination c.db_content_collection = pagination.items c.result = True else: c.result = False return render('/db_content/list_news.mako')
def list_news(self): if c.db_content_types: page = 1 if request.GET.has_key('page'): page = request.GET['page'] pagination = paginate.Page(DbContent.find_all_by_type("News"), page = page, items_per_page = 10) c.db_content_pages = pagination c.db_content_collection = pagination.items c.result = True else: c.result = False return render('/db_content/list_news.mako')
def edit(self, id): c.db_content = DbContent.find_by_id(id) defaults = h.object_to_defaults(c.db_content, 'db_content') # This is horrible, don't know a better way to do it if c.db_content.type: defaults['db_content.type'] = defaults['db_content.type_id'] defaults['db_content.publish_date'] = c.db_content.publish_timestamp.strftime('%d/%m/%y') defaults['db_content.publish_time'] = c.db_content.publish_timestamp.strftime('%H:%M:%S') form = render('/db_content/edit.mako') return htmlfill.render(form, defaults)
def view(self, id): c.db_content = DbContent.find_by_id(id) if c.db_content.publish_timestamp > datetime.now() and not h.auth.authorized(h.auth.has_organiser_role): c.db_content = None return NotFoundController().view() elif c.db_content.publish_timestamp > datetime.now(): h.flash(("This content is marked to be published on %s and will not be visiable to public until then." % c.db_content.publish_timestamp), 'Warning') if c.db_content.type.name == 'Redirect': redirect_to(c.db_content.body.encode("latin1"), _code=301) c.html_headers, c.html_body, c.menu_contents = self.parse_dbpage( c.db_content.body) return render('/db_content/view.mako')
def view(self, id): c.db_content = DbContent.find_by_id(id) if c.db_content.publish_timestamp > datetime.now( ) and not h.auth.authorized(h.auth.has_organiser_role): c.db_content = None return NotFoundController().view() elif c.db_content.publish_timestamp > datetime.now(): h.flash(( "This content is marked to be published on %s and will not be visiable to public until then." % c.db_content.publish_timestamp), 'Warning') if c.db_content.type.name == 'Redirect': redirect_to(c.db_content.body.encode("latin1"), _code=301) c.html_headers, c.html_body, c.menu_contents = self.parse_dbpage( c.db_content.body) return render('/db_content/view.mako')
def list_press(self): if c.db_content_types: page = 1 if request.GET.has_key('page'): page = request.GET['page'] pagination = paginate.Page( DbContent.find_all_by_type("In the press"), page=page, items_per_page=10) c.db_content_pages = pagination c.db_content_collection = pagination.items c.result = True else: c.result = False return render('/db_content/list_press.mako')
def edit(self, id): c.db_content = DbContent.find_by_id(id) defaults = h.object_to_defaults(c.db_content, 'db_content') # This is horrible, don't know a better way to do it if c.db_content.type: defaults['db_content.type'] = defaults['db_content.type_id'] defaults[ 'db_content.publish_date'] = c.db_content.publish_timestamp.strftime( '%d/%m/%y') defaults[ 'db_content.publish_time'] = c.db_content.publish_timestamp.strftime( '%H:%M:%S') form = render('/db_content/edit.mako') return htmlfill.render(form, defaults)
def _new(self): results = self.form_result['db_content'] if results['publish_time'] is None: results['publish_time'] = datetime.time(datetime.now()) if results['publish_date'] is not None: results['publish_timestamp'] = datetime.combine( results['publish_date'], results['publish_time']) else: results['publish_timestamp'] = None del results['publish_date'] del results['publish_time'] c.db_content = DbContent(**results) meta.Session.add(c.db_content) meta.Session.commit() h.flash("New Page Created.") redirect_to(action='view', id=c.db_content.id)
def _edit(self, id): c.db_content = DbContent.find_by_id(id) for key in self.form_result['db_content']: if ( not key in ['publish_date', 'publish_time'] ): setattr(c.db_content, key, self.form_result['db_content'][key]) if self.form_result['db_content']['publish_time'] is None: self.form_result['db_content']['publish_time'] = datetime.time(datetime.now()) if self.form_result['db_content']['publish_date'] is not None: c.db_content.publish_timestamp = \ datetime.combine(self.form_result['db_content']['publish_date'], \ self.form_result['db_content']['publish_time']) else: c.db_content.publish_timestamp = datetime.now() # update the objects with the validated form data meta.Session.commit() h.flash("Page updated.") redirect_to(action='view', id=id)
def _edit(self, id): c.db_content = DbContent.find_by_id(id) for key in self.form_result['db_content']: if (not key in ['publish_date', 'publish_time']): setattr(c.db_content, key, self.form_result['db_content'][key]) if self.form_result['db_content']['publish_time'] is None: self.form_result['db_content']['publish_time'] = datetime.time( datetime.now()) if self.form_result['db_content']['publish_date'] is not None: c.db_content.publish_timestamp = \ datetime.combine(self.form_result['db_content']['publish_date'], \ self.form_result['db_content']['publish_time']) else: c.db_content.publish_timestamp = datetime.now() # update the objects with the validated form data meta.Session.commit() h.flash("Page updated.") redirect_to(action='view', id=id)
def new(self): if len(c.db_content_types) is 0: h.flash( "Configuration Error: Please make sure at least one content type exists.", 'error') if DbContentType.find_by_name("News", abort_404=False) is None: h.flash( "Configuration Error: Please make sure the 'News' content type exists for full functionality.", 'error') if DbContentType.find_by_name("In the press", abort_404=False) is None: h.flash( "Configuration Error: Please make sure the 'In the press' content type exists for full functionality.", 'error') c.db_content = DbContent() defaults = h.object_to_defaults(c.db_content, 'db_content') if request.GET.has_key('url'): defaults['db_content.type'] = find_by_name('Page', abort_404=False) if request.GET['url'].startswith('/'): defaults['db_content.url'] = str(request.GET['url'])[1:] else: defaults['db_content.url'] = request.GET['url'] form = render('/db_content/new.mako') return htmlfill.render(form, defaults)
def index(self): c.db_content_collection = DbContent.find_all() return render('/db_content/list.mako')
def page(self): url = h.url_for().strip("/") c.db_content = DbContent.find_by_url(url, abort_404=False) if c.db_content is not None: return self.view(c.db_content.id) return NotFoundController().view()
def delete(self, id): c.db_content = DbContent.find_by_id(id) return render('/db_content/confirm_delete.mako')