Package coprs :: Package views :: Package coprs_ns :: Module coprs_chroots
[hide private]
[frames] | no frames]

Source Code for Module coprs.views.coprs_ns.coprs_chroots

 1  import flask 
 2   
 3  from coprs import db 
 4  from coprs import exceptions 
 5  from coprs import forms 
 6  from coprs import helpers 
 7  from coprs import models 
 8   
 9  from coprs.logic import builds_logic 
10  from coprs.logic import coprs_logic 
11   
12  from coprs.views.misc import login_required, page_not_found 
13  from coprs.views.coprs_ns import coprs_ns 
14 15 16 @coprs_ns.route('/<username>/<coprname>/edit_chroot/<chrootname>/') 17 @login_required 18 -def chroot_edit(username, coprname, chrootname):
19 copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() 20 if not copr: 21 return page_not_found('Project with name {0} does not exist.'.format(coprname)) 22 try: 23 chroot = coprs_logic.MockChrootsLogic.get_from_name(chrootname, active_only=True).first() 24 except ValueError, e: 25 return page_not_found("%s" % e) 26 if not chroot: 27 return page_not_found('Chroot name {0} does not exist.'.format(chrootname)) 28 form = forms.ChrootForm(buildroot_pkgs=copr.buildroot_pkgs(chroot)) 29 #FIXME - test if chroot belongs to copr 30 if flask.g.user.can_build_in(copr): 31 return flask.render_template('coprs/detail/edit_chroot.html', form=form, copr=copr, chroot=chroot) 32 else: 33 return page_not_found("You are not allowed to modify chroots in project ${0}." % coprname)
34
35 @coprs_ns.route('/<username>/<coprname>/update_chroot/<chrootname>/', methods=['POST']) 36 @login_required 37 -def chroot_update(username, coprname, chrootname):
38 form = forms.ChrootForm() 39 copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() 40 if not copr: 41 return page_not_found('Projec with name {0} does not exist.'.format(coprname)) 42 try: 43 chroot = coprs_logic.MockChrootsLogic.get_from_name(chrootname, active_only=True).first() 44 except ValueError, e: 45 return page_not_found("%s" % e) 46 if form.validate_on_submit() and flask.g.user.can_build_in(copr): 47 coprs_logic.CoprChrootsLogic.update_buildroot_pkgs(copr, chroot, form.buildroot_pkgs.data) 48 flask.flash("Buildroot {0} for project {1} was updated".format(chrootname, coprname)) 49 db.session.commit() 50 51 return flask.redirect(flask.url_for('coprs_ns.copr_edit', username = username, coprname = copr.name)) 52 else: 53 if form.validate_on_submit(): 54 flask.flash("You are not allowed to modify chroots.") 55 else: 56 return chroot_edit(username, coprname, chrootname)
57