示例#1
0
def edit_admin(request, pk):
	admin_form = AdminForm(prefix="adm")
	user_form = UserForm(prefix="usr")

	user = get_object_or_404(User, pk=pk)
	admin = get_object_or_404(Admin, user_id=user.pk)
	if request.method == 'POST':
		admin_form = AdminForm(request.POST, prefix="adm", instance=admin)
		user_form = UserForm(request.POST, prefix="usr", instance=admin.user)
		if user_form.is_valid() and admin_form.is_valid():
			user = user_form.save()
			admin = admin_form.save(commit=False)
			admin.user = user
			admin.pic = request.FILES['adm-pic']
			admin.save()
			#request.user = user
			request.user.save()
			return redirect('admin_details', matriculation=admin.matriculation)
		else:
			messages.error(request, "Error")
			return render(request, 'locker_manager/register_admin.html',{'admin_form':admin_form, 'user_form':user_form})
	else:
		admin_form = AdminForm(prefix="adm", instance=admin)	
		user_form = UserForm(prefix="usr", instance=admin.user)
		return render(request, 'locker_manager/register_admin.html',{'admin_form':admin_form, 'user_form':user_form})	
示例#2
0
文件: views.py 项目: berlincount/cbmi
def admin(request):
    admin_member = retrieve_member(request)
    if not request.user.profile.is_ldap_admin:
        return render(request, 'access_denied.html')
    users = admin_member.list_users()
    if request.method == 'POST':
        form = AdminForm(request.POST, request=request, users=users)

        if form.is_valid():
            new_password = form.cleaned_data['password1']
            admin_member.admin_change_password(form.cleaned_data['username'],
                                               new_password)

            member = MemberValues(form.cleaned_data['username'], new_password)
            member.set('sambaLMPassword', smbpasswd.lmhash(new_password))
            member.set('sambaNTPassword', smbpasswd.nthash(new_password))
            member.save()

            new_form = AdminForm(request=request, users=users)
            return render(
                request, 'admin.html', {
                    'message':
                    _('The password for %s was changed. Thank you!' %
                      form.cleaned_data['username']),
                    'form':
                    new_form
                })
        else:
            return render(request, 'admin.html', {'form': form})
    else:
        form = AdminForm(request=request, users=users)
        return render(request, 'admin.html', {'form': form})
示例#3
0
文件: opt.py 项目: v-komarov/kis
def	ItOpt(request):


    if CheckAccess(request,'3') != 'OK':
	return render_to_response("ithelpdesk/notaccess/opt.html")

    ### --- Сохранение закладки ----
    request.session['bookmark'] = 'itopt'

    if request.method == 'POST':
	form = AdminForm(request.POST)
	if form.is_valid():
	    admin = form.cleaned_data['admin']
	    AddAdminUser(admin)

    try:
	delete_admin = request.GET['delete_admin']
	DelAdminUser(delete_admin)
    except:
	pass


    form = AdminForm(None)

    ### --- Получение списка ---
    data = GetAdminList()
	
    c = RequestContext(request,{'form':form,'data':data})
    c.update(csrf(request))
    return render_to_response("ithelpdesk/opt.html",c)
示例#4
0
文件: views.py 项目: herzmut/cbmi
def admin(request):
    admin_member = retrieve_member(request)
    if not request.user.profile.is_ldap_admin:
        return render(request, 'access_denied.html')
    users = admin_member.list_users()
    if request.method == 'POST':
        form = AdminForm(request.POST, request=request, users=users)

        if form.is_valid():
            new_password = form.cleaned_data['password1']
            admin_member.admin_change_password(form.cleaned_data['username'], new_password)

            member = MemberValues(form.cleaned_data['username'], new_password)
            member.set('sambaLMPassword', smbpasswd.lmhash(new_password))
            member.set('sambaNTPassword', smbpasswd.nthash(new_password))
            member.save()

            new_form = AdminForm(request=request, users=users)
            return render(request, 'admin.html',
                {'message': _('The password for %s was changed. Thank you!' % form.cleaned_data['username']),
                 'form': new_form})
        else:
            return render(request, 'admin.html',
                {'form': form})
    else:
        form = AdminForm(request=request, users=users)
        return render(request, 'admin.html',
            {'form': form})
