Пример #1
0
def account_management_status(request):
    if not (request.user.account.has_perm('billservice.change_account')):
        return {
            'status': False,
            'message': _(u'У вас нет прав на изменение аккаунтов')
        }
    status = request.GET.get('status')
    if request.method == 'POST' and status:
        form = AccountManagementForm(request.POST)
        print request.POST
        if form.is_valid():
            accounts = form.cleaned_data.get('accounts')
            if accounts:
                accounts.update(status=status)

            messages.success(request,
                             _(u'Статус успешно изменён.'),
                             extra_tags='alert-success')
            return {'status': True}

        messages.error(request,
                       _(u'Ошибка при изменении статуса.'),
                       extra_tags='alert-danger')
        return {'status': False}
    return {}
Пример #2
0
def account_management_restore(request):
    if  not (request.user.account.has_perm('billservice.edit_account')):
        return {'status':False, 'message': _(u'У вас нет прав редактирование аккаунтов')}
    id = int(request.POST.get('id',0)) or int(request.GET.get('id',0))
    m_form = AccountManagementForm(request.GET) 

    if m_form.is_valid():
        for acc in m_form.cleaned_data.get('accounts'):
            acc.deleted=None
            acc.save()
            log('EDIT', request.user, acc)
        return {"status": True}
    else:
        return {"status": False, "message": "Account not found"} 
Пример #3
0
def account_management_delete(request):
    if  not (request.user.account.has_perm('billservice.delete_account')):
        return {'status':False, 'message': _(u'У вас нет прав на удаление аккаунтов')}
    id = int(request.POST.get('id',0)) or int(request.GET.get('id',0))
    m_form = AccountManagementForm(request.GET) 

    if m_form.is_valid():
        for acc in m_form.cleaned_data.get('accounts'):

            log('DELETE', request.user, acc)
            acc.delete()
        return {"status": True}
    else:
        return {"status": False, "message": "Account not found"} 
Пример #4
0
def sendsms(request):

    if request.method == 'POST':
        print request.POST
        form = SendSmsForm(request.POST)

        if not (request.user.account.has_perm('billservice.add_news')):
            messages.error(request,
                           _(u'У вас нет прав на создание новостей'),
                           extra_tags='alert-danger')
            return {}

        if form.is_valid():
            accounts = form.cleaned_data.get('accounts')
            publish_date = form.cleaned_data.get('publish_date')
            body = form.cleaned_data.get('body')
            backend = form.cleaned_data.get('backend')

            for acc in accounts:
                if not acc.phone_m: continue
                acc.ballance = '%.2f' % acc.ballance
                item = Message()
                item.account = acc
                item.backend = backend
                item.to = acc.phone_m
                item.body = body
                item.publish_date = publish_date
                item.save()
                log('CREATE', request.user, item)
            return {'form': form, 'status': True}
        else:

            return {'form': form, 'status': False}
    else:

        if not (request.user.account.has_perm('billservice.add_news')):
            messages.error(request,
                           _(u'У вас нет прав на создание новостей'),
                           extra_tags='alert-danger')
            return {}

        m_form = AccountManagementForm(request.GET)
        form = None
        if m_form.is_valid():
            form = SendSmsForm(initial={
                'accounts':
                m_form.cleaned_data.get('accounts', [])
            })  # An unbound form

    return {'form': form, 'status': False}
Пример #5
0
def account_management_suspendedperiod(request):

    if request.method == 'POST':
        print request.POST
        form = SuspendedPeriodBatchForm(request.POST)

        if not (request.user.account.has_perm(
                'billservice.add_suspendedperiod')):
            messages.error(
                request,
                _(u'У вас нет прав на создание периодов без списаний'),
                extra_tags='alert-danger')
            return {}

        if form.is_valid():
            start_date = form.cleaned_data.get('start_date')
            end_date = form.cleaned_data.get('end_date')

            for acc in form.cleaned_data.get('accounts'):
                print acc
                item = SuspendedPeriod()
                item.start_date = start_date
                item.end_date = end_date
                item.account = acc
                item.save()
                log('CREATE', request.user, item)
            return {'form': form, 'status': True}
        else:

            return {'form': form, 'status': False}
    else:

        if not (request.user.account.has_perm(
                'billservice.add_suspendedperiod')):
            messages.error(
                request,
                _(u'У вас нет прав на создание периодов без списаний'),
                extra_tags='alert-danger')
            return {}

        m_form = AccountManagementForm(request.GET)
        form = None
        if m_form.is_valid():
            form = SuspendedPeriodBatchForm(initial={
                'accounts':
                m_form.cleaned_data.get('accounts', [])
            })  # An unbound form

    return {'form': form, 'status': False}
