Exemple #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))
Exemple #2
0
def wage_entity(request, name, pk):
    if (name == EMPL_LIST):
        set_restriction(request.user, app_name, EMPL_INFO)
    elif (name == DEP_LIST):
        set_restriction(request.user, app_name, DEP_HIST)
    else:
        set_restriction(request.user, app_name, name)
    set_article_kind(request.user, app_name, '', pk)
    return HttpResponseRedirect(reverse('v2_wage:main'))
Exemple #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))
Exemple #4
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))
Exemple #5
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)
Exemple #6
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))
Exemple #7
0
def trip_entity(request, name, pk):
    set_restriction(request.user, app_name, name)
    set_article_kind(request.user, app_name, '', pk)
    return HttpResponseRedirect(reverse('v2_trip:main'))
Exemple #8
0
def go_trips(request):
    set_restriction(request.user, app_name, TRIP)
    return HttpResponseRedirect(reverse('v2_trip:main'))