示例#5
0
def register_admin(request):
    admin_form = AdminForm(prefix="adm")
    user_form = UserForm(prefix="usr")

    if request.method == 'POST':
        admin_form = AdminForm(request.POST, prefix="adm")
        user_form = UserForm(request.POST, prefix="usr")
        if user_form.is_valid() and admin_form.is_valid():
            user = user_form.save()
            admin = admin_form.save(commit=False)
            admin.user = user
            admin.save()
            return redirect('locker_manager.views.admin_details',
                            matriculation=admin.matriculation)
        else:
            messages.error(request, "Error")
            return render(request, 'locker_manager/register_admin.html', {
                'admin_form': admin_form,
                'user_form': user_form
            })

    else:
        return render(request, 'locker_manager/register_admin.html', {
            'admin_form': admin_form,
            'user_form': user_form
        })
示例#6
0
def edit_admin(request, pk):
    admin_form = AdminForm(prefix="adm")
    user_form = UserForm(prefix="usr")

    user = get_object_or_404(User, pk=pk)
    admin = get_object_or_404(Admin, user_id=user.pk)
    if request.method == 'POST':
        admin_form = AdminForm(request.POST, prefix="adm", instance=admin)
        user_form = UserForm(request.POST, prefix="usr", instance=admin.user)
        if user_form.is_valid() and admin_form.is_valid():
            user = user_form.save()
            admin = admin_form.save(commit=False)
            admin.user = user
            admin.pic = request.FILES['adm-pic']
            admin.save()
            #request.user = user
            request.user.save()
            return redirect('admin_details', matriculation=admin.matriculation)
        else:
            messages.error(request, "Error")
            return render(request, 'locker_manager/register_admin.html', {
                'admin_form': admin_form,
                'user_form': user_form
            })
    else:
        admin_form = AdminForm(prefix="adm", instance=admin)
        user_form = UserForm(prefix="usr", instance=admin.user)
        return render(request, 'locker_manager/register_admin.html', {
            'admin_form': admin_form,
            'user_form': user_form
        })
示例#7
0
def admin(request):
    """ Set up default admin account. """
    admin_form = AdminForm()
    if request.method == "POST":
        admin_form = AdminForm(request.POST)
        if admin_form.is_valid():
            user = User.objects.create_user(admin_form.cleaned_data['username'], admin_form.cleaned_data['email_address'], admin_form.cleaned_data['password'])
            user.is_staff = True
            user.save()
            print user
            return redirect("index")
    return render(request, "wizard/admin.html", {"form": admin_form})
示例#8
0
def admin(request):
    """ Set up default admin account. """
    admin_form = AdminForm()
    if request.method == "POST":
        admin_form = AdminForm(request.POST)
        if admin_form.is_valid():
            user = User.objects.create_user(
                admin_form.cleaned_data['username'],
                admin_form.cleaned_data['email_address'],
                admin_form.cleaned_data['password'])
            user.is_staff = True
            user.save()
            print user
            return redirect("index")
    return render(request, "wizard/admin.html", {"form": admin_form})
示例#9
0
def register_admin(request):
	admin_form = AdminForm(prefix="adm")
	user_form = UserForm(prefix="usr")

	if request.method == 'POST':
		admin_form = AdminForm(request.POST, prefix="adm")
		user_form = UserForm(request.POST, prefix="usr")
		if user_form.is_valid() and admin_form.is_valid():
			user = user_form.save()
			admin = admin_form.save(commit=False)
			admin.user = user
			admin.save()
			return redirect('locker_manager.views.admin_details', matriculation=admin.matriculation)
		else:
			messages.error(request, "Error")
			return render(request, 'locker_manager/register_admin.html',{'admin_form':admin_form, 'user_form':user_form})

	else:	
		return render(request, 'locker_manager/register_admin.html',{'admin_form':admin_form, 'user_form':user_form})