Example #1
0
def item2_form(request, pk):
    app_param = get_app_params(request.user, app_name)
    if (app_param.restriction == EMPL_INFO):
        set_article_kind(request.user, app_name, '', pk)
    if (app_param.restriction == DEP_HIST):
        set_article_kind(request.user, app_name, '', pk)
        set_restriction(request.user, app_name, DEP_INFO)
    return HttpResponseRedirect(
        reverse('v2_wage:main') + extract_get_params(request))
Example #2
0
def goto(request):  # Опуститься в указанную папку
    set_article_visible(request.user, app_name, False)
    app_param = get_app_params(request.user, app_name)
    prefix = ''
    if app_param.content:
        prefix = app_param.content + '/'
    query = get_name_from_request(request)
    if query:
        set_content(request.user, app_name, prefix + query)
    return HttpResponseRedirect(
        reverse('v2_photo:main') + extract_get_params(request))
Example #3
0
def item_form(request, pk):
    app_param = get_app_params(request.user, app_name)
    if (app_param.restriction == EMPL_LIST):
        set_restriction(request.user, app_name, EMPL_INFO)
        item = Employee.objects.filter(id=pk).get()
        item.set_active()
        set_article_kind(request.user, app_name, '', item.id)
    elif (app_param.restriction == DEP_LIST):
        set_restriction(request.user, app_name, DEP_HIST)
        item = Depart.objects.filter(id=pk).get()
        item.set_active()
        set_article_kind(request.user, app_name, '', item.id)
    elif (app_param.restriction == DEP_INFO):
        set_restriction(request.user, app_name, DEP_HIST)
        set_article_kind(request.user, app_name, '', pk)
    else:
        set_article_kind(request.user, app_name, '', pk)
    return HttpResponseRedirect(
        reverse('v2_wage:main') + extract_get_params(request))
Example #4
0
def rise(request, level):  # Подняться на указанный уровень вверх
    set_article_visible(request.user, app_name, False)
    if not level:
        set_content(request.user, app_name, '')
    else:
        app_param = get_app_params(request.user, app_name)
        crumbs = app_param.content.split('/')
        new_rest = ''
        cur_level = 1
        for crumb in crumbs:
            new_rest += crumb
            if (cur_level < level):
                new_rest += '/'
                cur_level += 1
            else:
                break
        set_content(request.user, app_name, new_rest)

    return HttpResponseRedirect(
        reverse('v2_photo:main') + extract_get_params(request))
