Beispiel #1
0
def edit_telegram_data(request):
    if request.method == 'POST':
        action = request.POST.get('name')
        uid = request.POST.get('pk')
        value = request.POST.get('value')
        if not validate_empty_str(value):
            if check_ajax(request):
                return HttpResponseBadRequest(_('please enter username'))
            return render(request, 'errors/CustomError.html',
                          {'error_message': _('please enter username')})
        if not validate_integer(uid):
            if check_ajax(request):
                return HttpResponseBadRequest(_('invalid user'))
            return render(request, 'errors/CustomError.html',
                          {'error_message': _('invalid user')})
        if not TelegramUser.objects.filter(pk=uid).exists():
            if check_ajax(request):
                return HttpResponseBadRequest(_('no such user found!'))
            return render(request, 'errors/CustomError.html',
                          {'error_message': _('no such user found')})
        u = TelegramUser.objects.get(pk=uid)
        u.username = value
        u.save()
        if check_ajax(request):
            return HttpResponse('200')
        return redirect(reverse(view_active_users))
    else:
        if check_ajax(request):
            return HttpResponseBadRequest(_('invalid method'))
        return redirect(reverse(view_active_users))
Beispiel #2
0
def view_send_types(request):
    if not check_ajax(request):
        return render(request,
                      'finance/dedicate/SendType/SendTypeManagement.html',
                      {'has_nav': True})
    sm = SendTypeManagement(request)
    return HttpResponse(sm.get_all())
Beispiel #3
0
def view_letter_files(request):
    if not check_ajax(request):
        return render(request,
                      'indicator/LetterFile/LetterFileManagement.html',
                      {'has_nav': False})
    lm = LetterFileManagement(request)
    return HttpResponse(lm.get_all())
Beispiel #4
0
def reference_job_to_other(request):
    if request.method == 'POST':
        job = request.POST.get('rfj')
        message = request.POST.get('rf')
        group = request.POST.get('rg')
        if not validate_integer(job):
            return _return_error_(_('invalid dashboard'), request)
        if not validate_empty_str(message):
            return _return_error_(_('please enter message'), request)
        if not validate_integer(group):
            return _return_error_(_('invalid group'), request)
        dash = get_current_user_dashboard(request.user, True)
        if int(job) not in dash:
            return _return_error_(_('invalid dashboard'), request)
        if not Group.objects.filter(pk=group).exists():
            return _return_error_(_('invalid group'), request)
        d = Dashboard.objects.get(pk=job)
        if DashboardReferences.objects.filter(
                dashboard=d.pk, target_group_id=group,
                source_group_id=d.group_id).exists():
            dr = DashboardReferences.objects.get(dashboard=d.pk,
                                                 target_group_id=group,
                                                 source_group_id=d.group_id)
        else:
            dr = DashboardReferences()
        if request.user.is_superuser:
            src_id = d.group_id
        else:
            user_groups = request.user.groups.all().values_list('pk',
                                                                flat=True)
            if d.group_id in user_groups:
                src_id = d.group_id
            else:
                src_id = user_groups[0]
        d.last_state = 0
        d.save()
        dr.dashboard = d
        dr.reason = message
        dst = Group.objects.get(pk=group)
        src = Group.objects.get(pk=src_id)
        dr.target_group = dst
        dr.source_group = src
        dr.user = request.user
        dr.save()
        uw = UserWorkHistory()
        uw.group = src
        uw.dashboard = d
        uw.message = _('job referenced to other group'
                       ) + ' - ' + dst.name + ' - ' + message
        uw.start_date = now()
        uw.state = 5  # referenced
        uw.user = request.user
        uw.save()
        dc = DashboardCurrentGroup.objects.get(dashboard=d.pk)
        dc.group_id = group
        dc.save()
        if check_ajax(request):
            return HttpResponse('200')
        return redirect(reverse(view_dashboard) + '?j=%s' % job)
    return _return_error_('invalid method', request)
Beispiel #5
0
def create_user_ajax(request):
    ia = check_ajax(request)
    um = UserManager(request)
    if request.method == 'POST':
        try:
            um.set_post()
            new_user = um.update()
            if request.user.is_superuser:
                if um.is_superuser:
                    um.set_personnel()
                    um.set_superuser()
                elif um.is_personnel or um.is_reseller:
                    um.set_personnel()
            if new_user.is_superuser:
                SuperUserCreatedEventHandler().fire(new_user, None,
                                                    request.user.pk, True)
            elif new_user.is_staff:
                StaffUserCreatedEventHandler().fire(new_user, None,
                                                    request.user.pk, True)
            if not new_user.is_active:
                InactiveAccountLoginEventHandler().fire(
                    new_user, None, request.user.pk, True)
            return HttpResponse(str(new_user.pk))
        except RequestProcessException as e:
            # um.roll_back()
            return e.get_response()
    if ia:
        return HttpResponseBadRequest(_('invalid method'))
    return render(request, 'errors/AccessDenied.html')
