Ejemplo n.º 1
0
def create_department_file(data_form, import_errors_create, department_create):

    form_department = DepartmentEditForm(data=data_form)

    if form_department.is_valid():
        department = DepartmentService.reconstruct_and_save(form_department)
        department_create.append(department)
    else:
        name = form_department.data["name"]
        code = form_department.data["code"]
        import_errors_create.append(name + " (" + code + ")")
Ejemplo n.º 2
0
def create_department_file(data_form, import_errors_create, department_create):

    form_department = DepartmentEditForm(data=data_form)

    if form_department.is_valid():
        department = DepartmentService.reconstruct_and_save(form_department)
        department_create.append(department)
    else:
        name = form_department.data['name']
        code = form_department.data['code']
        import_errors_create.append(name + " (" + code + ")")
Ejemplo n.º 3
0
def edit_department(request, department_id):

    data_form = {}
    data_template = {}

    if request.POST:
        form = DepartmentEditForm(request.POST)

        try:

            if department_id:
                assert department_id == form.cleaned_data['id']

        except AssertionError:
            messages.error(request, _("Action failed, try again!"))
            return HttpResponseRedirect('/admin/department/lis')

        if form.is_valid():
            department = DepartmentService.reconstruct_and_save(form)
            messages.success(request, _("Action completed successfully"))
            redirect = '/admin/department/details/' + str(department.id)
            return HttpResponseRedirect(redirect)
    else:

        if department_id:
            department = DepartmentService.find_one(department_id)
            data_form = DepartmentService.get_form_data(department)

        form = DepartmentEditForm(initial=data_form)

    if department_id:
        data_template['create'] = False
        data_template['cancel'] = '/admin/department/details/' + str(
            department_id)
    else:
        data_template['create'] = True

    data_template['form'] = form
    data_template['action'] = '/admin/department/edit/'
    template_name = 'department/edit.html'
    return render_to_response(template_name,
                              data_template,
                              context_instance=RequestContext(request))
Ejemplo n.º 4
0
def edit_department(request, department_id):

    data_form = {}
    data_template = {}

    if request.POST:
        form = DepartmentEditForm(request.POST)

        try:

            if department_id:
                assert department_id == form.cleaned_data["id"]

        except AssertionError:
            messages.error(request, _("Action failed, try again!"))
            return HttpResponseRedirect("/admin/department/lis")

        if form.is_valid():
            department = DepartmentService.reconstruct_and_save(form)
            messages.success(request, _("Action completed successfully"))
            redirect = "/admin/department/details/" + str(department.id)
            return HttpResponseRedirect(redirect)
    else:

        if department_id:
            department = DepartmentService.find_one(department_id)
            data_form = DepartmentService.get_form_data(department)

        form = DepartmentEditForm(initial=data_form)

    if department_id:
        data_template["create"] = False
        data_template["cancel"] = "/admin/department/details/" + str(department_id)
    else:
        data_template["create"] = True

    data_template["form"] = form
    data_template["action"] = "/admin/department/edit/"
    template_name = "department/edit.html"
    return render_to_response(template_name, data_template, context_instance=RequestContext(request))