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