Beispiel #6
0
def update_dedicated_user_service(request):
    if request.method == 'POST':
        service_id = request.POST.get('si')
        name = request.POST.get('s')
        price = request.POST.get('pr')
        ip = request.POST.get('i')
        if not validate_integer(service_id):
            return send_error(request, _('invalid service'))
        if not DedicatedUserService.objects.filter(pk=service_id).exists():
            return send_error(request, _('no such service'))
        if not validate_empty_str(name):
            return send_error(request, _('please enter service'))
        if not validate_integer(price):
            return send_error(request, _('please enter valid price'))
        if not validate_empty_str(ip):
            return send_error(request, _('please enter ip'))
        x = DedicatedUserService.objects.get(pk=service_id)
        x.price = int(price)
        x.service = name
        x.ip_pool = ip
        x.save()
        if check_ajax(request):
            return HttpResponse('200')
        return redirect(
            reverse(view_dedicated_user_service) + '?u=%s' % x.user_id)
    return send_error(request, _('invalid method'))
Beispiel #7
0
def view_pocket_book(request):
    if not check_ajax(request):
        return render(request,
                      'indicator/PocketBook/PocketBookManagement.html',
                      {'has_nav': False})
    pm = PocketBookManagement(request)
    return HttpResponse(pm.get_all())
Beispiel #8
0
def view_vip_groups(request):
    if not check_ajax(request):
        groups = ServiceGroups.objects.filter(is_deleted=False)
        return render(request, 'vip/VIPGroupManagement.html',
                      {'groups': groups})
    gm = VIPGroupManagement(request)
    return HttpResponse(gm.get_all())
Beispiel #9
0
def view_towers(request):
    load_towers_from_ibs()
    if not check_ajax(request):
        return render(request, 'towers/TowerManagement.html',
                      {'has_nav': False})
    tm = TowerRequestManager(request)
    return HttpResponse(tm.get_all())
Beispiel #10
0
def add_new_job_state(request):
    ai = check_ajax(request)
    if request.method == 'GET':
        if ai:
            return redirect(reverse(view_dashboard))
        return redirect('/')
    elif request.method == 'POST':
        message = request.POST.get('msg')
        dash_id = request.POST.get('di')
        state = request.POST.get('s')
        to_edit = request.POST.get('te')
        if not validate_integer(dash_id):
            return _return_error_(_('no such data found'), request)
        if not validate_empty_str(message):
            return _return_error_(_('please enter your report'), request)
        if not Dashboard.objects.filter(pk=dash_id).exists():
            return _return_error_(_('no such dashboard found'), request)
        if not validate_integer(state):
            state = 2
        else:
            state = int(state)
        # if state > 4:
        #     state = 4
        uw = None
        if request.user.has_perm('CRM.change_userworkhistory'):
            if validate_integer(to_edit):
                if UserWorkHistory.objects.filter(pk=to_edit).exists():
                    uw = UserWorkHistory.objects.get(pk=to_edit)
                    if state < 2:  # user is trying to modify start state
                        uw = None
        if not uw:
            uw = UserWorkHistory()
        dash = Dashboard.objects.get(pk=dash_id)
        uw.dashboard = dash
        # DashboardReferences.objects.get().
        if request.user.is_superuser:
            dst = Group.objects.get(pk=dash.group_id)
        else:
            dst = Group.objects.get(pk=request.user.groups.first().pk)
        uw.group = dst
        uw.message = message
        uw.start_date = now()
        uw.user = request.user
        if dash.is_read:
            dash.last_state = state
        else:
            state = 0
        uw.state = state
        uw.save()
        if state == 3 or state == 4:
            dash.is_done = True
            dash.done_date = now()
            remove_calendar_event(dash)
        dash.save()
        if ai:
            return HttpResponse('200')
        return redirect(reverse(view_dashboard) + '?j=%s' % dash_id)
    else:
        return render(request, 'errors/AccessDenied.html')
Beispiel #11
0
def view_equipment_state_list(request):
    if not check_ajax(request):
        return render(request, 'equipment/state_list/StateListManagement.html', {'has_nav': True, 'get': request.GET})
    fields = ['pk', 'name', 'description', 'ext']
    order = get_full_sort(request.GET, fields)
    states = search_equipment_state_list(request.GET).values(*fields).order_by(order)
    res = get_paginate(states, request.GET.get('current'), request.GET.get('rowCount'))
    return HttpResponse(res)