Example #5
0
def do_main(request, restriction, pk=None, art_vis=False):

    if process_common_commands(request, app_name):
        return HttpResponseRedirect(
            reverse('v2_photo:' + restriction) + extract_get_params(request))

    set_restriction(request.user, app_name, restriction)

    item = None
    name = ''
    if (restriction == 'one') and pk:
        item = get_object_or_404(
            Photo.objects.filter(id=pk, user=request.user.id))
        name = item.name

    app_param, context = get_base_context_ext(request, app_name, restriction,
                                              get_title(restriction, name))

    if (restriction == 'one') and (not item):
        item = get_object_or_404(
            Photo.objects.filter(id=app_param.art_id, user=request.user.id))

    redirect_rest = ''

    if (restriction == 'one'):
        valid_article = Photo.objects.filter(id=app_param.art_id,
                                             user=request.user.id).exists()
        if not valid_article:
            set_article_visible(request.user, app_name, False)
            return HttpResponseRedirect(
                reverse('v2_photo:main') + extract_get_params(request))
        else:
            item = get_object_or_404(
                Photo.objects.filter(id=app_param.art_id,
                                     user=request.user.id))
            context['item'] = item
            context['title'] = item.name
            if app_param.article:
                disable_delete = (app_param.content == 'Trash')
                redirect_rest = edit_item(request, context, item,
                                          disable_delete)

    if redirect_rest:
        return HttpResponseRedirect(
            reverse('v2_photo:' + redirect_rest) + extract_get_params(request))

    file_form = None

    if (request.method == 'POST'):
        if ('file_upload' in request.POST):
            file_form = FileForm(request.POST, request.FILES)
            if file_form.is_valid():
                handle_uploaded_file(request.FILES['upload'], request.user,
                                     app_param.content)
                return HttpResponseRedirect(
                    reverse('v2_photo:' + restriction) +
                    extract_get_params(request))

    if not file_form:
        file_form = FileForm()

    context['file_form'] = file_form

    query = None
    page_number = 1
    if (request.method == 'GET'):
        query = request.GET.get('q')
        page_number = request.GET.get('page')
    context['search_info'] = get_search_info(query)
    context['hide_add_item_input'] = True
    context['without_lists'] = True

    data, gps_data = filtered_sorted_list(request.user, app_param, query)
    context['search_qty'] = len(data)
    context['search_data'] = query and (len(data) > 0)
    context['gps_data'] = gps_data

    fixes = []
    fixes.append(
        Fix('main',
            _('thumbnails').capitalize(), 'v2/rok/icon/all.png', '/v2_photo/',
            len(data)))
    fixes.append(
        Fix('map',
            _('on the map').capitalize(), 'v2/todo/icon/map.png',
            '/v2_photo/map/', len(gps_data)))
    context['fix_list'] = fixes

    bread_crumbs = []
    crumbs = app_param.content.split('/')
    if ((len(crumbs) > 0) and crumbs[0]) or (restriction == 'one'):
        bread_crumbs.append({
            'url': '/v2_photo/rise/0/',
            'name': '[{}]'.format(_('photobank').capitalize())
        })

    level = 1
    for crumb in crumbs:
        if not crumb:
            continue
        if (level == len(crumbs)) and (restriction != 'one'):
            context['title'] = crumb
        else:
            url = '/v2_photo/rise/{}/'.format(level)
            bread_crumbs.append({'url': url, 'name': crumb})
        level += 1
    context['bread_crumbs'] = bread_crumbs

    paginator = Paginator(data, items_per_page)
    page_obj = paginator.get_page(page_number)
    context['page_obj'] = paginator.get_page(page_number)

    template_name = 'v2_photo/' + restriction + '.html'
    template = loader.get_template(template_name)
    return HttpResponse(template.render(context, request))
Example #6
0
def set_restriction_and_redirect(request, restriction, save_context=False):
    add = ''
    if save_context:
        add = extract_get_params(request)
    set_restriction(request.user, app_name, restriction)
    return HttpResponseRedirect(reverse('v2_wage:main') + add)
