Esempio n. 1
0
def create_user(request):
    users = User.objects.all()
    inst_id = sanitize_get_param(request.GET.get('id'))
    institution = get_institution(inst_id)
    edit_id = sanitize_get_param(request.GET.get('edit_id'))
    edit_user = get_user(edit_id)
    logged_user = request.zeususer._user
    if edit_user:
        if not can_do(logged_user, edit_user):
            raise PermissionDenied
    if edit_user:
        initial = {'institution': edit_user.institution.name}
    elif institution:
        initial = {'institution': institution.name}
    else:
        initial = None
    form = None

    if request.method == 'POST':
        form = userForm(logged_user,
                        request.POST,
                        initial=initial,
                        instance=edit_user)
        if form.is_valid():
            user, password = form.save()
            if edit_user:
                message = _("Changes on user were successfully saved")
            else:
                message = _("User %(uid)s was created with"
                            " password %(password)s.")\
                            % {'uid': user.user_id, 'password': password}
            messages.success(request, message)
            url = "%s?uid=%s" % (reverse('user_management'), \
                str(user.id))
            return redirect(url)

    if request.method == 'GET':
        form = userForm(logged_user, initial=initial, instance=edit_user)

    tpl = 'account_administration/create_user',
    context = {'form': form}
    return render_template(request, tpl, context)
Esempio n. 2
0
def create_institution(request):
    inst_id = sanitize_get_param(request.GET.get('id'))
    edit_inst = get_institution(inst_id)
    form = None
    if request.method == 'POST':
        form = institutionForm(request.POST, instance=edit_inst)
        if form.is_valid():
            form.save()
            if edit_inst:
                message = _("Changes were successfully saved")
            else:
                message = _("Institution created.")
            messages.success(request, message)
            return redirect(reverse('list_institutions'))
    if request.method == 'GET':
        form = institutionForm(instance=edit_inst)
    context = {'form': form}
    return render_template(request,
                           'account_administration/create_institution',
                           context)
Esempio n. 3
0
def create_user(request):
    users = User.objects.all()
    inst_id = sanitize_get_param(request.GET.get('id'))
    institution = get_institution(inst_id)
    edit_id = sanitize_get_param(request.GET.get('edit_id'))
    edit_user = get_user(edit_id)
    logged_user = request.zeususer._user
    if edit_user:
        if not can_do(logged_user, edit_user):
            edit_user = None
    if edit_user:
        initial = {'institution': edit_user.institution.name}
    elif institution:
        initial = {'institution': institution.name}
    else:
        initial = None
    form = None

    if request.method == 'POST':
        form = userForm(request.POST, initial=initial, instance=edit_user)
        if form.is_valid():
            user, password = form.save()
            if edit_user:
                message = _("Changes on user were successfully saved")
            else:
                message = _("User %(uid)s was created with"
                            " password %(password)s.")\
                            % {'uid': user.user_id, 'password': password}
            messages.success(request, message)
            url = "%s?uid=%s" % (reverse('user_management'), \
                str(user.id))
            return redirect(url)

    if request.method == 'GET':
        form = userForm(initial=initial, instance=edit_user)

    tpl = 'account_administration/create_user',
    context = {'form': form}
    return render_template(request, tpl, context)
Esempio n. 4
0
def create_institution(request):
    inst_id = sanitize_get_param(request.GET.get('id'))
    edit_inst = get_institution(inst_id)
    form = None
    if request.method == 'POST':
        form = institutionForm(request.POST, instance=edit_inst)
        if form.is_valid():
            form.save()
            if edit_inst:
                message = _("Changes were successfully saved")
            else:
                message= _("Institution created.")
            messages.success(request, message)
            return redirect(reverse('list_institutions'))
    if request.method == 'GET': 
        form = institutionForm(instance=edit_inst)
    context = {'form': form}
    return render_template(
        request,
        'account_administration/create_institution',
        context
        )