[copr] master: Mandate at least one mock chroot per copr (734f797)
bkabrda at fedoraproject.org
bkabrda at fedoraproject.org
Tue Jan 15 11:06:50 UTC 2013
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 734f7978bd2a81eea1dc4a6d95a33cca564f4322
Author: Bohuslav Kabrda <bkabrda at redhat.com>
Date: Tue Jan 15 10:48:04 2013 +0100
Mandate at least one mock chroot per copr
>---------------------------------------------------------------
coprs_frontend/coprs/forms.py | 16 ++++++++++++++++
.../coprs/templates/coprs/_coprs_forms.html | 3 +++
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/coprs_frontend/coprs/forms.py b/coprs_frontend/coprs/forms.py
index 3a8fc59..cfca500 100644
--- a/coprs_frontend/coprs/forms.py
+++ b/coprs_frontend/coprs/forms.py
@@ -90,6 +90,22 @@ class CoprFormFactory(object):
selected.append(ch)
return selected
+ def validate(self):
+ if not super(F, self).validate():
+ return False
+
+ if not self.validate_mock_chroots_not_empty():
+ self._mock_chroots_error = 'At least one chroot must be selected'
+ return False
+ return True
+
+ def validate_mock_chroots_not_empty(self):
+ have_any = False
+ for c in self.chroots_list:
+ if getattr(self, c).data:
+ have_any = True
+ return have_any
+
F.chroots_list = map(lambda x: x.chroot_name, models.MockChroot.query.filter(models.MockChroot.is_active==True).all())
F.chroots_list.sort()
F.chroots_sets = {} # sets of chroots according to how we should print them in columns
diff --git a/coprs_frontend/coprs/templates/coprs/_coprs_forms.html b/coprs_frontend/coprs/templates/coprs/_coprs_forms.html
index 7b90310..4256bdc 100644
--- a/coprs_frontend/coprs/templates/coprs/_coprs_forms.html
+++ b/coprs_frontend/coprs/templates/coprs/_coprs_forms.html
@@ -4,6 +4,9 @@
{# if using for updating, we need to pass name to url_for, but otherwise we need to pass nothing #}
<form action="{% if copr %}{{ url_for(view, username = copr.owner.name, coprname = copr.name) }}{% else %}{{ url_for(view) }}{% endif %}" method=post class=add-entry>
<dl>
+ {% if form._mock_chroots_error %}
+ <p style="color:red;">{{ form._mock_chroots_error }}</p>
+ {% endif %}
{{ form.csrf_token }}
{{ render_field(form.id, hidden = True) }}
{{ render_field(form.name) }}
More information about the copr-devel
mailing list