Beispiel #1
0
    def by_name(self, input, *args, **kw):
        if 'anywhere' in kw:
            search = ConfigItem.list_by_name(input, find_anywhere=True)
        else:
            search = ConfigItem.list_by_name(input)

        keys = [elem.name for elem in search]
        return dict(matches=keys)
Beispiel #2
0
    def edit(self,**kw):
        if kw.get('id'):
            item = ConfigItem.by_id(kw['id'])
            form_values = dict(
                id         = item.id,
                numeric    = item.numeric,
                value      = item.current_value()
            )
        else:
            flash(_(u"Error: No item ID specified"))
            raise redirect(".")

        # Show all future values, and the previous five
        config_values = item.values().filter(item.value_class.valid_from > datetime.utcnow()).order_by(item.value_class.valid_from.desc()).all() \
                      + item.values().filter(item.value_class.valid_from <= datetime.utcnow()).order_by(item.value_class.valid_from.desc())[:5]

        if item.readonly:
            form = None
        elif item.numeric:
            form = self.int_form
        else:
            form = self.string_form

        return dict(
            title = item.description,
            form = form,
            action = './save',
            options = {},
            value = form_values,
            list = config_values,
            grid = self.value_grid,
            warn_msg = item.readonly and "This item is read-only",
        )
Beispiel #3
0
 def remove(self, **kw):
     item = ConfigItem.by_id(kw['id'])
     item.set(None, None, identity.current.user)
     session.add(item)
     session.flush()
     flash(_(u"%s cleared") % item.description)
     raise redirect(".")
Beispiel #4
0
 def delete(self, **kw):
     item = ConfigItem.by_id(kw['item'])
     val = item.value_class.by_id(kw['id'])
     if val.valid_from <= datetime.utcnow():
         flash(_(u"Cannot remove past value of %s") % item.name)
         raise redirect("/configuration/edit?id=%d" % item.id)
     session.delete(val)
     session.flush()
     flash(_(u"Future value of %s cleared") % item.name)
     raise redirect(".")
Beispiel #5
0
    def save(self, **kw):
        if 'id' in kw and kw['id']:
            item = ConfigItem.by_id(kw['id'])
        else:
            flash(_(u"Error: No item ID"))
            raise redirect(".")
        if kw['valid_from']:
            try:
                valid_from = datetime.strptime(kw['valid_from'], '%Y-%m-%d %H:%M')
            except ValueError:
                flash(_(u"Invalid date and time specification, use: YYYY-MM-DD HH:MM"))
                raise redirect("/configuration/edit?id=%d" % item.id)
        else:
            valid_from = None

        try:
            item.set(kw['value'], valid_from, identity.current.user)
        except Exception, msg:
            flash(_(u"Failed to save setting: %s" % msg))
            raise redirect("/configuration/edit?id=%d" % item.id)