Menu

[r6348]: / trunk / gui / account / views.py  Maximize  Restore  History

Download this file

177 lines (149 with data), 6.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#+
# Copyright 2010 iXsystems
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted providing that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# $FreeBSD$
#####################################################################
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils import simplejson
from django.utils.translation import ugettext as _
from freenasUI.account import forms
from freenasUI.account import models
def home(request):
focus_form = request.GET.get('tab', 'passform')
variables = RequestContext(request, {
'focus_form': focus_form,
})
return render_to_response('account/index2.html', variables)
def bsduser(request):
bsduser_list = models.bsdUsers.objects.order_by("id").select_related().filter(bsdusr_builtin=False)
bsduser_list_builtin = models.bsdUsers.objects.order_by("id").select_related().filter(bsdusr_builtin=True)
variables = RequestContext(request, {
'bsduser_list': bsduser_list,
'bsduser_list_builtin': bsduser_list_builtin,
})
return render_to_response('account/bsdusers.html', variables)
def bsdgroup(request):
bsdgroup_list = models.bsdGroups.objects.order_by("id").filter(bsdgrp_builtin=False)
bsdgroup_list_builtin = models.bsdGroups.objects.order_by("id").filter(bsdgrp_builtin=True)
variables = RequestContext(request, {
'bsdgroup_list': bsdgroup_list,
'bsdgroup_list_builtin': bsdgroup_list_builtin,
})
return render_to_response('account/bsdgroups.html', variables)
def password_change(request):
extra_context = {}
password_change_form=forms.PasswordChangeForm
passform = password_change_form(user=request.user)
if request.method == 'POST':
passform = password_change_form(user=request.user, data=request.POST)
if passform.is_valid():
passform.save()
passform = password_change_form(user=request.user)
return HttpResponse(simplejson.dumps({"error": False, "message": _("%s successfully update.") % _("Password")}), mimetype="application/json")
extra_context.update({ 'passform' : passform, })
variables = RequestContext(request, extra_context)
return render_to_response('account/passform.html', variables)
def user_change(request):
extra_context = {}
changeform = forms.UserChangeForm(instance=request.user)
if request.method == 'POST':
changeform = forms.UserChangeForm(instance=request.user, data=request.POST)
if changeform.is_valid():
changeform.save()
return HttpResponse(simplejson.dumps({"error": False, "message": _("%s successfully update.") % _("Admin user")}), mimetype="application/json")
extra_context.update({ 'changeform' : changeform, })
variables = RequestContext(request, extra_context)
return render_to_response('account/changeform.html', variables)
def group2user_update(request, object_id):
if request.method == 'POST':
f = forms.bsdGroupToUserForm(object_id, request.POST)
if f.is_valid():
f.save()
return HttpResponse(simplejson.dumps({"error": False, "message": _("%s successfully update.") % _("Users")}), mimetype="application/json")
#return render_to_response('account/bsdgroup2user_form_ok.html')
else:
f = forms.bsdGroupToUserForm(groupid=object_id)
variables = RequestContext(request, {
'url': reverse('account_bsdgroup_members', kwargs={'object_id':object_id}),
'form' : f,
})
return render_to_response('account/bsdgroup2user_form2.html', variables)
def user2group_update(request, object_id):
if request.method == 'POST':
f = forms.bsdUserToGroupForm(object_id, request.POST)
if f.is_valid():
f.save()
return HttpResponse(simplejson.dumps({"error": False, "message": _("%s successfully update.") % _("Groups")}), mimetype="application/json")
#return render_to_response('account/bsdgroup2user_form_ok.html')
else:
f = forms.bsdUserToGroupForm(userid=object_id)
variables = RequestContext(request, {
'url': reverse('account_bsduser_groups', kwargs={'object_id':object_id}),
'form' : f,
})
return render_to_response('account/bsdgroup2user_form2.html', variables)
def json_users(request):
from common.freenasldap import FreeNAS_Users
query = request.GET.get("q", None)
json = {
'identifier': 'id',
'label': 'name',
'items': [],
}
idx = 1
for user in FreeNAS_Users():
if idx > 50:
break
if query == None or user.bsdusr_username.startswith(query):
json['items'].append({
'id': user.bsdusr_username,
'name': user.bsdusr_username,
'label': user.bsdusr_username,
})
idx += 1
return HttpResponse(simplejson.dumps(json, indent=3))
def json_groups(request):
from common.freenasldap import FreeNAS_Groups
query = request.GET.get("q", None)
json = {
'identifier': 'id',
'label': 'name',
'items': [],
}
idx = 1
for grp in FreeNAS_Groups():
if idx > 50:
break
if query == None or grp.bsdgrp_group.startswith(query):
json['items'].append({
'id': grp.bsdgrp_group,
'name': grp.bsdgrp_group,
'label': grp.bsdgrp_group,
})
idx += 1
return HttpResponse(simplejson.dumps(json, indent=3))
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.