[copr] master: Allow building again, refactor it to simple views (2fb40dd)

bkabrda at fedoraproject.org bkabrda at fedoraproject.org
Mon Jan 21 11:12:58 UTC 2013


Repository : http://git.fedorahosted.org/cgit/copr.git

On branch  : master

>---------------------------------------------------------------

commit 2fb40ddd66bd54f44a5a3bb8b975a8dd21ec28bb
Author: Bohuslav Kabrda <bkabrda at redhat.com>
Date:   Mon Jan 21 09:04:59 2013 +0100

    Allow building again, refactor it to simple views


>---------------------------------------------------------------

 coprs_frontend/coprs/templates/coprs/detail.html   |    5 +++++
 .../coprs/templates/coprs/detail/_build_forms.html |    8 +++++---
 .../coprs/views/coprs_ns/coprs_builds.py           |   20 ++++++++++++++++----
 .../coprs/views/coprs_ns/coprs_general.py          |    2 +-
 4 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/coprs_frontend/coprs/templates/coprs/detail.html b/coprs_frontend/coprs/templates/coprs/detail.html
index e12e5f1..b851500 100644
--- a/coprs_frontend/coprs/templates/coprs/detail.html
+++ b/coprs_frontend/coprs/templates/coprs/detail.html
@@ -17,6 +17,11 @@
     <div class="unselected">
       <a href="{{ url_for('coprs_ns.copr_builds', username = copr.owner.name, coprname = copr.name) }}">Builds</a>
     </div>
+    {% if g.user and g.user.can_build_in(copr) %}
+      <div class="unselected">
+        <a href="{{ url_for('coprs_ns.copr_add_build', username = copr.owner.name, coprname = copr.name) }}">New Build</a>
+      </div>
+    {% endif %}
     {% if g.user and g.user.can_edit(copr) %}
       <div class="unselected">
         <a href="{{ url_for('coprs_ns.copr_edit', username = copr.owner.name, coprname = copr.name) }}">Edit</a>
diff --git a/coprs_frontend/coprs/templates/coprs/detail/_build_forms.html b/coprs_frontend/coprs/templates/coprs/detail/_build_forms.html
index a5d6c4e..f5a761e 100644
--- a/coprs_frontend/coprs/templates/coprs/detail/_build_forms.html
+++ b/coprs_frontend/coprs/templates/coprs/detail/_build_forms.html
@@ -1,8 +1,10 @@
+{% from "_helpers.html" import render_field %}
+
 {% macro copr_build_form(form, view, copr) %} 
-    <form action="{{ url_for(view, username = copr.owner.name, coprname = copr.name) }}" method=post class=add-entry> 
+    <form action="{{ url_for(view, username=copr.owner.name, coprname=copr.name) }}" method="post"> 
       <dl> 
         {{ form.csrf_token }} 
-        {{ render_field(form.pkgs, rows = 10, cols = 50) }} 
+        {{ render_field(form.pkgs, label='URLs of packages to build', rows = 10, cols = 50) }} 
         {% if g.user.proven %} 
           {{ render_field(form.memory_reqs) }} 
           {{ render_field(form.timeout) }} 
@@ -10,7 +12,7 @@
           {{ render_field(form.memory_reqs, hidden = True) }} 
           {{ render_field(form.timeout, hidden = True) }} 
         {% endif %} 
-        <dd><input type=submit value=Submit></dd> 
+        <dd><input type="submit" value="Build"></dd> 
       </dl> 
     </form> 
 {% endmacro %} 
diff --git a/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py b/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py
index 0027b3b..c2fcccc 100644
--- a/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py
+++ b/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py
@@ -29,9 +29,21 @@ def copr_show_builds(username, coprname, page = 1):
     return flask.render_template('coprs/show_builds.html', builds = paginator.sliced_query, paginator = paginator)
 
 
- at coprs_ns.route('/detail/<username>/<coprname>/add_build/', methods = ["POST"])
+ at coprs_ns.route('/detail/<username>/<coprname>/add_build/')
+def copr_add_build(username, coprname, form=None):
+    copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
+
+    if not copr: # hey, this Copr doesn't exist
+        return page_not_found('Copr with name {0} does not exist.'.format(coprname))
+
+    if not form:
+        form = forms.BuildForm()
+
+    return flask.render_template('coprs/detail/add_build.html', copr=copr, form=form)
+
+ at coprs_ns.route('/detail/<username>/<coprname>/new_build/', methods = ["POST"])
 @login_required
-def copr_add_build(username, coprname):
+def copr_new_build(username, coprname):
     form = forms.BuildForm()
     copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
     if not copr: # hey, this Copr doesn't exist
@@ -52,9 +64,9 @@ def copr_add_build(username, coprname):
         db.session.commit()
 
         flask.flash("Build was added")
-        return flask.redirect(flask.url_for('coprs_ns.copr_detail', username = username, coprname = copr.name))
+        return flask.redirect(flask.url_for('coprs_ns.copr_detail', username=username, coprname=copr.name))
     else:
-        return flask.current_app.view_functions['coprs_ns.copr_detail'](username = username, coprname = coprname, build_form = form)
+        return copr_add_build(username=username, coprname=coprname, form=form)
 
 @coprs_ns.route('/detail/<username>/<coprname>/cancel_build/<int:build_id>/', methods = ['POST'])
 @login_required
diff --git a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
index 4459528..2b1eff6 100644
--- a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
+++ b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
@@ -128,7 +128,7 @@ def copr_permissions(username, coprname):
                                  current_user_permissions = user_perm)
 
 @coprs_ns.route('/detail/<username>/<coprname>/builds/')
-def copr_builds(username, coprname, build_form = None):
+def copr_builds(username, coprname):
     try: # query[0:10][0] will raise an index error, if Copr doesn't exist
         query = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname, with_builds = True)
         copr = query[0:10][0]# we retrieved all builds, but we got one copr in a list...



More information about the copr-devel mailing list