Add dependency support to Edit Requests

This commit is contained in:
rubenwardy 2018-05-25 17:41:16 +01:00
parent 9d91d337d5
commit 079775f5f6
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
3 changed files with 58 additions and 0 deletions

@ -40,3 +40,19 @@ Then run the server:
./rundebug.py
Then view in your web browser: http://localhost:5000/
## How-tos
### Create migration
```sh
# if sqlite
python setup.py -t
rm db.sqlite && python setup.py -t && FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db stamp head
# Create migration
FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db migrate
# Run migration
FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db migrate
```

@ -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)

@ -18,6 +18,8 @@
{{ render_field(form.type) }}
{{ render_field(form.license) }}
{{ render_multiselect_field(form.tags) }}
{{ render_multiselect_field(form.harddeps) }}
{{ render_multiselect_field(form.softdeps) }}
{{ render_field(form.repo) }}
{{ render_field(form.website) }}
{{ render_field(form.issueTracker) }}