Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Add utilities for altering arguments to a rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Mar 20, 2015
1 parent 7477563 commit d9e5960
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions fmn/lib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ def create_from_code_path(cls, session, valid_paths, code_path,
session.commit()
return rule

def set_argument(self, session, key, value):
args = self.arguments
args[key] = value
self.arguments = args
session.flush()
session.commit()
self.notify(
self.filter.preference.openid,
self.filter.preference.context.name,
"filters")

def title(self, valid_paths):
root, name = self.code_path.split(':', 1)
return valid_paths[root][name]['title']
Expand Down Expand Up @@ -355,6 +366,18 @@ def fired(self, session):
if pref:
self.notify(pref.openid, pref.context_name, "filters")

def get_rule(self, session, code_path, **kw):
for r in self.rules:
if r.code_path == code_path:
return r
raise ValueError("No such rule found: %r" % code_path)

def has_rule(self, session, code_path, **kw):
for r in self.rules:
if r.code_path == code_path:
return True
return False

def add_rule(self, session, paths, rule, **kw):
if isinstance(rule, basestring):
rule = Rule.create_from_code_path(session, paths, rule, **kw)
Expand Down

0 comments on commit d9e5960

Please sign in to comment.