Commit 881c856c authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

minor changes/fixes

parent 63c0ae82
......@@ -39,6 +39,10 @@ from hashlib import new as newhasher
from astakos.im.models import AstakosUser
from astakos.im.util import get_or_create_user
from astakos.im.forms import ExtendedUserCreationForm
import uuid
import logging
class AdminProfileForm(forms.ModelForm):
"""
......@@ -58,4 +62,28 @@ class AdminProfileForm(forms.ModelForm):
ro_fields = ('username','date_joined', 'auth_token', 'last_login', 'email')
if instance and instance.id:
for field in ro_fields:
self.fields[field].widget.attrs['readonly'] = True
\ No newline at end of file
self.fields[field].widget.attrs['readonly'] = True
class AdminUserCreationForm(ExtendedUserCreationForm):
class Meta:
model = AstakosUser
fields = ("email", "first_name", "last_name", "is_superuser",
"is_active", "affiliation")
def __init__(self, *args, **kwargs):
"""
Changes the order of fields, and removes the username field.
"""
super(AdminUserCreationForm, self).__init__(*args, **kwargs)
self.fields.keyOrder = ['email', 'first_name', 'last_name',
'is_superuser', 'is_active', 'affiliation',
'password1', 'password2']
def save(self, commit=True):
user = super(AdminUserCreationForm, self).save(commit=False)
user.username = uuid.uuid4().hex[:30]
user.renew_token()
if commit:
user.save()
logging.info('Created user %s', user)
return user
\ No newline at end of file
......@@ -2,7 +2,7 @@
{% block tabs %}
<ul class="tabs">
<li{% ifequal tab "home" %} class="active"{% endifequal %}>
<li{% ifequal tab "admin" %} class="active"{% endifequal %}>
<a href="{% url astakos.im.admin.views.admin %}">Home</a>
</li>
<li{% ifequal tab "users" %} class="active"{% endifequal %}>
......
......@@ -3,63 +3,7 @@
{% block body %}
<form action="{% url astakos.im.admin.views.users_create %}" method="post">{% csrf_token %}
<div class="clearfix">
<label for="user-username">Username</label>
<div class="input">
<input class="span4" id="user-username" name="username" type="text" />
</div>
</div>
<div class="clearfix">
<label for="user-email">Email</label>
<div class="input">
<input class="span4" id="user-email" name="email" type="text" />
</div>
</div>
<div class="clearfix">
<label for="user-first-name">First Name</label>
<div class="input">
<input class="span4" id="user-first-name" name="first_name" type="text" />
</div>
</div>
<div class="clearfix">
<label for="user-last-name">Last Name</label>
<div class="input">
<input class="span4" id="user-last-name" name="last_name" type="text" />
</div>
</div>
<div class="clearfix">
<label for="user-admin">Admin</label>
<div class="input">
<ul class="inputs-list">
<li>
<label>
<input type="checkbox" id="user-admin" name="admin">
</label>
</li>
</ul>
</div>
</div>
<div class="clearfix">
<label for="user-affiliation">Affiliation</label>
<div class="input">
<input class="span4" id="user-affiliation" name="affiliation" type="text" />
</div>
</div>
<div class="clearfix">
<label for="user-quota">Quota</label>
<div class="input">
<div class="input-append">
<input class="span2" id="user-quota" name="quota" type="text" />
<span class="add-on">GiB</span>
</div>
</div>
</div>
{{ form.as_p }}
<div class="actions">
<button type="submit" class="btn primary">Create</button>
......
......@@ -64,6 +64,7 @@ from astakos.im.forms import *
from astakos.im.backends import get_backend
from astakos.im.views import render_response, index
from astakos.im.admin.forms import AdminProfileForm
from astakos.im.admin.forms import AdminUserCreationForm
def requires_admin(func):
"""
......@@ -214,6 +215,7 @@ def users_info(request, user_id, template_name='users_info.html', extra_context=
user = AstakosUser.objects.get(id=user_id)
return render_response(template_name,
form = AdminProfileForm(instance=user),
user = user,
context_instance = get_context(request, extra_context))
@requires_admin
......@@ -534,18 +536,15 @@ def users_create(request, template_name='users_create.html', extra_context={}):
users_create.html or ``template_name`` keyword argument.
"""
if request.method == 'GET':
return render_response(template_name,
form = AdminUserCreationForm()
elif request.method == 'POST':
form = AdminUserCreationForm(request.POST)
if form.is_valid():
try:
user = form.save()
return users_info(request, user.id)
except ValueError, e:
messages.add_message(request, messages.ERROR, e)
return render_response(template_name,
form = form,
context_instance=get_context(request, extra_context))
if request.method == 'POST':
user = AstakosUser()
user.username = request.POST.get('username')
user.email = request.POST.get('email')
user.first_name = request.POST.get('first_name')
user.last_name = request.POST.get('last_name')
user.is_superuser = True if request.POST.get('admin') else False
user.affiliation = request.POST.get('affiliation')
user.quota = int(request.POST.get('quota') or 0) * (1024**3) # In GiB
user.renew_token()
user.provider = 'local'
user.save()
return redirect(users_info, user.id)
......@@ -73,6 +73,8 @@ class ExtendedUserCreationForm(UserCreationForm):
def clean_email(self):
email = self.cleaned_data['email']
if not email:
raise forms.ValidationError(_("This field is required"))
try:
AstakosUser.objects.get(email = email)
raise forms.ValidationError(_("Email is reserved"))
......@@ -118,8 +120,8 @@ class InvitedExtendedUserCreationForm(ExtendedUserCreationForm):
def save(self, commit=True):
user = super(InvitedExtendedUserCreationForm, self).save(commit=False)
level = user.invitation.inviter.level
user.level = level + 1
level = user.invitation.inviter.level + 1
user.level = level
user.invitations = settings.INVITATIONS_PER_LEVEL[level]
if commit:
user.save()
......
......@@ -5,11 +5,11 @@
<li{% ifequal tab "profile" %} class="active"{% endifequal %}>
<a href="{% url astakos.im.views.edit_profile %}">Profile</a>
</li>
<li{% ifequal tab "passwordchange" %} class="active"{% endifequal %}>
<li{% ifequal not tab %} class="active"{% endifequal %}>
<a href="{% url django.contrib.auth.views.password_change %}">Password Change</a>
</li>
{% if invitations_enabled %}
<li{% ifequal tab "invite" %} class="active"{% endifequal %}>
<li{% ifequal tab "invitations" %} class="active"{% endifequal %}>
<a href="{% url astakos.im.views.invite %}">Invite</a>
</li>
{% endif %}
......
......@@ -4,7 +4,7 @@
{% block body %}
<form method="post">{% csrf_token %}
<form action="{% url astakos.im.views.send_feedback %}" method="post">{% csrf_token %}
{{ form.as_p }}
<div class="actions">
......
......@@ -9,7 +9,7 @@
{% if user.invitations %}
<br />
<h4>Invite someone else:</h4>
<form method="post">{% csrf_token %}
<form action="{% url astakos.im.views.invite %}" method="post">{% csrf_token %}
<div class="clearfix">
<label for="user-realname">Name</label>
<div class="input">
......
......@@ -10,7 +10,7 @@
{% if "local" in im_modules %}
<div class="span4">
<h4>Local account</h4>
<form action="" method="post" class="form-stacked">{% csrf_token %}
<form action="{% url astakos.im.views.signup %}" method="post" class="form-stacked">{% csrf_token %}
{{ form.as_p }}
<br>
<div class="">
......
......@@ -61,7 +61,6 @@ from django.contrib import messages
from django.db import transaction
from django.contrib.auth.forms import UserCreationForm
#from astakos.im.openid_store import PithosOpenIDStore
from astakos.im.models import AstakosUser, Invitation
from astakos.im.util import isoformat, get_context, get_current_site
from astakos.im.backends import get_backend
......@@ -74,7 +73,7 @@ def render_response(template, tab=None, status=200, context_instance=None, **kwa
specified ``status``.
"""
if tab is None:
tab = template.partition('_')[0]
tab = template.partition('_')[0].partition('.html')[0]
kwargs.setdefault('tab', tab)
html = render_to_string(template, kwargs, context_instance=context_instance)
return HttpResponse(html, status=status)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment