示例#1
0
def edit_robot(request, action: str, row_id: int = None, *args, **kwargs):
    """Создание/редактирование роботов
       :param request: HttpRequest
       :param action: действие над объектом (создание/редактирование/удаление)
       :param row_id: ид записи
    """
    mh_vars = robots_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, action)
    row = mh.get_row(row_id)
    context = mh.context
    if mh.error:
        return redirect('%s?error=not_found' % (mh.root_url, ))
    if request.method == 'GET':
        if action == 'create':
            mh.breadcrumbs_add({
                'link': mh.url_create,
                'name': '%s %s' % (mh.action_create, mh.rp_singular_obj),
            })
        elif action == 'edit' and row:
            mh.breadcrumbs_add({
                'link': mh.url_edit,
                'name': '%s %s' % (mh.action_edit, mh.rp_singular_obj),
            })
        elif action == 'drop' and row:
            if mh.permissions['drop']:
                row.delete()
                mh.row = None
                context['success'] = '%s удален' % (mh.singular_obj, )
            else:
                context['error'] = 'Недостаточно прав'
    elif request.method == 'POST':
        pass_fields = ()
        mh.post_vars(pass_fields=pass_fields)
        if action == 'create' or (action == 'edit' and row):
            if action == 'create':
                if mh.permissions['create']:
                    mh.row = mh.model()
                    mh.save_row()
                    context['success'] = 'Данные успешно записаны'
                else:
                    context['error'] = 'Недостаточно прав'
            if action == 'edit':
                if mh.permissions['edit']:
                    mh.save_row()
                    context['success'] = 'Данные успешно записаны'
                else:
                    context['error'] = 'Недостаточно прав'
        elif action == 'img' and request.FILES:
            mh.uploads()
    if mh.row:
        context['row'] = object_fields(mh.row, pass_fields=('password', ))
        context['row']['folder'] = mh.row.get_folder()
        context['row']['thumb'] = mh.row.thumb()
        context['row']['imagine'] = mh.row.imagine()
        context['redirect'] = mh.get_url_edit()

    if request.is_ajax() or action == 'img':
        return JsonResponse(context, safe=False)
    template = '%sedit.html' % (mh.template_prefix, )
    return render(request, template, context)
示例#2
0
def admission_sheet_positions(request, *args, **kwargs):
    """Изменение позиций листов допуска"""
    result = {}
    mh_vars = admission_sheet_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#3
0
def flattooltip_positions(request, *args, **kwargs):
    """Изменение позиций подсказок"""
    result = {}
    mh_vars = flattooltip_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#4
0
def users_positions(request, *args, **kwargs):
    """Изменение позиций пользователей АТС"""
    result = {}
    mh_vars = users_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#5
0
def show_flattooltip(request, *args, **kwargs):
    """Вывод подсказок"""
    mh_vars = flattooltip_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP)
    mh.select_related_add('block')
    context = mh.context

    # -----------------------------
    # Вся выборка только через аякс
    # -----------------------------
    if request.is_ajax():
        rows = mh.standard_show()
        result = []
        for row in rows:
            item = object_fields(row)
            item['actions'] = row.id
            item['folder'] = row.get_folder()
            item['thumb'] = row.thumb()
            item['imagine'] = row.imagine()
            result.append(item)
        if request.GET.get('page'):
            result = {'data': result,
                      'last_page': mh.raw_paginator['total_pages'],
                      'total_records': mh.raw_paginator['total_records'],
                      'cur_page': mh.raw_paginator['cur_page'],
                      'by': mh.raw_paginator['by'], }
        return JsonResponse(result, safe=False)
    template = '%stable.html' % (mh.template_prefix, )
    return render(request, template, context)
示例#6
0
def conclusions_positions(request, *args, **kwargs):
    """Изменение позиций заключений (актов)"""
    result = {}
    mh_vars = conclusions_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#7