Пример #6
0
def account_management_accounttariff(request):

    account = None
    account_id = request.GET.get("account_id")
    id = request.POST.get("id")

    if request.method == 'POST':
        form = BatchAccountTariffForm(request.POST)

        if not (request.user.account.has_perm('billservice.add_accounttarif')):
            messages.error(
                request,
                _(u'У вас нет прав на создание тарифных планов у аккаунта'),
                extra_tags='alert-danger')
            return {}

        if form.is_valid():
            tariff = form.cleaned_data.get('tariff')
            dt = form.cleaned_data.get('datetime')
            for acc in form.cleaned_data.get('accounts'):
                acct = AccountTarif()
                acct.account = acc
                acct.tarif = tariff
                acct.datetime = dt
                acct.save()
                log('CREATE', request.user, acct)
            return {'form': form, 'status': True}
        else:
            print form._errors
            return {'form': form, 'status': False}
    else:

        if not (request.user.account.has_perm('billservice.add_accounttarif')):
            messages.error(request,
                           _(u'У вас нет прав на доступ в этот раздел.'),
                           extra_tags='alert-danger')
            return {}

        m_form = AccountManagementForm(request.GET)
        form = None
        if m_form.is_valid():
            form = BatchAccountTariffForm(
                initial={
                    'accounts': m_form.cleaned_data.get('accounts', []),
                    'datetime': datetime.datetime.now()
                })  # An unbound form

    return {'form': form, 'status': False, 'account': account}
Пример #7
0
def sendsms(request):
    

    if request.method == 'POST': 
        print request.POST
        form = SendSmsForm(request.POST) 

        if  not (request.user.account.has_perm('billservice.add_news')):
            messages.error(request, _(u'У вас нет прав на создание новостей'), extra_tags='alert-danger')
            return {}
        
        
        if form.is_valid(): 
            accounts = form.cleaned_data.get('accounts')
            publish_date = form.cleaned_data.get('publish_date')
            body = form.cleaned_data.get('body')
            backend = form.cleaned_data.get('backend')

            for acc in accounts:
                if not acc.phone_m: continue
                acc.ballance = '%.2f' % acc.ballance 
                item = Message()
                item.account = acc
                item.backend = backend
                item.to = acc.phone_m
                item.body = body
                item.publish_date = publish_date
                item.save() 
                log('CREATE', request.user, item)
            return {'form':form,  'status': True} 
        else:

            return {'form':form,  'status': False} 
    else:

        if  not (request.user.account.has_perm('billservice.add_news')):
            messages.error(request, _(u'У вас нет прав на создание новостей'), extra_tags='alert-danger')
            return {}

        m_form = AccountManagementForm(request.GET) 
        form = None
        if m_form.is_valid():
            form = SendSmsForm(initial={'accounts': m_form.cleaned_data.get('accounts', [])}) # An unbound form


    return { 'form':form, 'status': False} 
Пример #8
0
def account_management_restore(request):
    if not (request.user.account.has_perm('billservice.edit_account')):
        return {
            'status': False,
            'message': _(u'У вас нет прав редактирование аккаунтов')
        }
    id = int(request.POST.get('id', 0)) or int(request.GET.get('id', 0))
    m_form = AccountManagementForm(request.GET)

    if m_form.is_valid():
        for acc in m_form.cleaned_data.get('accounts'):
            acc.deleted = None
            acc.save()
            log('EDIT', request.user, acc)
        return {"status": True}
    else:
        return {"status": False, "message": "Account not found"}
