diff --git a/app/models.py b/app/models.py index 531737da..c3864289 100644 --- a/app/models.py +++ b/app/models.py @@ -118,7 +118,7 @@ class Package(db.Model): author=self.author.username, name=self.name) def getEditURL(self): - return url_for("edit_package_page", + return url_for("create_edit_package_page", type=self.type.toName(), author=self.author.username, name=self.name) diff --git a/app/templates/package_edit.html b/app/templates/package_create_edit.html similarity index 93% rename from app/templates/package_edit.html rename to app/templates/package_create_edit.html index f7e34b11..26b4c445 100644 --- a/app/templates/package_edit.html +++ b/app/templates/package_create_edit.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block title %} - {{ package.title }} + {{ package.title or "Create Package" }} {% endblock %} {% block content %} diff --git a/app/views/packages.py b/app/views/packages.py index a6b68942..33013eac 100644 --- a/app/views/packages.py +++ b/app/views/packages.py @@ -62,29 +62,41 @@ class PackageForm(FlaskForm): title = StringField("Title") shortDesc = StringField("Short Description") desc = StringField("Long Description") - type = SelectField("Type", choices=PackageType.choices(), coerce=PackageType.coerce) + type = SelectField("Type", choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD) repo = StringField("Repo URL") website = StringField("Website URL") issueTracker = StringField("Issue Tracker URL") forums = StringField("Forum Topic ID") submit = SubmitField('Save') +@menu.register_menu(app, '.new', 'Create', order=20) +@app.route("/new/", methods=['GET', 'POST']) @app.route("/s///edit/", methods=['GET', 'POST']) @login_required -def edit_package_page(type, author, name): - package = getPageByInfo(type, author, name) - if not package.checkPerm(current_user, Permission.EDIT_PACKAGE): - return redirect(package.getDetailsURL()) +def create_edit_package_page(type=None, author=None, name=None): + package = None + form = None + if type is None: + form = PackageForm(formdata=request.form) + else: + package = getPageByInfo(type, author, name) + if not package.checkPerm(current_user, Permission.EDIT_PACKAGE): + return redirect(package.getDetailsURL()) + + form = PackageForm(formdata=request.form, obj=package) # Initial form class from post data and default data - form = PackageForm(formdata=request.form, obj=package) if request.method == "POST" and form.validate(): # Successfully submitted! + if not package: + package = Package() + package.author = current_user + form.populate_obj(package) # copy to row db.session.commit() # save return redirect(package.getDetailsURL()) # redirect - return render_template('package_edit.html', package=package, form=form) + return render_template('package_create_edit.html', package=package, form=form) class CreatePackageReleaseForm(FlaskForm):