From 743d1d909fbfb704185475c162f6ae2396272c75 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 26 Mar 2018 15:17:39 +0100 Subject: [PATCH] Add ability to suggest tag changes using edit requests Fixes #36 --- app/models.py | 15 ++++++++++++++- app/templates/packages/editrequest_create.html | 1 + app/views/packages.py | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/models.py b/app/models.py index 0c9b2f27..444d606b 100644 --- a/app/models.py +++ b/app/models.py @@ -142,11 +142,18 @@ class PackagePropertyKey(enum.Enum): shortDesc = "Short Description" desc = "Description" type = "Type" + tags = "Tags" repo = "Repository" website = "Website" issueTracker = "Issue Tracker" forums = "Forum Topic ID" + def convert(self, value): + if self == PackagePropertyKey.tags: + return ','.join([t.title for t in value]) + else: + return str(value) + tags = db.Table('tags', db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True), db.Column('package_id', db.Integer, db.ForeignKey('package.id'), primary_key=True) @@ -370,7 +377,13 @@ class EditRequestChange(db.Model): newValue = db.Column(db.Text, nullable=True) def apply(self, package): - setattr(package, self.key.name, self.newValue) + if self.key == PackagePropertyKey.tags: + package.tags.clear() + for tagTitle in self.newValue.split(","): + tag = Tag.query.filter_by(title=tagTitle.strip()).first() + package.tags.append(tag) + else: + setattr(package, self.key.name, self.newValue) # Setup Flask-User db_adapter = SQLAlchemyAdapter(db, User) # Register the User model diff --git a/app/templates/packages/editrequest_create.html b/app/templates/packages/editrequest_create.html index d0c592a3..cdf5cfad 100644 --- a/app/templates/packages/editrequest_create.html +++ b/app/templates/packages/editrequest_create.html @@ -14,6 +14,7 @@ {{ render_field(form.shortDesc) }} {{ render_field(form.desc) }} {{ render_field(form.type) }} + {{ render_field(form.tags) }} {{ render_field(form.repo) }} {{ render_field(form.website) }} {{ render_field(form.issueTracker) }} diff --git a/app/views/packages.py b/app/views/packages.py index d9f07172..e532d3f1 100644 --- a/app/views/packages.py +++ b/app/views/packages.py @@ -265,8 +265,8 @@ def create_editrequest_page(ptype, author, name): change = EditRequestChange() change.request = erequest change.key = e - change.oldValue = str(oldValue) - change.newValue = str(newValue) + change.oldValue = e.convert(oldValue) + change.newValue = e.convert(newValue) db.session.add(change) wasChangeMade = True