0
def show_email_accounts(request, *args, **kwargs):
    """Вывод Email аккаунтов"""
    mh_vars = email_accounts_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP)
    mh.breadcrumbs.insert(0, root_breadcrumbs)
    context = mh.context

    # -----------------------------
    # Вся выборка только через аякс
    # -----------------------------
    if request.is_ajax():
        rows = mh.standard_show()
        result = []
        for row in rows:
            item = object_fields(row)
            item['actions'] = row.id
            item['folder'] = row.get_folder()
            item['thumb'] = row.thumb()
            item['imagine'] = row.imagine()
            result.append(item)

        if request.GET.get('page'):
            result = {
                'data': result,
                'last_page': mh.raw_paginator['total_pages'],
                'total_records': mh.raw_paginator['total_records'],
                'cur_page': mh.raw_paginator['cur_page'],
                'by': mh.raw_paginator['by'],
            }
        return JsonResponse(result, safe=False)
    context['import_xlsx_url'] = reverse('%s:%s' % (CUR_APP, 'import_xlsx'),
                                         kwargs={'action': 'email_accounts'})
    template = '%stable.html' % (mh.template_prefix, )
    return render(request, template, context)
示例#8
0
def holding_kss_positions(request, *args, **kwargs):
    """Изменение позиций проведений КСС"""
    result = {}
    mh_vars = holding_kss_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#9
0
def spam_tables_positions(request, *args, **kwargs):
    """Изменение позиций файлов"""
    result = {}
    mh_vars = spam_tables_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#10
0
def robots_positions(request, *args, **kwargs):
    """Изменение позиций объектов"""
    result = {}
    mh_vars = binary_com_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#11
0
def show_holding_kss(request, *args, **kwargs):
    """Вывод проведений КСС"""
    mh_vars = holding_kss_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP)
    mh.select_related_add('welder')
    mh.select_related_add('welder__subject')
    mh.select_related_add('certification')
    context = mh.context
    context['insert_breadcrumbs'] = insert_breadcrumbs
    context['welding_types'] = WELDING_TYPES
    context['materials'] = MATERIALS
    context['group_choices'] = CertSections.group_choices
    # -----------------------------
    # Вся выборка только через аякс
    # -----------------------------
    if request.is_ajax():
        rows = mh.standard_show()
        result = []
        ids_certs = {
            row.certification.id: []
            for row in rows if row.certification
        }
        # Вытаскиваем группы для удостоверений
        cert_sections = CertSections.objects.filter(
            certification__in=ids_certs.keys()).values('certification',
                                                       'group', 'points')
        for cert_section in cert_sections:
            ids_certs[cert_section['certification']].append(cert_section)

        for row in rows:
            item = object_fields(row)
            item['sections'] = []
            if row.certification:
                item['sections'] = ids_certs.get(row.certification.id, [])
            welding_view = 'ТТ'
            with_tt = False
            with_mk = False
            for section in item['sections']:
                if section['group'] == 12:
                    with_mk = True
                else:
                    with_tt = True
            if with_mk:
                welding_view = 'МК'
            if with_mk and with_tt:
                welding_view = 'ТТ/МК'
            item['certification__certsections__group'] = welding_view
            item['actions'] = row.id
            result.append(item)
        if request.GET.get('page'):
            result = {
                'data': result,
                'last_page': mh.raw_paginator['total_pages'],
                'total_records': mh.raw_paginator['total_records'],
                'cur_page': mh.raw_paginator['cur_page'],
                'by': mh.raw_paginator['by'],
            }
        return JsonResponse(result, safe=False)
    template = '%stable.html' % (mh.template_prefix, )
    return render(request, template, context)
示例#12
0
def black_list_positions(request, *args, **kwargs):
    """Изменение позиций в черном списке"""
    result = {}
    mh_vars = black_list_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#13
0
def redirects_positions(request, *args, **kwargs):
    """Изменение переадресаций рассылки"""
    result = {}
    mh_vars = redirects_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#14
0
def letters_of_guarantee_positions(request, *args, **kwargs):
    """Изменение позиций гарантийных писем"""
    result = {}
    mh_vars = letters_of_guarantee_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#15
0
def mechtest_positions(request, *args, **kwargs):
    """Изменение позиций мехиспытаний"""
    result = {}
    mh_vars = mechtest_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#16
