コード例 #1
0
def edit_list(request, list_id, template_name):
    unit = determine_group(request.user.username)
    if unit == "Undefined":
        return render_to_response("common/unauthorized.html", {},
                                  context_instance=RequestContext(request))
    list = Checklist.objects.get(id=list_id)
    if request.method == 'POST':
        formset = ListItemFormset(
            request.POST, queryset=ChecklistItem.objects.filter(listname=list))
        if formset.is_valid():
            instances = formset.save(commit=False)
            for instance in instances:
                try:
                    obj = ChecklistItem.objects.get(id=instance.id)
                    obj.order = instance.order
                    obj.save()
                except:
                    pass
    form = ListItemFormset(queryset=ChecklistItem.objects.filter(
        listname=list))
    items = ChecklistItem.objects.filter(listname=list).order_by("order")
    return render_to_response(template_name, {
        "list": list,
        "items": items,
        "form": form
    },
                              context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: futurice/checklist
def employeeview(request, template_name, employee_id):
    employee = Employee.objects.get(id=employee_id)
    unit = determine_group(request.user.username)
    if employee.ldap_account != request.user.username:
        if unit == "Undefined":
            return render_to_response("common/unauthorized.html", {},
                                      context_instance=RequestContext(request))
    items_yours = ChecklistItem.objects.filter(
        listname=employee.listname.id).filter(unit=unit)
    items_others = ChecklistItem.objects.filter(
        listname=employee.listname.id).exclude(unit=unit)

    employee_items = EmployeeItem.objects.filter(employee=employee)
    employee_dict = {}
    for item in employee_items:
        employee_dict[item.item.id] = item

    form = EmployeeHeader(instance=employee)

    listitems_yours = __combine_lists(employee_dict, items_yours)
    listitems_others = __combine_lists(employee_dict, items_others)
    return render_to_response(template_name, {
        'listitems_yours': listitems_yours,
        'listitems_others': listitems_others,
        'employee': employee,
        'employee_form': form
    },
                              context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: futurice/checklist
def update_employeelist(request, template_name, employee_id, item_id):
    employee = Employee.objects.get(id=employee_id)
    listitem = ChecklistItem.objects.get(id=item_id)
    (employee_item, created) = EmployeeItem.objects.get_or_create(employee=employee, item=listitem, listname=employee.listname)
    unit = determine_group(request.user.username)
    if employee.ldap_account != request.user.username:
        if unit == "Undefined":
            return render_to_response("common/unauthorized.html", {}, context_instance=RequestContext(request))

    if "checkbox" in request.POST.keys():
        if request.POST["checkbox"] == 'on' or request.POST["checkbox"] == 'true' or request.POST["checkbox"] == "checked":
            employee_item.value = True
        else:
            employee_item.value = False
    else:
        employee_item.value = False
    keys = employee_item.value

    if "textbox" in request.POST.keys():
        employee_item.textvalue = request.POST["textbox"]

    employee_item.save()
    keys = {"success": True, "key": listitem.id, "employee_item_id": employee_item.id, "value": employee_item.value}
    keys = json.dumps(keys)
    return render_to_response(template_name, {"keys": keys }, context_instance=RequestContext(request))
コード例 #4
0
def edit_lists(request, template_name):
    unit = determine_group(request.user.username)
    if unit == "Undefined":
        return render_to_response("common/unauthorized.html", {},
                                  context_instance=RequestContext(request))
    lists = Checklist.objects.all()
    return render_to_response(template_name, {"lists": lists},
                              context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: futurice/checklist
def reminderhome(request, template_name):
    ret = {}
    unit = determine_group(request.user.username)
    if unit != "Undefined":
        ret["authorized"] = True
    lists = ReminderList.objects.all()
    ret["lists"] = lists

    return render_to_response(template_name, ret, context_instance=RequestContext(request))
コード例 #6
0
ファイル: views.py プロジェクト: futurice/checklist
def toggle_state_employee(request, action, employee_id):
    unit = determine_group(request.user.username)
    if unit == "Undefined":
        return render_to_response("common/unauthorized.html", {}, context_instance=RequestContext(request))
    employee = get_object_or_404(Employee, pk=employee_id)
    if action == "delete":
        employee.deleted = not employee.deleted
    if action == "archive":
        employee.archived = not employee.archived
    employee.save()
    url = reverse('employeeview', kwargs={'employee_id': employee.id})
    return HttpResponseRedirect(url)
コード例 #7
0
ファイル: views.py プロジェクト: futurice/checklist
def toggle_state_employee(request, action, employee_id):
    unit = determine_group(request.user.username)
    if unit == "Undefined":
        return render_to_response("common/unauthorized.html", {},
                                  context_instance=RequestContext(request))
    employee = get_object_or_404(Employee, pk=employee_id)
    if action == "delete":
        employee.deleted = not employee.deleted
    if action == "archive":
        employee.archived = not employee.archived
    employee.save()
    url = reverse('employeeview', kwargs={'employee_id': employee.id})
    return HttpResponseRedirect(url)
コード例 #8
0
ファイル: views.py プロジェクト: futurice/checklist
def new_employee(request, template_name):
    unit = determine_group(request.user.username)
    if unit == "Undefined":
        return render_to_response("common/unauthorized.html", {}, context_instance=RequestContext(request))
    if request.method == 'POST': # If the form has been submitted...
        form = NewEmployee(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            employee = form.save(commit=False)
            employee.save()
            url = reverse('employeeview', kwargs={'employee_id': employee.id})
            return HttpResponseRedirect(url) # Redirect after POST
    else:
        form = NewEmployee() # An unbound form

    return render_to_response(template_name, {'form': form}, context_instance=RequestContext(request))
コード例 #9
0
ファイル: views.py プロジェクト: futurice/checklist
def update_employeeinfo(request, template_name, employee_id):
    employee = Employee.objects.get(id=employee_id)
    keys = {"success": True, "form": "headerform", "key": "header"}
    unit = determine_group(request.user.username)
    if employee.ldap_account != request.user.username:
        if unit == "Undefined":
            return render_to_response("common/unauthorized.html", {}, context_instance=RequestContext(request))
    if request.method == 'POST':
        formset = EmployeeHeader(request.POST, instance=employee)
        if formset.is_valid():
            formset.save()
        else:
            keys["success"] = False

    keys = json.dumps(keys)
    return render_to_response(template_name, {"keys": keys}, context_instance=RequestContext(request))
コード例 #10
0
ファイル: views.py プロジェクト: futurice/checklist
def new_employee(request, template_name):
    unit = determine_group(request.user.username)
    if unit == "Undefined":
        return render_to_response("common/unauthorized.html", {},
                                  context_instance=RequestContext(request))
    if request.method == 'POST':  # If the form has been submitted...
        form = NewEmployee(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            employee = form.save(commit=False)
            employee.save()
            url = reverse('employeeview', kwargs={'employee_id': employee.id})
            return HttpResponseRedirect(url)  # Redirect after POST
    else:
        form = NewEmployee()  # An unbound form

    return render_to_response(template_name, {'form': form},
                              context_instance=RequestContext(request))
コード例 #11
0
ファイル: views.py プロジェクト: futurice/checklist
def update_employeeinfo(request, template_name, employee_id):
    employee = Employee.objects.get(id=employee_id)
    keys = {"success": True, "form": "headerform", "key": "header"}
    unit = determine_group(request.user.username)
    if employee.ldap_account != request.user.username:
        if unit == "Undefined":
            return render_to_response("common/unauthorized.html", {},
                                      context_instance=RequestContext(request))
    if request.method == 'POST':
        formset = EmployeeHeader(request.POST, instance=employee)
        if formset.is_valid():
            formset.save()
        else:
            keys["success"] = False

    keys = json.dumps(keys)
    return render_to_response(template_name, {"keys": keys},
                              context_instance=RequestContext(request))
コード例 #12
0
ファイル: views.py プロジェクト: futurice/checklist
def employeeview(request, template_name, employee_id):
    employee = Employee.objects.get(id=employee_id)
    unit = determine_group(request.user.username)
    if employee.ldap_account != request.user.username:
        if unit == "Undefined":
            return render_to_response("common/unauthorized.html", {}, context_instance=RequestContext(request))
    items_yours = ChecklistItem.objects.filter(listname=employee.listname.id).filter(unit=unit)
    items_others = ChecklistItem.objects.filter(listname=employee.listname.id).exclude(unit=unit)

    employee_items = EmployeeItem.objects.filter(employee=employee)
    employee_dict = {}
    for item in employee_items:
        employee_dict[item.item.id] = item

    form = EmployeeHeader(instance=employee)

    listitems_yours = __combine_lists(employee_dict, items_yours)
    listitems_others = __combine_lists(employee_dict, items_others)
    return render_to_response(template_name, {'listitems_yours': listitems_yours, 'listitems_others': listitems_others, 'employee': employee, 'employee_form': form }, context_instance=RequestContext(request))
コード例 #13
0
ファイル: views.py プロジェクト: futurice/checklist
def employeelist(request, template_name, list_id, without_item_id=None):
    unit = determine_group(request.user.username)
    if unit == "Undefined":
        return render_to_response("common/unauthorized.html", {},
                                  context_instance=RequestContext(request))
    chklist = Checklist.objects.get(id=list_id)
    all_employees = Employee.objects.filter(listname=list_id, deleted=False)

    # exclude employees who have this item ticked
    without_item = None
    if without_item_id is not None:
        without_item = ChecklistItem.objects.get(id=without_item_id)
        empl_id_with_item = all_employees.filter(
            employeeitem__item_id=without_item_id,
            employeeitem__value=True).values('id')
        all_employees = all_employees.exclude(id__in=empl_id_with_item)

    employees_unarchived = all_employees.filter(archived=False)
    employees_archived = all_employees.filter(archived=True)

    for employee in itertools.chain(employees_unarchived, employees_archived):
        fill_employee_extra(employee, request.user.username, unit)
        try:
            employee.textvalue = EmployeeItem.objects.get(
                employee_id=employee.id,
                item=without_item,
                listname=employee.listname).textvalue
        except EmployeeItem.DoesNotExist:
            pass

    return render_to_response(template_name, {
        'chklist':
        chklist,
        'employees':
        employees_unarchived,
        'archived':
        employees_archived,
        'without_item':
        without_item,
        'without_item_url':
        reverse('employeelist', kwargs={'list_id': chklist.id}),
    },
                              context_instance=RequestContext(request))
コード例 #14
0
ファイル: views.py プロジェクト: futurice/checklist
def indexview(request):
    ret = {}
    unit = determine_group(request.user.username)
    if unit != "Undefined":
        ret["authorized"] = True
    lists = Checklist.objects.all()
    my_items = Employee.objects.filter(ldap_account=request.user.username).order_by("start_date")
    ret["my_items"] = my_items
    ret["lists"] = lists

    all_employees = Employee.objects.filter(deleted=False)
    employees_unarchived = all_employees.filter(archived=False)
    employees_archived = all_employees.filter(archived=True)
    for employee in itertools.chain(employees_unarchived, employees_archived):
        fill_employee_extra(employee, request.user.username, unit)
    ret['employees'] = employees_unarchived
    ret['archived'] = employees_archived

    return render(request, 'index.html', ret)
コード例 #15
0
ファイル: views.py プロジェクト: futurice/checklist
def indexview(request):
    ret = {}
    unit = determine_group(request.user.username)
    if unit != "Undefined":
        ret["authorized"] = True
    lists = Checklist.objects.all()
    my_items = Employee.objects.filter(
        ldap_account=request.user.username).order_by("start_date")
    ret["my_items"] = my_items
    ret["lists"] = lists

    all_employees = Employee.objects.filter(deleted=False)
    employees_unarchived = all_employees.filter(archived=False)
    employees_archived = all_employees.filter(archived=True)
    for employee in itertools.chain(employees_unarchived, employees_archived):
        fill_employee_extra(employee, request.user.username, unit)
    ret['employees'] = employees_unarchived
    ret['archived'] = employees_archived

    return render(request, 'index.html', ret)
コード例 #16
0
ファイル: views.py プロジェクト: futurice/checklist
def employeelist(request, template_name, list_id, without_item_id=None):
    unit = determine_group(request.user.username)
    if unit == "Undefined":
        return render_to_response("common/unauthorized.html", {}, context_instance=RequestContext(request))
    chklist = Checklist.objects.get(id=list_id)
    all_employees = Employee.objects.filter(listname=list_id, deleted=False)

    # exclude employees who have this item ticked
    without_item = None
    if without_item_id is not None:
        without_item = ChecklistItem.objects.get(id=without_item_id)
        empl_id_with_item = all_employees.filter(
                employeeitem__item_id=without_item_id,
                employeeitem__value=True).values('id')
        all_employees = all_employees.exclude(id__in=empl_id_with_item)

    employees_unarchived = all_employees.filter(archived=False)
    employees_archived = all_employees.filter(archived=True)

    for employee in itertools.chain(employees_unarchived, employees_archived):
        fill_employee_extra(employee, request.user.username, unit)
        try:
            employee.textvalue = EmployeeItem.objects.get(
                    employee_id=employee.id, item=without_item,
                    listname=employee.listname).textvalue
        except EmployeeItem.DoesNotExist:
            pass

    return render_to_response(template_name, {
        'chklist': chklist,
        'employees': employees_unarchived,
        'archived': employees_archived,
        'without_item': without_item,
        'without_item_url': reverse('employeelist',
            kwargs={'list_id': chklist.id}),
    }, context_instance=RequestContext(request))
コード例 #17
0
ファイル: views.py プロジェクト: futurice/checklist
def update_employeelist(request, template_name, employee_id, item_id):
    employee = Employee.objects.get(id=employee_id)
    listitem = ChecklistItem.objects.get(id=item_id)
    (employee_item,
     created) = EmployeeItem.objects.get_or_create(employee=employee,
                                                   item=listitem,
                                                   listname=employee.listname)
    unit = determine_group(request.user.username)
    if employee.ldap_account != request.user.username:
        if unit == "Undefined":
            return render_to_response("common/unauthorized.html", {},
                                      context_instance=RequestContext(request))

    if "checkbox" in request.POST.keys():
        if request.POST["checkbox"] == 'on' or request.POST[
                "checkbox"] == 'true' or request.POST["checkbox"] == "checked":
            employee_item.value = True
        else:
            employee_item.value = False
    else:
        employee_item.value = False
    keys = employee_item.value

    if "textbox" in request.POST.keys():
        employee_item.textvalue = request.POST["textbox"]

    employee_item.save()
    keys = {
        "success": True,
        "key": listitem.id,
        "employee_item_id": employee_item.id,
        "value": employee_item.value
    }
    keys = json.dumps(keys)
    return render_to_response(template_name, {"keys": keys},
                              context_instance=RequestContext(request))
コード例 #18
0
def edit_list_item(request, action, item_id, list_id, template_name):
    unit = determine_group(request.user.username)
    if unit == "Undefined":
        return render_to_response("common/unauthorized.html", {},
                                  context_instance=RequestContext(request))
    list = Checklist.objects.get(id=list_id)
    if request.method == 'POST':
        if request.GET.get("action") == "delete":
            form = DeleteForm(request.POST)
            if form.is_valid():
                ChecklistItem.objects.get(id=item_id).delete()
                url = reverse("edit_list", kwargs={'list_id': list_id})
                return HttpResponseRedirect(url)
            else:
                return HttpResponse404()
        try:
            if action == 'pair':
                instance = ChecklistItem.objects.get(item_pair=item_id)
            else:
                instance = ChecklistItem.objects.get(id=item_id)
            form = ListItemForm(request.POST, instance=instance)
        except ObjectDoesNotExist:
            form = ListItemForm(request.POST)
        if form.is_valid():
            item = form.save(commit=False)
            item.listname = list
            if action == 'new':
                try:
                    largest_order = ChecklistItem.objects.filter(
                        listname=list).order_by("-order")[0].order
                    item.order = largest_order + 1
                except:
                    largest_order = 0
                item.save()
                url = reverse("edit_list_item",
                              kwargs={
                                  'list_id': list_id,
                                  'item_id': item.id,
                              })
                return HttpResponseRedirect(url)
            item.save()

    else:
        if action == 'new':
            form = ListItemForm(initial={"listname": list_id, "order": 0})
        elif action == 'pair':
            try:
                instance = ChecklistItem.objects.get(item_pair=item_id)
            except ObjectDoesNotExist:
                instance = ChecklistItem(
                    itemname='Item name',
                    unit='Unit name',
                    order=20,
                    listname=Checklist.objects.get(id=2),
                    item_pair=ChecklistItem.objects.get(id=item_id))
            form = ListItemForm(instance=instance)
        else:  # action = edit
            instance = ChecklistItem.objects.get(id=item_id)
            form = ListItemForm(instance=instance)

    return render_to_response(template_name, {
        'form': form,
        "list_id": list.id
    },
                              context_instance=RequestContext(request))