def _to_python(self, value, state): from adhocracy.model import Badge badge = Badge.by_id(value) if not badge: raise formencode.Invalid( _("No Badge ID '%s' exists") % value, value, state) return badge
def _to_python(self, value, state): from adhocracy.model import Badge badge = Badge.by_id(value) if not badge: raise formencode.Invalid( _("No Badge ID '%s' exists") % value, value, state) return badge
def _get_badge_or_redirect(self, id): ''' Get a badge. Redirect if it does not exist. Redirect if the badge is not from the current instance, but the user is only an instance admin, not a global admin ''' badge = Badge.by_id(id, instance_filter=False) if badge is None: self._redirect_not_found(id) if badge.instance != c.instance and not has('global.admin'): self._redirect_not_found(id) return badge
def edit(self, id, errors=None): c.form_title = c.save_button = _("Edit Badge") c.action_url = self.base_url + '/edit/%s' % id c.groups = meta.Session.query(Group).order_by(Group.group_name).all() badge = Badge.by_id(id) if badge is None: self._redirect_not_found(id) group_default = badge.group and badge.group.code or '' defaults = dict(title=badge.title, description=badge.description, color=badge.color, group=group_default, display_group=badge.display_group, badge_delegateable=badge.badge_delegateable, ) return htmlfill.render(render("/badge/form.html"), errors=errors, defaults=defaults)
def edit(self, id, errors=None): c.form_title = c.save_button = _("Edit Badge") c.action_url = self.base_url + '/edit/%s' % id c.groups = meta.Session.query(Group).order_by(Group.group_name).all() badge = Badge.by_id(id) if badge is None: self._redirect_not_found(id) group_default = badge.group and badge.group.code or '' defaults = dict( title=badge.title, description=badge.description, color=badge.color, group=group_default, display_group=badge.display_group, badge_delegateable=badge.badge_delegateable, ) return htmlfill.render(render("/badge/form.html"), errors=errors, defaults=defaults)
def update(self, id): badge = Badge.by_id(id) if badge is None: self._redirect_not_found(id) title = self.form_result.get('title').strip() description = self.form_result.get('description').strip() color = self.form_result.get('color').strip() group = self.form_result.get('group') display_group = self.form_result.get('display_group') if group: badge.group = group else: badge.group = None badge.title = title badge.color = color badge.description = description badge.display_group = display_group meta.Session.commit() h.flash(_("Badge changed successfully"), 'success') redirect(self.base_url)
def update(self, id): badge = Badge.by_id(id) if badge is None: self._redirect_not_found(id) title = self.form_result.get('title').strip() description = self.form_result.get('description').strip() color = self.form_result.get('color').strip() group = self.form_result.get('group') display_group = self.form_result.get('display_group') if group: badge.group = group else: badge.group = None badge.title = title badge.color = color badge.description = description badge.display_group = display_group meta.Session.commit() h.flash(_("Badge changed successfully"), 'success') redirect(self.base_url)