0
def extra_fields_positions(request, *args, **kwargs):
    """Изменение позиций доп. полей пользователей/групп"""
    result = {}
    mh_vars = extra_fields_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#17
0
def show_dealers(request, *args, **kwargs):
    """Вывод дилеров
       :param request: HttpRequest
    """
    mh_vars = dealers_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP)
    mh.select_related_add('address')
    context = mh.context
    context['city_choices'] = Dealer.city_choices
    # -----------------------------
    # Вся выборка только через аякс
    # -----------------------------
    if request.is_ajax():
        rows = mh.standard_show()
        result = []
        for row in rows:
            item = object_fields(row)
            item['actions'] = row.id
            item['folder'] = row.get_folder()
            item['thumb'] = row.thumb()
            item['imagine'] = row.imagine()
            if row.address:
                item['address'] = row.address.address_str()
            result.append(item)
        if request.GET.get('page'):
            result = {
                'data': result,
                'last_page': mh.raw_paginator['total_pages'],
                'total_records': mh.raw_paginator['total_records'],
                'cur_page': mh.raw_paginator['cur_page'],
                'by': mh.raw_paginator['by'],
            }
        return JsonResponse(result, safe=False)
    template = '%stable.html' % (mh.template_prefix, )
    return render(request, template, context)
示例#18
0
def api(request, action: str = 'users'):
    """Апи-метод для получения всех данных"""
    mh_vars = users_vars.copy()
    #if action == 'users':
    #    mh_vars = users_vars.copy()

    mh = create_model_helper(mh_vars, request, CUR_APP)
    # Принудительные права на просмотр
    #mh.permissions['view'] = True
    mh.select_related_add('customuser')
    context = mh.context

    rows = mh.standard_show()

    result = []
    for row in rows:
        item = object_fields(row, pass_fields=('password', ))
        item['folder'] = row.customuser.get_folder()
        item['thumb'] = row.customuser.thumb()
        item['name'] = str(row.customuser)
        item['phone'] = row.customuser.phone
        item['function'] = row.customuser.function
        result.append(item)

    result = {
        'data': result,
        'last_page': mh.raw_paginator['total_pages'],
        'total_records': mh.raw_paginator['total_records'],
        'cur_page': mh.raw_paginator['cur_page'],
        'by': mh.raw_paginator['by'],
    }
    return JsonResponse(result, safe=False)
示例#19
0
def users_positions(request, *args, **kwargs):
    """Изменение позиций пользователей"""
    result = {}
    mh_vars = users_vars.copy()
    # -----------------------------------------
    # Нестандартная сортировка, т/к сортировать
    # нужно связную модель user.customuser
    # -----------------------------------------
    positions = []
    if request.method == 'POST':
        positions = request.POST.getlist('positions[]')
    elif request.method == 'GET':
        positions = request.GET.getlist('positions[]')
    ids_customuser = dict(
        User.objects.filter(pk__in=positions).values_list(
            'id', 'customuser__id'))
    ids = []
    for position in positions:
        position = int(position)
        if position in ids_customuser:
            ids.append(ids_customuser[position])
    mh_vars['model'] = customUser
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    # Для customUser прав на просмотр нету,
    # поэтому и менять позиции не получится
    result = mh.update_positions(custom_positions=ids)
    return JsonResponse(result, safe=False)
示例#20
0
def show_seances(request, *args, **kwargs):
    """Вывод сеансов для Афиши"""
    mh_vars = seances_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP)
    mh.select_related_add('place')
    mh.select_related_add('event')
    context = mh.context

    # -----------------------------
    # Вся выборка только через аякс
    # -----------------------------
    if request.is_ajax():
        rows = mh.standard_show()
        result = []
        for row in rows:
            item = object_fields(row)
            item['actions'] = row.id
            item['folder'] = row.get_folder()
            if row.place:
                item['place__name'] = row.place.name
            if row.event:
                item['event__name'] = row.event.name
            result.append(item)

        if request.GET.get('page'):
            result = {
                'data': result,
                'last_page': mh.raw_paginator['total_pages'],
                'total_records': mh.raw_paginator['total_records'],
                'cur_page': mh.raw_paginator['cur_page'],
                'by': mh.raw_paginator['by'],
            }
        return JsonResponse(result, safe=False)
    template = '%stable.html' % (mh.template_prefix, )
    return render(request, template, context)
