diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-05-27 17:58:09 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-05-27 18:52:23 +0100 |
commit | 5e4613a6ef78180f208b0cd58aeffb63f1e19853 (patch) | |
tree | c874ceae225b17159328abbf7194da040ab704e0 /app/models.py | |
parent | f4c9348b7f36b31980f7629478fdc8b2877801cc (diff) | |
download | cheatdb-5e4613a6ef78180f208b0cd58aeffb63f1e19853.tar.xz |
Add ability to edit provides
Diffstat (limited to 'app/models.py')
-rw-r--r-- | app/models.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/models.py b/app/models.py index d715994..ea8bb18 100644 --- a/app/models.py +++ b/app/models.py @@ -410,6 +410,39 @@ class MetaPackage(db.Model): def __str__(self): return self.name + @staticmethod + def ListToSpec(list): + return ",".join([str(x) for x in list]) + + @staticmethod + def SpecToList(spec, cache={}): + retval = [] + arr = spec.split(",") + + import re + pattern = re.compile("^([a-z0-9_]+)$") + + for x in arr: + x = x.strip() + if x == "": + continue + + if not pattern.match(x): + continue + + mp = cache.get(x) + if mp is None: + mp = MetaPackage.query.filter_by(name=x).first() + + if mp is None: + mp = MetaPackage(x) + db.session.add(mp) + + cache[x] = mp + retval.append(mp) + + return retval + class Tag(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), unique=True, nullable=False) |