Add ability to suggest tag changes using edit requests

Fixes #36
This commit is contained in:
rubenwardy 2018-03-26 15:17:39 +01:00
parent 28d967e3e2
commit 743d1d909f
3 changed files with 17 additions and 3 deletions

@ -142,11 +142,18 @@ class PackagePropertyKey(enum.Enum):
shortDesc = "Short Description" shortDesc = "Short Description"
desc = "Description" desc = "Description"
type = "Type" type = "Type"
tags = "Tags"
repo = "Repository" repo = "Repository"
website = "Website" website = "Website"
issueTracker = "Issue Tracker" issueTracker = "Issue Tracker"
forums = "Forum Topic ID" 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', tags = db.Table('tags',
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True), 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) 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) newValue = db.Column(db.Text, nullable=True)
def apply(self, package): 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 # Setup Flask-User
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model db_adapter = SQLAlchemyAdapter(db, User) # Register the User model

@ -14,6 +14,7 @@
{{ render_field(form.shortDesc) }} {{ render_field(form.shortDesc) }}
{{ render_field(form.desc) }} {{ render_field(form.desc) }}
{{ render_field(form.type) }} {{ render_field(form.type) }}
{{ render_field(form.tags) }}
{{ render_field(form.repo) }} {{ render_field(form.repo) }}
{{ render_field(form.website) }} {{ render_field(form.website) }}
{{ render_field(form.issueTracker) }} {{ render_field(form.issueTracker) }}

@ -265,8 +265,8 @@ def create_editrequest_page(ptype, author, name):
change = EditRequestChange() change = EditRequestChange()
change.request = erequest change.request = erequest
change.key = e change.key = e
change.oldValue = str(oldValue) change.oldValue = e.convert(oldValue)
change.newValue = str(newValue) change.newValue = e.convert(newValue)
db.session.add(change) db.session.add(change)
wasChangeMade = True wasChangeMade = True