diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-05-25 17:41:16 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-05-25 17:41:16 +0100 |
commit | 079775f5f6599163f3b40a4bc9ddb7669ba91ef7 (patch) | |
tree | 88553d425c52c6029c7f8bca7c1c0023609c5197 /app/models.py | |
parent | 9d91d337d5fc099195a756d331c27bc0780f5ce7 (diff) | |
download | cheatdb-079775f5f6599163f3b40a4bc9ddb7669ba91ef7.tar.xz |
Add dependency support to Edit Requests
Diffstat (limited to 'app/models.py')
-rw-r--r-- | app/models.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/app/models.py b/app/models.py index cafdf5d..c0c9a09 100644 --- a/app/models.py +++ b/app/models.py @@ -225,6 +225,9 @@ class PackagePropertyKey(enum.Enum): def convert(self, value): if self == PackagePropertyKey.tags: return ",".join([t.title for t in value]) + elif self == PackagePropertyKey.harddeps or self == PackagePropertyKey.softdeps: + return ",".join([t.author.username + "/" + t.name for t in value]) + else: return str(value) @@ -531,6 +534,43 @@ class EditRequestChange(db.Model): for tagTitle in self.newValue.split(","): tag = Tag.query.filter_by(title=tagTitle.strip()).first() package.tags.append(tag) + + elif self.key == PackagePropertyKey.harddeps: + package.harddeps.clear() + for pair in self.newValue.split(","): + key, value = pair.split("/") + if key is None or value is None: + continue + + user = User.query.filter_by(username=key).first() + if user is None: + continue + + dep = Package.query.filter_by(author=user, name=value).first() + if dep is None: + continue + + package.harddeps.append(dep) + + elif self.key == PackagePropertyKey.softdeps: + package.softdeps.clear() + for pair in self.newValue.split(","): + key, value = pair.split("/") + if key is None or value is None: + continue + + user = User.query.filter_by(username=key).first() + if user is None: + raise Exception("No such user!") + continue + + dep = Package.query.filter_by(author=user, name=value).first() + if dep is None: + raise Exception("No such package!") + continue + + package.softdeps.append(dep) + else: setattr(package, self.key.name, self.newValue) |