Пример #9
0
def account_management_delete(request):
    if not (request.user.account.has_perm('billservice.delete_account')):
        return {
            'status': False,
            'message': _(u'У вас нет прав на удаление аккаунтов')
        }
    id = int(request.POST.get('id', 0)) or int(request.GET.get('id', 0))
    m_form = AccountManagementForm(request.GET)

    if m_form.is_valid():
        for acc in m_form.cleaned_data.get('accounts'):

            log('DELETE', request.user, acc)
            acc.delete()
        return {"status": True}
    else:
        return {"status": False, "message": "Account not found"}
Пример #10
0
def account_management_status(request):
    if  not (request.user.account.has_perm('billservice.change_account')):
        return {'status':False, 'message': _(u'У вас нет прав на изменение аккаунтов')}
    status = request.GET.get('status')
    if request.method == 'POST' and status: 
        form = AccountManagementForm(request.POST) 
        print request.POST
        if form.is_valid():
            accounts = form.cleaned_data.get('accounts')
            if accounts:
                accounts.update(status=status)
 
            messages.success(request, _(u'Статус успешно изменён.'), extra_tags='alert-success')
            return { 'status': True} 

        messages.error(request, _(u'Ошибка при изменении статуса.'), extra_tags='alert-danger')
        return { 'status': False} 
    return {}
Пример #11
0
def account_management_suspendedperiod(request):
    

    if request.method == 'POST': 
        print request.POST
        form = SuspendedPeriodBatchForm(request.POST) 

        if  not (request.user.account.has_perm('billservice.add_suspendedperiod')):
            messages.error(request, _(u'У вас нет прав на создание периодов без списаний'), extra_tags='alert-danger')
            return {}
        
        
        if form.is_valid(): 
            start_date = form.cleaned_data.get('start_date')
            end_date = form.cleaned_data.get('end_date')

            for acc in form.cleaned_data.get('accounts'):
                print acc
                item = SuspendedPeriod()
                item.start_date = start_date
                item.end_date = end_date
                item.account = acc
                item.save() 
                log('CREATE', request.user, item)
            return {'form':form,  'status': True} 
        else:

            return {'form':form,  'status': False} 
    else:

        if  not (request.user.account.has_perm('billservice.add_suspendedperiod')):
            messages.error(request, _(u'У вас нет прав на создание периодов без списаний'), extra_tags='alert-danger')
            return {}

        m_form = AccountManagementForm(request.GET) 
        form = None
        if m_form.is_valid():
            form = SuspendedPeriodBatchForm(initial={'accounts': m_form.cleaned_data.get('accounts', [])}) # An unbound form


    return { 'form':form, 'status': False} 
Пример #12
0
def account_management_accounttariff(request):

    account = None
    account_id = request.GET.get("account_id")
    id = request.POST.get("id")

    if request.method == 'POST': 
        form = BatchAccountTariffForm(request.POST) 

        if  not (request.user.account.has_perm('billservice.add_accounttarif')):
            messages.error(request, _(u'У вас нет прав на создание тарифных планов у аккаунта'), extra_tags='alert-danger')
            return {}

        if form.is_valid(): 
            tariff = form.cleaned_data.get('tariff')
            dt = form.cleaned_data.get('datetime')
            for acc in form.cleaned_data.get('accounts'):
                acct = AccountTarif()
                acct.account = acc
                acct.tarif = tariff
                acct.datetime = dt
                acct.save() 
                log('CREATE', request.user, acct)
            return {'form':form,  'status': True} 
        else:
            print form._errors
            return {'form':form,  'status': False} 
    else:

        if  not (request.user.account.has_perm('billservice.add_accounttarif')):
            messages.error(request, _(u'У вас нет прав на доступ в этот раздел.'), extra_tags='alert-danger')
            return {}

        m_form = AccountManagementForm(request.GET) 
        form = None
        if m_form.is_valid():
            form = BatchAccountTariffForm(initial={'accounts': m_form.cleaned_data.get('accounts', []), 'datetime': datetime.datetime.now()}) # An unbound form

    return { 'form':form, 'status': False, 'account':account}