Example #1
0
def table_view(request: WSGIRequest):
    empl = employee.Employee.find(request.user.get_username())
    context = {**base_view.get_user_context(request)}
    if not employee.Permission.can_view_employee_list(empl):
        return redirect(index.no_permission)
    else:
        employees = model.collect_employees()
        for empl in employees:
            empl.floatTime = round(model.calculate_float_time(empl.emplNr), 2)
            if empl.roles:
                empl.roles_joined = ", ".join(
                    [r.description for r in empl.roles])
            else:
                empl.roles_joined = "-"
        context.update({
            **base_view.get_user_context(request),
            "employees": employees,
            "updown_arrow_nr": "",
            "updown_arrow_firstname": "",
            "updown_arrow_lastname": "",
            "updown_arrow_ftime": "",
            "updown_nr": "asc",
            "updown_firstname": "asc",
            "updown_lastname": "asc",
            "updown_ftime": "asc",
        })
        sort_employee_list(context, request)

    return render(request, "employee_list.html", context=context)
Example #2
0
def detail_view(project_nr, request):
    pro = project.Project.find(project_nr)
    user_empl = employee.Employee.find(request.user.get_username())
    context = base_view.get_user_context(request)
    if employee.Permission.can_view_project_details(user_empl):
        context.update({**base_view.get_user_context(request),
                        "nr": pro.nr,
                        "name": pro.name,
                        "hours": round(model.calculate_hours_for_project(pro.nr), 2),
                        "contributors": [e.firstName + " " + e.lastName for e in
                                         model.get_contributors_for_project(pro.nr)]
                        })
    else:
        return redirect(index.no_permission)
    return render(request, "project.html", context=context)
Example #3
0
def new_absence(request: WSGIRequest):
    today = datetime.date.today().isoformat()
    empl_nr = int(request.GET.get("empl_nr", "0"))
    empl = employee.Employee.find(empl_nr)
    user_empl = employee.Employee.find(request.user.get_username())
    if employee.Permission.can_add_absence(
            empl) or empl.emplNr == user_empl.emplNr:
        context = {
            **base_view.get_user_context(request),
            "default_empl_nr": empl_nr,
            "default_start": today,
            "default_end": today,
        }
        if request.POST:
            try:
                model.add_absence(request.POST)
            except ValueError as e:
                msg = "Fehler: " + " ".join(e.args)
                good_news = False
            else:
                msg = "Die Absenz wurde erfolgreich gespeichert."
                good_news = True
            context.update(base_view.get_message_context(msg, good_news))
        return render(request, "new_absence.html", context)
    else:
        return redirect(index.no_permission)
Example #4
0
def admin(request: WSGIRequest):
    con = {
        **base_view.get_user_context(request),
        "git_log": model_admin.get_git_log(),
        "import_options": importexport.get_all_exported_folders(),
    }
    return render(request, "admin.html", context=con)
Example #5
0
def table_view(request: WSGIRequest):
    user_empl = employee.Employee.find(request.user.get_username())
    context = {**base_view.get_user_context(request)}
    if not employee.Permission.can_view_project_list(user_empl):
        return redirect(index.no_permission)
    else:
        projects = model.collect_projects()
        for pro in projects:
            pro.hours = round(model.calculate_hours_for_project(pro.nr), 2)
        context.update({
            **base_view.get_user_context(request),
            "projects": projects,
            "updown_arrow_nr": "",
            "updown_arrow_name": "",
            "updown_arrow_hours": "",
            "updown_nr": "asc",
            "updown_name": "asc",
            "updown_hours": "asc",
        })
        sort_projects_list(context, request)

    return render(request, "project_list.html", context=context)
Example #6
0
def detail_view(empl_nr, request):
    empl = employee.Employee.find(empl_nr)
    user_empl = employee.Employee.find(request.user.get_username())
    context = base_view.get_user_context(request)
    if employee.Permission.can_view_employee_details(
            user_empl) or empl.emplNr == user_empl.emplNr:
        absences_list = model.collect_absences(empl_nr, sort=True)
        absences = []
        for ab in absences_list:
            absences.append({
                "start": util.locale_format(ab.start),
                "end": util.locale_format(ab.end),
                "reason": ab.reason,
                "length": ab.length,
            })
        context.update({
            **base_view.get_user_context(request),
            "firstName":
            empl.firstName,
            "lastName":
            empl.lastName,
            "empl_nr":
            empl.emplNr,
            "float_time_total":
            round(model.calculate_float_time(empl_nr), 2),
            "active_since":
            util.locale_format(empl.since),
            "active_until":
            util.locale_format(empl.until) if empl.until else "",
            "absence_total":
            model.count_absent_days(empl_nr),
            "absences":
            absences,
        })
    else:
        return redirect(index.no_permission)
    return render(request, "employee.html", context=context)
Example #7
0
def index(request: WSGIRequest, messages: List[str] = None):
    if messages is None:
        messages = []
    if not request.user.is_authenticated:
        return redirect(login.login)
    empl_nr = int(request.user.get_username())
    save_msgs = model.save_changes(empl_nr, request.GET)
    if save_msgs:
        messages.extend(save_msgs)
    context = {
        **base_view.get_user_context(request),
        **base_view.get_message_context(messages),
        **generate_entries_context(request.user.get_username(), request.GET),
        "project_names":
        mark_safe(model.get_all_projects_as_json()),
    }
    return render(request, "index.html", context)
Example #8
0
def view(request: WSGIRequest):
    se = [{
        "id": Setting.SOLL_WORK_PER_DAY,
        "displayName": "Sollstunden pro Tag",
        "value": Setting.find_float_value(Setting.SOLL_WORK_PER_DAY),
        "type": "number",
    }, {
        "id": Setting.MAX_WORK_PER_DAY,
        "displayName": "Maximale Arbeitsstunden pro Tag",
        "value": Setting.find_float_value(Setting.MAX_WORK_PER_DAY),
        "type": "number",
    }]
    context = {
        **base_view.get_user_context(request),
        "all_settings": se,
    }
    return render(request, "configuration.html", context=context)
Example #9
0
 def view(cls, request: WSGIRequest) -> HttpResponse:
     if not request.user.is_authenticated:
         return redirect(login.login)
     user_empl = employee.Employee.find(request.user.get_username())
     if not employee.Permission.can_view_graphs(user_empl):
         return redirect(index.no_permission)
     self = cls()
     for key in self.get_argument_keys():
         if key not in request.GET.keys():
             return cls.ask_for_arguments(request)
     self.generate(request.GET)
     graph_html = self.save()
     graph_html = graph_html.replace(
         "https://cdn.pydata.org/bokeh/release/bokeh-1.4.0.min.js",
         "/static/js/bokeh-1.4.0.min.js")
     con = {
         **base_view.get_user_context(request), "graph_title":
         self.get_title(),
         "graph_html": mark_safe(graph_html)
     }
     return render(request, "graph.html", context=con)
Example #10
0
def no_permission(request: WSGIRequest) -> HttpResponse:
    return render(request, "no_permission.html",
                  base_view.get_user_context(request))
Example #11
0
 def ask_for_arguments(cls, request: WSGIRequest) -> HttpResponse:
     con = {
         **base_view.get_user_context(request),
         "keys": cls.get_argument_keys(),
     }
     return render(request, "ask_graph_params.html", context=con)
Example #12
0
def view(request: WSGIRequest) -> HttpResponse:
    con = {
        **base_view.get_user_context(request),
        "graphs": [{"name": it.name, "url": "graph/" + it.url} for it in MENU_ITEMS]
    }
    return render(request, "graph_list.html", con)