Skip to content

Commit

Permalink
Merge pull request CitoEngine#6 from CitoEngine/develop
Browse files Browse the repository at this point in the history
version 0.9.3 fixes multiple ui bugs
  • Loading branch information
extremeunix committed Jul 1, 2014
2 parents c63b596 + f79e034 commit 3237bee
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cito_plugin_server/templates/view_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h2><i class="icon-info-sign"></i>User Details</h2>
{% endif %}
</form>


<div class="btn-group"><a class="btn btn-info" href="/users/edit/{{ view_user.id }}/">Edit Details</a></div>
</div>

</div> <!--user info -->
Expand Down
5 changes: 3 additions & 2 deletions cito_plugin_server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)

urlpatterns += patterns('',
url(r'^$', 'webservice.views.auth_views.login_user'),
url(r'^$', 'webservice.views.plugin_views.view_all_plugins'),
url(r'^login/$', 'webservice.views.auth_views.login_user'),
url(r'^logout/$', 'webservice.views.auth_views.logout_user'),
)
Expand All @@ -49,8 +49,9 @@
urlpatterns += patterns('',
url(r'^users/$', 'webservice.views.user_views.view_all_users'),
url(r'^users/create/$', 'webservice.views.user_views.create_user'),
url(r'^users/edit/(?P<user_id>\d+)/$', 'webservice.views.user_views.edit_user'),
url(r'^users/toggle/$', 'webservice.views.user_views.toggle_user'),
url(r'^users/view/(?P<user_id>\d+)$', 'webservice.views.user_views.view_single_user'),
url(r'^users/view/(?P<user_id>\d+)/$', 'webservice.views.user_views.view_single_user'),
)

urlpatterns += patterns('',
Expand Down
24 changes: 24 additions & 0 deletions webservice/forms/user_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ def clean(self):
password1 = cleaned_data.get('password1')
password2 = cleaned_data.get('password2')

if password1 and password2 and password1 != password2:
msg = u"The passwords did not match. Please try again."
self._errors["password1"] = self.error_class([msg])
self._errors["password2"] = self.error_class([msg])
return cleaned_data


class EditUserForm(forms.Form):
first_name = forms.CharField(label='First name', max_length=100)
last_name = forms.CharField(label='Last name', max_length=100)
username = forms.CharField(max_length=100)
password1 = forms.CharField(label='Password', widget=forms.PasswordInput, required=False)
password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput, required=False)
email = forms.EmailField()

def __init__(self, *args, **kwargs):
super(EditUserForm, self).__init__(*args, **kwargs)
self.fields['password1'].help_text = "Leave blank if you dont want to change it"

def clean(self):
cleaned_data = super(EditUserForm, self).clean()
password1 = cleaned_data.get('password1')
password2 = cleaned_data.get('password2')

if password1 and password2 and password1 != password2:
msg = u"The passwords did not match. Please try again."
self._errors["password1"] = self.error_class([msg])
Expand Down
29 changes: 29 additions & 0 deletions webservice/views/user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ def create_user(request):
render_vars['form'] = form
return render_to_response('generic_form.html', render_vars, context_instance=RequestContext(request))

@login_required(login_url='/login/')
def edit_user(request, user_id):
render_vars = dict()
user = get_object_or_404(User, pk=user_id)
if not request.user.is_superuser:
return render_to_response('unauthorized.html', context_instance=RequestContext(request))
if request.method == "POST":
form = user_forms.EditUserForm(request.POST)
if form.is_valid():
user.first_name = form.cleaned_data.get('first_name')
user.last_name = form.cleaned_data.get('last_name')
user.username = form.cleaned_data.get('username')
user.email = form.cleaned_data.get('email')
user.save()
password = form.cleaned_data.get('password1')
if password:
user.set_password(password)
user.save()
return redirect('/users/view/%s/' % user.id)
else:
form_vars = {'first_name': user.first_name,
'last_name': user.last_name,
'email': user.email,
'username': user.username}
form = user_forms.EditUserForm(initial=form_vars)
render_vars['form'] = form
render_vars['page_title'] = render_vars['box_title'] = 'Editing user: %s ' % user.username
return render_to_response('generic_form.html', render_vars, context_instance=RequestContext(request))


@login_required(login_url='/login/')
def toggle_user(request):
Expand Down

0 comments on commit 3237bee

Please sign in to comment.