Beispiel #12
0
def view_temp_charge_reports(request):
    if not check_ajax(request):
        return render(request, 'service/TempCharge/TempChargeReport.html', {'has_nav': True})
    tm = TempChargeManagement(request)
    try:
        return HttpResponse(tm.get_all())
    except RequestProcessException as e:
        return e.get_response()
Beispiel #13
0
def view_equipment_code(request):
    if not check_ajax(request):
        return render(request, 'equipment/codes/CodeManagement.html', {'has_nav': False})
    fields = ['pk', 'ext', 'code', 'sell_price', 'used_sell_price', 'name']
    sort = get_full_sort(request.GET, fields)
    ec = search_equipment_code(request.GET).values(*fields).order_by(sort)
    rs = get_paginate(ec, request.GET.get('current'), request.GET.get("rowCount"))
    return HttpResponse(rs)
Beispiel #14
0
def view_equipment_type(request):
    if not check_ajax(request):
        return render(request, 'equipment/equipment_type/TypeManagement.html', {'has_nav': True})
    fields = ['pk', 'ext', 'name']
    sort = get_full_sort(request.GET, fields)
    res = search_equipment_type(request.GET).values(*fields).order_by(sort)
    p = get_paginate(res, request.GET.get('current'), request.GET.get('rowCount'))
    return HttpResponse(p)
Beispiel #15
0
def show_all_service(request):
    if not check_ajax(request):
        service_groups = ServiceGroups.objects.filter(is_deleted=False)
        return render(request, 'service/ViewAllServices.html', {'service_groups': service_groups})
    try:
        sm = NormalServiceManager(request)
        return HttpResponse(sm.get_all())
    except RequestProcessException as e:
        return e.get_response()
Beispiel #16
0
def view_equipment_group(request):
    if not check_ajax(request):
        return render(request, 'equipment/group/GroupManagement.html', {'has_nav': False})
    fields = ['name', 'pk', 'description', 'ext', 'equipment_type__name', 'remain_items', 'used_remain_items',
              'code__code']
    sort = get_full_sort(request.GET, fields)
    groups = search_equipment_group(request.GET).values(*fields).order_by(sort)
    rs = get_paginate(groups, request.GET.get('current'), request.GET.get('rowCount'))
    return HttpResponse(rs)
Beispiel #17
0
def view_float_service(request):
    if not check_ajax(request):
        formula = ServiceFormula.objects.filter(is_deleted=False)
        ibs_groups = IBSService.objects.filter(is_deleted=False)
        return render(request, 'service/float_service/FloatServiceManagement.html', {'has_nav': False,
                                                                                     'formula': formula,
                                                                                     'ibs': ibs_groups})
    sm = BasicServiceManager(request)
    return HttpResponse(sm.get_all())
Beispiel #18
0
def close_poll(request):
    if request.method == 'GET':
        pid = request.GET.get('p')
        x = validate_single_poll(pid)
        if not x[0]:
            if check_ajax(request):
                return HttpResponseBadRequest(x[1])
            return redirect(reverse(view_polls))
        p = Polls.objects.get(pk=pid)
        p.is_closed = not p.is_closed
        p.save()
        if check_ajax(request):
            return HttpResponse('200')
        return redirect(reverse(view_polls))
    else:
        if check_ajax(request):
            return HttpResponseBadRequest(_('invalid method'))
        return redirect(reverse(view_polls))
Beispiel #19
0
def view_ip_static(request):
    active_ips = UserIPStatic.objects.filter(is_deleted=False).values_list(
        'ip', flat=True)
    if not check_ajax(request):
        return render(request, 'service/IPStatic/ViewIPs.html',
                      {'used': active_ips})
    ipm = IPStaticRequestManager(request)
    res = ipm.get_all()
    return HttpResponse(res)
Beispiel #20
0
def view_equipment_order(request):
    em = EquipmentOrderManager(request)
    if not check_ajax(request):
        personnel = em.get_personnel()
        rcv = em.get_receivers()
        search_params = em.url_data
        return render(request, 'equipment/order/OrderManagement.html', {'has_nav': True, 'personnel': personnel,
                                                                        'rcv': rcv,
                                                                        'search_params': search_params})
    return HttpResponse(em.get_all())
Beispiel #21
0
def view_equipment(request):
    if not check_ajax(request):
        groups = EquipmentGroup.objects.all()
        return render(request, 'equipment/ViewEquipment.html', {'has_nav': True, 'equipment_groups': groups})
    fields = ['ext', 'description', 'group__name', 'last_update',
              'is_involved', 'is_used', 'pk', 'serial', 'fk_equipment_state_equipment__state__name']
    order = get_full_sort(request.GET, fields)
    res = search_equipment(request.GET).values(*fields).order_by(order)
    x = get_paginate(res, request.GET.get('current'), request.GET.get('rowCount'))
    return HttpResponse(x)