Example #7
0
def main(request):
    app_param = get_app_params(request.user, app_name)
    if (app_param.restriction not in ALL_RESTRICTIONS):
        return set_restriction_and_redirect(request, PER)

    if not Period.objects.filter(user=request.user.id, active=True).exists():
        if (app_param.restriction != PER):
            return set_restriction_and_redirect(request, PER)

    period = None
    if Period.objects.filter(user=request.user.id, active=True).exists():
        period = Period.objects.filter(user=request.user.id, active=True).get()

    if (app_param.restriction in EMPL_ASIDE):
        if not Employee.objects.filter(user=request.user.id,
                                       active=True).exists():
            return set_restriction_and_redirect(request, EMPL_LIST)

    employee = None
    if Employee.objects.filter(user=request.user.id, active=True).exists():
        employee = Employee.objects.filter(user=request.user.id,
                                           active=True).get()

    if (app_param.restriction == DEP_HIST):
        if not Depart.objects.filter(user=request.user.id,
                                     active=True).exists():
            return set_restriction_and_redirect(request, DEP_LIST)

    depart = None
    if Depart.objects.filter(user=request.user.id, active=True).exists():
        depart = Depart.objects.filter(user=request.user.id, active=True).get()

    if process_common_commands(request, app_name):
        return HttpResponseRedirect(
            reverse('v2_wage:main') + extract_get_params(request))

    # For converting the string representation of dates, in particular in item_info
    locale.setlocale(locale.LC_CTYPE, request.LANGUAGE_CODE)
    locale.setlocale(locale.LC_TIME, request.LANGUAGE_CODE)

    if (request.method == 'POST'):
        if ('item-add' in request.POST):
            if (app_param.restriction == PER):
                item_id = add_period(request)
            if (app_param.restriction == POST):
                item_id = add_post(request)
            if (app_param.restriction == TITLE):
                item_id = add_pay_title(request)
            if (app_param.restriction == DEP_LIST):
                item_id = add_department(request)
            if (app_param.restriction in (DEP_HIST, DEP_INFO)):
                item_id = add_dep_hist(request, depart)
            if (app_param.restriction == EMPL_LIST):
                item_id = add_employee(request)
            if (app_param.restriction == ACC):
                item_id = add_payment(request, period, employee, 0)
            if (app_param.restriction == PAY):
                item_id = add_payment(request, period, employee, 1)
            if (app_param.restriction == APP):
                item_id = add_appoint(request, period, employee)
            if (app_param.restriction == EDUC):
                item_id = add_education(request, period, employee)
            if (app_param.restriction == CHLD):
                item_id = add_child(request, period, employee)
            if (app_param.restriction == SUR):
                item_id = add_surname(request, period, employee)
            return HttpResponseRedirect(
                reverse('v2_wage:item_form', args=[item_id]))
        if ('item-in-list-select' in request.POST) and (app_param.restriction
                                                        == PER):
            pk = request.POST['item-in-list-select']
            if pk:
                set_active(request.user.id, pk)
                return HttpResponseRedirect(
                    reverse('v2_wage:item_form', args=[pk]) +
                    extract_get_params(request))

    app_param, context = get_base_context_ext(
        request, app_name, 'main',
        get_title(app_param.restriction, employee, depart))

    redirect = False

    if app_param.article:
        valid_article = False
        if (app_param.restriction == PER):
            valid_article = Period.objects.filter(
                id=app_param.art_id, user=request.user.id).exists()
        if (app_param.restriction == POST):
            valid_article = Post.objects.filter(id=app_param.art_id,
                                                user=request.user.id).exists()
        if (app_param.restriction == TITLE):
            valid_article = PayTitle.objects.filter(
                id=app_param.art_id, user=request.user.id).exists()
        if (app_param.restriction == DEP_HIST):
            valid_article = DepHist.objects.filter(id=app_param.art_id,
                                                   depart=depart.id).exists()
        if (app_param.restriction == DEP_INFO):
            valid_article = Depart.objects.filter(
                id=app_param.art_id, user=request.user.id).exists()
        if (app_param.restriction == EMPL_INFO):
            valid_article = Employee.objects.filter(
                id=app_param.art_id, user=request.user.id).exists()
        if (app_param.restriction == ACC):
            valid_article = Payment.objects.filter(id=app_param.art_id,
                                                   employee=employee.id,
                                                   period=period.id,
                                                   direct=0).exists()
        if (app_param.restriction == PAY):
            valid_article = Payment.objects.filter(id=app_param.art_id,
                                                   employee=employee.id,
                                                   period=period.id,
                                                   direct=1).exists()
        if (app_param.restriction == APP):
            valid_article = Appoint.objects.filter(
                id=app_param.art_id, employee=employee.id).exists()
        if (app_param.restriction == EDUC):
            valid_article = Education.objects.filter(
                id=app_param.art_id, employee=employee.id).exists()
        if (app_param.restriction == CHLD):
            valid_article = Child.objects.filter(
                id=app_param.art_id, employee=employee.id).exists()
        if (app_param.restriction == SUR):
            valid_article = FioHist.objects.filter(
                id=app_param.art_id, employee=employee.id).exists()
        if (app_param.restriction == REPORT):
            valid_article = True

        if valid_article:
            if (app_param.restriction == PER):
                item = get_object_or_404(
                    Period.objects.filter(id=app_param.art_id,
                                          user=request.user.id))
                disable_delete = item.active or EmplPer.objects.filter(period = item.id).exists() or \
                                                Payment.objects.filter(period = item.id).exists()
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item,
                                     disable_delete)
            if (app_param.restriction == POST):
                item = get_object_or_404(
                    Post.objects.filter(id=app_param.art_id,
                                        user=request.user.id))
                disable_delete = Appoint.objects.filter(post=item.id).exists()
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item,
                                     disable_delete)
            if (app_param.restriction == TITLE):
                item = get_object_or_404(
                    PayTitle.objects.filter(id=app_param.art_id,
                                            user=request.user.id))
                disable_delete = Payment.objects.filter(title=item.id).exists()
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item,
                                     disable_delete)
            if (app_param.restriction == DEP_HIST):
                item = get_object_or_404(
                    DepHist.objects.filter(id=app_param.art_id,
                                           depart=depart.id))
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item, False)
            if (app_param.restriction == DEP_INFO):
                item = get_object_or_404(
                    Depart.objects.filter(id=app_param.art_id,
                                          user=request.user.id))
                disable_delete = DepHist.objects.filter(depart = item.id).exists() or \
                                 DepHist.objects.filter(node = item.id).exists() or \
                                 Appoint.objects.filter(depart = item.id).exists()
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item,
                                     disable_delete)
            if (app_param.restriction == EMPL_INFO):
                item = get_object_or_404(
                    Employee.objects.filter(id=app_param.art_id,
                                            user=request.user.id))
                disable_delete = FioHist.objects.filter(employee = item.id).exists() or \
                                 Child.objects.filter(employee = item.id).exists() or \
                                 Appoint.objects.filter(employee = item.id).exists() or \
                                 Education.objects.filter(employee = item.id).exists() or \
                                 Payment.objects.filter(employee = item.id).exists()
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item,
                                     disable_delete)
            if (app_param.restriction == ACC):
                item = get_object_or_404(
                    Payment.objects.filter(id=app_param.art_id,
                                           employee=employee.id,
                                           period=period.id,
                                           direct=0))
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item, False)
            if (app_param.restriction == PAY):
                item = get_object_or_404(
                    Payment.objects.filter(id=app_param.art_id,
                                           employee=employee.id,
                                           period=period.id,
                                           direct=1))
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item, False)
            if (app_param.restriction == APP):
                item = get_object_or_404(
                    Appoint.objects.filter(id=app_param.art_id,
                                           employee=employee.id))
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item, False)
            if (app_param.restriction == EDUC):
                item = get_object_or_404(
                    Education.objects.filter(id=app_param.art_id,
                                             employee=employee.id))
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item, False)
            if (app_param.restriction == CHLD):
                item = get_object_or_404(
                    Child.objects.filter(id=app_param.art_id,
                                         employee=employee.id))
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item, False)
            if (app_param.restriction == SUR):
                item = get_object_or_404(
                    FioHist.objects.filter(id=app_param.art_id,
                                           employee=employee.id))
                redirect = edit_item(request, context, app_param.restriction,
                                     period, employee, depart, item, False)
        else:
            set_article_visible(request.user, app_name, False)
            redirect = True

    if (request.method == 'POST'):
        if ('total-save' in request.POST):
            total_save(request, context, period, employee)
    else:
        check_empl_per(request.user, context, app_param, period, employee)

    if redirect:
        return HttpResponseRedirect(
            reverse('v2_wage:main') + extract_get_params(request))

    fixes = []
    if (app_param.restriction in EMPL_ASIDE):
        fixes.append(
            Fix(PER,
                _('periods').capitalize(), 'v2/todo/icon/planned.png',
                'periods/', len(Period.objects.filter(user=request.user.id))))
        fixes.append(
            Fix(EMPL_LIST,
                _('employees').capitalize(),
                'v2/rok/icon/user.png', 'employees/',
                len(Employee.objects.filter(user=request.user.id))))
        fixes.append(
            Fix(EMPL_INFO,
                _('totals').capitalize(), 'v2/todo/icon/myday.png', 'total/',
                None))
        fixes.append(
            Fix(
                ACC,
                _('accruals').capitalize(), 'v2/todo/icon/myday.png',
                'accrual/',
                len(
                    Payment.objects.filter(employee=employee.id,
                                           period=period.id,
                                           direct=0))))
        fixes.append(
            Fix(
                PAY,
                _('pays').capitalize(), 'v2/todo/icon/myday.png', 'payment/',
                len(
                    Payment.objects.filter(employee=employee.id,
                                           period=period.id,
                                           direct=1))))
        fixes.append(
            Fix(APP,
                _('appointments').capitalize(), 'v2/todo/icon/myday.png',
                'appoint/', len(Appoint.objects.filter(employee=employee.id))))
        fixes.append(
            Fix(EDUC,
                _('educations').capitalize(), 'v2/todo/icon/myday.png',
                'education/',
                len(Education.objects.filter(employee=employee.id))))
        fixes.append(
            Fix(SUR,
                _('surnames').capitalize(), 'v2/todo/icon/myday.png',
                'surname/', len(FioHist.objects.filter(employee=employee.id))))
        fixes.append(
            Fix(CHLD,
                _('children').capitalize(), 'v2/todo/icon/myday.png', 'child/',
                len(Child.objects.filter(employee=employee.id))))
    elif (app_param.restriction in (DEP_HIST, DEP_INFO)):
        fixes.append(
            Fix(DEP_LIST,
                _('departments').capitalize(),
                'v2/rok/icon/home.png', 'departments/',
                len(Depart.objects.filter(user=request.user.id))))
        fixes.append(
            Fix(DEP_HIST,
                _('department history').capitalize(), 'v2/rok/icon/home.png',
                'dep_hist/', len(DepHist.objects.filter(depart=depart.id))))
    else:
        fixes.append(
            Fix(PER,
                _('periods').capitalize(), 'v2/todo/icon/planned.png',
                'periods/', len(Period.objects.filter(user=request.user.id))))
        fixes.append(
            Fix(EMPL_LIST,
                _('employees').capitalize(),
                'v2/rok/icon/user.png', 'employees/',
                len(Employee.objects.filter(user=request.user.id))))
        fixes.append(
            Fix(DEP_LIST,
                _('departments').capitalize(),
                'v2/rok/icon/home.png', 'departments/',
                len(Depart.objects.filter(user=request.user.id))))
        fixes.append(
            Fix(POST,
                _('posts').capitalize(), 'v2/rok/icon/work.png', 'posts/',
                len(Post.objects.filter(user=request.user.id))))
        fixes.append(
            Fix(TITLE,
                _('pay titles').capitalize(), 'v2/rok/icon/edit.png',
                'pay_titles/',
                len(PayTitle.objects.filter(user=request.user.id))))
        fixes.append(
            Fix(REPORT,
                _('reports').capitalize(), 'v2/rok/icon/news.png', 'reports/',
                1))

    context['fix_list'] = fixes
    context['without_lists'] = True
    context['hide_important'] = True
    if period:
        context['title_info'] = period.name()

    if (app_param.restriction in HIDE_ITEM_INPUT):
        context['hide_add_item_input'] = True
    if (app_param.restriction not in SHOW_SELECTOR):
        context['hide_selector'] = True
    if (app_param.restriction in ADD_ENTITY):
        context['add_item_placeholder'] = ADD_ENTITY[
            app_param.restriction].capitalize()
    if (app_param.restriction == EMPL_INFO):
        context['list_id'] = employee.id
    if (app_param.restriction == DEP_HIST):
        context['list_id'] = depart.id

    query = None
    page_number = 1
    if (request.method == 'GET'):
        query = request.GET.get('q')
        page_number = request.GET.get('page')
    context['search_info'] = get_search_info(query)
    data = filtered_sorted_list(request.user, app_param, period, employee,
                                depart, query)
    context['search_qty'] = len(data)
    context['search_data'] = query and (len(data) > 0)

    if (app_param.restriction == EMPL_LIST):
        context['ed_item'] = employee

    if (app_param.restriction == EMPL_LIST):
        groups = []
        for item in data:
            grp_id, grp_name = get_grp_name(item, period.dBeg)
            group = find_group(groups, request.user, app_name, grp_id,
                               grp_name)
            group.items.append(item)
        context['item_groups'] = sorted(groups,
                                        key=lambda group: group.grp.grp_id)
        context['page_obj'] = data

    paginator = Paginator(data, items_per_page)
    page_obj = paginator.get_page(page_number)
    context['page_obj'] = paginator.get_page(page_number)
    template = loader.get_template('v2_wage/' + app_param.restriction +
                                   '.html')
    return HttpResponse(template.render(context, request))
