[mango/django] Create initial add_account view
- From: Olav Vitters <ovitters src gnome org>
- To: svn-commits-list gnome org
- Subject: [mango/django] Create initial add_account view
- Date: Sun, 19 Jul 2009 10:44:37 +0000 (UTC)
commit f86a60f6b05287960963a9904b3cda536bea9c1a
Author: Olav Vitters <olav bkor dhs org>
Date: Sun Jul 19 12:13:32 2009 +0200
Create initial add_account view
This doesn't work yet.
mango/models.py | 10 +++++++++-
mango/views.py | 38 +++++++++++++++++++++++++++++++++-----
www/new_account.xsl | 16 ++++++++--------
3 files changed, 50 insertions(+), 14 deletions(-)
---
diff --git a/mango/models.py b/mango/models.py
index c9be343..6b8707b 100644
--- a/mango/models.py
+++ b/mango/models.py
@@ -9,7 +9,7 @@
from django.db import models
from django.conf import settings
-from django.forms import ModelForm, BaseModelForm, BooleanField
+from django.forms import ModelForm, BaseModelForm, BooleanField, MultipleChoiceField, ChoiceField
from django.utils import tree
from django.db.models import Q
import ldap
@@ -36,6 +36,14 @@ class AccountsForm(ModelForm):
class Meta:
model = AccountRequest
+class AccountsFormAdd(ModelForm):
+ group = MultipleChoiceField()
+ vouch_dev = ChoiceField()
+ vouch_i18n = ChoiceField()
+
+ class Meta:
+ model = AccountRequest
+
class AccountGroups(models.Model):
id = models.AutoField(primary_key=True)
request = models.ForeignKey(AccountRequest)
diff --git a/mango/views.py b/mango/views.py
index 740eb5e..d1d5bf6 100644
--- a/mango/views.py
+++ b/mango/views.py
@@ -202,23 +202,51 @@ def list_accounts(request):
return get_xmlresponse(doc, "list_accounts.xsl")
+def add_account_to_xml(root, member=None, form=None, dev_modules=None, trans_modules=None):
+ if member is None and form is None:
+ return
+
+ instance = form and form.instance or member
+ form_or_member = form and form.data or member.__dict__
+
+ vouch_dev = form_or_member.get('vouch_dev', None)
+ vouch_i18n = form_or_member.get('vouch_i18n', None)
+
+ for module in dev_modules:
+ if module.cn == vouch_dev:
+ ET.SubElement(root, 'gnomemodule', {'cn': module.cn, 'selected': '1'})
+ else:
+ ET.SubElement(root, 'gnomemodule', {'cn': module.cn})
+ for module in trans_modules:
+ if module.cn == vouch_i18n:
+ ET.SubElement(root, 'translation', {'cn': module.cn, 'desc': module.description, 'selected': '1'})
+ else:
+ ET.SubElement(root, 'translation', {'cn': module.cn, 'desc': module.description})
+
+ for field in ('uid', 'cn', 'mail', 'comment'):
+ ET.SubElement(root, field).text = form_or_member[field]
+ if form:
+ for cn in form.data.getlist('group'):
+ ET.SubElement(root, 'group', {'cn': cn})
+
def add_account(request):
doc, pagenode = get_xmldoc('Request LDAP account', request, 'newaccount')
dev_modules = models.DevModules.search()
trans_modules = models.L10nModules.search()
- for module in dev_modules:
- ET.SubElement(pagenode, 'gnomemodule', {'cn': module.cn})
- for module in trans_modules:
- ET.SubElement(pagenode, 'translation', {'cn': module.cn, 'desc': module.description})
+ f = None
if request.method == 'POST':
- f = models.AccountsForm(request.POST)
+ f = models.AccountsFormAdd(request.POST)
+ f.fields['vouch_dev'].choices = [(module.cn, module.cn) for module in dev_modules]
+ f.fields['vouch_i18n'].choices = [(module.cn, module.description) for module in trans_modules]
if add_form_errors_to_xml(pagenode, f):
# mirror = f.save()
return HttpResponseRedirect(u'../view/%s' % unicode(mirror.id))
+ add_account_to_xml(pagenode, form=f, dev_modules=dev_modules, trans_modules=trans_modules)
+
return get_xmlresponse(doc, "new_account.xsl")
def list_mirrors(request):
diff --git a/www/new_account.xsl b/www/new_account.xsl
index 03dc2da..8b5c269 100644
--- a/www/new_account.xsl
+++ b/www/new_account.xsl
@@ -7,7 +7,7 @@
<xsl:include href="common.xsl" />
- <xsl:variable name="script" select="'new_account.php'"/>
+ <xsl:variable name="script" select="'.'"/>
<xsl:template match="newaccount">
@@ -121,7 +121,7 @@
</th>
<td>
<div>
- <input onclick="on_ability_click()" type="checkbox" name="gnomecvs" id="gnomecvs">
+ <input onclick="on_ability_click()" type="checkbox" name="group" value="gnomecvs" id="gnomecvs">
<xsl:if test="boolean(group[ cn='gnomecvs'])">
<xsl:attribute name="checked"/>
</xsl:if>
@@ -129,7 +129,7 @@
<label for="gnomecvs">Access to Git</label>
</div>
<div>
- <input onclick="on_ability_click()" type="checkbox" name="ftpadmin" id="ftpadmin">
+ <input onclick="on_ability_click()" type="checkbox" name="group" value="ftpadmin" id="ftpadmin">
<xsl:if test="boolean(group[ cn='ftpadmin'])">
<xsl:attribute name="checked"/>
</xsl:if>
@@ -137,7 +137,7 @@
<label for="ftpadmin">Install new modules on ftp.gnome.org</label>
</div>
<div>
- <input type="checkbox" name="mailusers" id="mailusers">
+ <input type="checkbox" name="group" value="mailusers" id="mailusers">
<xsl:if test="boolean(group[ cn='mailusers'])">
<xsl:attribute name="checked"/>
</xsl:if>
@@ -146,7 +146,7 @@
</div>
<p>Special abilities:
<div>
- <input type="checkbox" name="gnomeweb" id="gnomeweb">
+ <input type="checkbox" name="group" value="gnomeweb" id="gnomeweb">
<xsl:if test="boolean(group[ cn='gnomeweb'])">
<xsl:attribute name="checked"/>
</xsl:if>
@@ -154,7 +154,7 @@
<label for="gnomeweb">Shell access for GNOME websites</label>
</div>
<div>
- <input type="checkbox" name="bugzilla" id="bugzilla">
+ <input type="checkbox" name="group" value="bugzilla" id="bugzilla">
<xsl:if test="boolean(group[ cn='bugzilla'])">
<xsl:attribute name="checked"/>
</xsl:if>
@@ -162,7 +162,7 @@
<label for="bugzilla">Shell access for GNOME Bugzilla</label>
</div>
<div>
- <input type="checkbox" name="artweb" id="artweb">
+ <input type="checkbox" name="group" value="artweb" id="artweb">
<xsl:if test="boolean(group[ cn='artweb'])">
<xsl:attribute name="checked"/>
</xsl:if>
@@ -170,7 +170,7 @@
<label for="artweb">Shell access for GNOME art website</label>
</div>
<div>
- <input type="checkbox" name="membctte" id="membctte">
+ <input type="checkbox" name="group" value="membctte" id="membctte">
<xsl:if test="boolean(group[ cn='membctte'])">
<xsl:attribute name="checked"/>
</xsl:if>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]