Beispiel #22
0
def view_transport(request):
    if not check_ajax(request):
        return render(request, 'transportation/TransportMain.html',
                      {'has_nav': True})
    data = search_transports(request.GET,
                             None).values('pk', 'name', 'description',
                                          'last_update',
                                          'transport_type__name', 'external')
    res = get_paginate(data, request.GET.get('current'),
                       request.GET.get('rowCount'))
    return HttpResponse(res)
Beispiel #23
0
def view_service_templates(request):
    if not check_ajax(request):
        return render(request, 'service/float_service/template/FloatTemplateManagement.html')
    try:
        fm = UserTemplateManager(request)
        return HttpResponse(fm.get_all())
    except RequestProcessException as e:
        return e.get_response()
    except Exception as e:
        logger.error(e.message or e.args)
        return send_error(request, _('system error'))
Beispiel #24
0
def view_float_service_discount(request):
    if not check_ajax(request):
        return render(request, 'service/float_service/discount/FloatDiscountManagement.html')
    try:
        dm = FloatDiscountManager(request)
        res = dm.get_all()
        return HttpResponse(res)
    except RequestProcessException as e:
        return e.get_response()
    except Exception as e:
        logger.error(e.message or e.args)
        return send_error(request, _('system error'))
Beispiel #25
0
def contract_view_all(request):
    if not check_ajax(request):
        return render(request, 'contract/ContractManagement.html')
    try:
        xm = ContractRequestManagement(request)
        res = xm.get_all()
        return HttpResponse(res)
    except RequestProcessException as e:
        return e.get_response()
    except Exception as e:
        logger.error(e.args or e.message)
        return send_error(request, _('system error'))
Beispiel #26
0
def view_calendar_event_types(request):
    try:
        if not check_ajax(request):
            return render(request,
                          'calendar/event_type/EventTypeManagement.html')
        cm = CalendarEventTypeRequestManager(request)
        res = cm.get_all()
        return HttpResponse(res)
    except RequestProcessException as e:
        return e.get_response()
    except Exception as e:
        logger.error(e.message or e.args)
        return send_error(request, _('system error'))
Beispiel #27
0
def view_custom_option(request):
    if not check_ajax(request):
        return render(request,
                      'service/float_service/custom_options/CustomOptionManagement.html',
                      {'has_nav': True, 'service': BasicService.objects.filter(is_deleted=False),
                       'ibs_groups': IBSService.objects.filter(is_deleted=False),
                       'group': CustomOptionGroup.objects.filter(is_deleted=False),
                       'pool': IBSIpPool.objects.filter(is_deleted=False)})
    try:
        cm = CustomOptionManager(request)
        return HttpResponse(cm.get_all())
    except RequestProcessException as e:
        return e.get_response()
Beispiel #28
0
def show_all_invoices(request):
    ia = check_ajax(request)
    if not (ia or request.GET.get('p') == '1' or request.GET.get('x') == '1'):
        service_groups = ServiceGroups.objects.filter(is_deleted=False)
        return render(
            request, 'finance/ShowAll.html', {
                'service_groups': service_groups,
                'get': request.GET,
                'has_nav': True,
                'pre_search': request.GET.urlencode()
            })
    im = InvoiceRequestManager(request)
    return HttpResponse(im.get_all())
Beispiel #29
0
def view_charge_packages(request):
    if not check_ajax(request):
        return render(request, 'finance/debit/ChargePackageManagement.html',
                      {'groups': Group.objects.all()})
    name = get_string(request.GET.get('searchPhrase'))
    fields = ['pk', 'name', 'ext', 'amount']
    sort = get_full_sort(request.GET, fields)
    packs = PricePackage.objects.filter(is_deleted=False)
    if name:
        packs = packs.filter(name__icontains=name)
    packs = packs.values(*fields).order_by(sort)
    res = get_paginate(packs, request.GET.get('current'),
                       request.GET.get('rowCount'))
    return HttpResponse(res)
Beispiel #30
0
def undo_delete_dedicate(request):
    if request.method == 'GET':
        service_id = request.GET.get('s')
        if not validate_integer(service_id):
            return send_error(request, _('invalid service'))
        if not DedicatedUserService.objects.filter(pk=service_id).exists():
            return send_error(request, _('no such service'))
        s = DedicatedUserService.objects.get(pk=service_id)
        s.is_deleted = False
        s.save()
        if check_ajax(request):
            return HttpResponse('200')
        return redirect(
            reverse(view_dedicated_user_service) + '?u=%s' % s.user_id)
    return send_error(request, _('invalid method'))