Example #8
0
def toggle(request, pk):
    toggle_content_group(request.user.id, app_name, pk)
    return HttpResponseRedirect(
        reverse('v2_wage:main') + extract_get_params(request))
Example #9
0
def main(request):
    app_param = get_app_params(request.user, app_name)
    if (app_param.restriction != PERS) and (app_param.restriction != TRIP):
        set_restriction(request.user, app_name, TRIP)
        return HttpResponseRedirect(
            reverse('v2_trip:main') + extract_get_params(request))

    if process_common_commands(request, app_name):
        return HttpResponseRedirect(
            reverse('v2_trip:main') + extract_get_params(request))

    form = None
    if (request.method == 'POST'):
        if ('item-add' in request.POST):
            if (app_param.restriction == TRIP):
                item_id = trip_add(request)
            if (app_param.restriction == PERS):
                item_id = pers_add(request)
            return HttpResponseRedirect(
                reverse('v2_trip:item_form', args=[item_id]))
        if ('trip-count' in request.POST):
            do_count(request)
            return HttpResponseRedirect(reverse('v2_trip:main'))
        if ('item-in-list-select' in request.POST) and (app_param.restriction
                                                        == PERS):
            pk = request.POST['item-in-list-select']
            if pk:
                set_active(request.user.id, pk)
                return HttpResponseRedirect(
                    reverse('v2_trip:item_form', args=[pk]))

    app_param, context = get_base_context_ext(request, app_name, 'main',
                                              (app_param.restriction, ))

    redirect = False

    if app_param.article:
        valid_article = False
        if (app_param.restriction == TRIP):
            valid_article = Trip.objects.filter(id=app_param.art_id,
                                                user=request.user.id).exists()
        if (app_param.restriction == PERS):
            valid_article = Person.objects.filter(
                id=app_param.art_id, user=request.user.id).exists()
        if valid_article:
            if (app_param.restriction == TRIP):
                redirect = get_trip_article(request, context, app_param.art_id)
            if (app_param.restriction == PERS):
                redirect = get_pers_article(request, context, app_param.art_id)
        else:
            set_article_visible(request.user, app_name, False)
            redirect = True

    if redirect:
        return HttpResponseRedirect(
            reverse('v2_trip:main') + extract_get_params(request))

    fixes = []
    fixes.append(
        Fix(PERS,
            _('persons').capitalize(), 'v2/rok/icon/user.png', 'persons/',
            len(Person.objects.filter(user=request.user.id))))
    fixes.append(
        Fix(TRIP,
            _('trips').capitalize(), 'v2/rok/icon/car.png', 'trips/',
            len(Trip.objects.filter(user=request.user.id))))
    context['fix_list'] = fixes
    context['without_lists'] = True
    context['hide_important'] = True
    context['title_info'] = trip_summary(request.user.id, False)
    if (app_param.restriction == PERS):
        context['add_item_placeholder'] = _('add person').capitalize()
    if (app_param.restriction == TRIP):
        context['hide_add_item_input'] = True
        context['complete_icon'] = 'v2/rok/icon/car.png'
        context['uncomplete_icon'] = 'v2/rok/icon/cost.png'
        context['today'] = int(datetime.today().strftime('%w'))

    query = None
    if request.method == 'GET':
        query = request.GET.get('q')
    context['search_info'] = get_search_info(query)
    data = filtered_sorted_list(request.user, app_param.restriction, query)
    context['search_qty'] = len(data)
    context['search_data'] = query and (len(data) > 0)
    page_number = 1
    if (request.method == 'GET'):
        page_number = request.GET.get('page')
    paginator = Paginator(data, items_per_page)
    page_obj = paginator.get_page(page_number)
    context['page_obj'] = paginator.get_page(page_number)

    template = loader.get_template(get_template_file(app_param.restriction))
    return HttpResponse(template.render(context, request))
Example #10
0
def item_form(request, pk):
    set_article_kind(request.user, app_name, '', pk)
    return HttpResponseRedirect(
        reverse('v2_trip:main') + extract_get_params(request))