示例#21
0
def email_accounts_positions(request, *args, **kwargs):
    """Изменение позиций Email аккаунтов"""
    result = {}
    mh_vars = email_accounts_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#22
0
def show_pickup_points(request, *args, **kwargs):
    """Вывод точек вывоза пользователей
       :param request: HttpRequest
    """
    mh_vars = pickup_points_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP)
    mh.select_related_add('shopper')
    mh.select_related_add('address')
    mh.select_related_add('order')
    context = mh.context

    # -----------------------------
    # Вся выборка только через аякс
    # -----------------------------
    if request.is_ajax():
        result = []
        rows = mh.standard_show(only_fields=pp_only_fields)
        for row in rows:
            item = object_fields(row,
                                 only_fields=pp_only_fields,
                                 fk_only_keys=pp_fk_keys)
            item['actions'] = row.id
            result.append(item)
        if request.GET.get('page'):
            result = {
                'data': result,
                'last_page': mh.raw_paginator['total_pages'],
                'total_records': mh.raw_paginator['total_records'],
                'cur_page': mh.raw_paginator['cur_page'],
                'by': mh.raw_paginator['by'],
            }
        return JsonResponse(result, safe=False)
    template = '%stable.html' % (mh.template_prefix, )
    return render(request, template, context)
示例#23
0
def show_black_list(request, *args, **kwargs):
    """Вывод Черного списка emails"""
    mh_vars = black_list_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP)
    mh.breadcrumbs.insert(0, root_breadcrumbs)
    context = mh.context

    # -----------------------------
    # Вся выборка только через аякс
    # -----------------------------
    if request.is_ajax():
        rows = mh.standard_show()
        result = []
        for row in rows:
            item = object_fields(row)
            item['actions'] = row.id
            item['folder'] = row.get_folder()
            item['thumb'] = row.thumb()
            item['imagine'] = row.imagine()
            result.append(item)

        if request.GET.get('page'):
            result = {
                'data': result,
                'last_page': mh.raw_paginator['total_pages'],
                'total_records': mh.raw_paginator['total_records'],
                'cur_page': mh.raw_paginator['cur_page'],
                'by': mh.raw_paginator['by'],
            }
        return JsonResponse(result, safe=False)
    template = '%stable.html' % (mh.template_prefix, )
    return render(request, template, context)
示例#24
0
def translates_positions(request, *args, **kwargs):
    """Изменение позиций переводов"""
    result = {}
    mh_vars = languages_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#25
0
def sms_phones_positions(request, *args, **kwargs):
    """Изменение позиций телефонов для смс"""
    result = {}
    mh_vars = sms_phones_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#26
0
def certifications_positions(request, *args, **kwargs):
    """Изменение удостоверений"""
    result = {}
    mh_vars = certifications_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#27
0
def defectoscopists_positions(request, *args, **kwargs):
    """Изменение позиций дефектоскопистов"""
    result = {}
    mh_vars = defectoscopists_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#28
0
def personal_users_positions(request, *args, **kwargs):
    """Изменение позиций пользователей с сайта
       Они загружаются автоматом, поэтому смысла мало"""
    result = {}
    mh_vars = personal_users_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#29
0
def pvalues_positions(request, *args, **kwargs):
    """Изменение позиций значений свойств в свойстве"""
    result = {}
    mh_vars = pvalues_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    mh.get_permissions(Products)  # Права от товаров/услуг
    result = mh.update_positions()
    return JsonResponse(result, safe=False)
示例#30
0
def contractors_positions(request, *args, **kwargs):
    """Изменение позиций контрагентов
       :param request: HttpRequest
    """
    result = {}
    mh_vars = contractors_vars.copy()
    mh = create_model_helper(mh_vars, request, CUR_APP, 'positions')
    result = mh.update_positions()
    return JsonResponse(result, safe=False)