예제 #1
0
파일: views.py 프로젝트: sdocent/djing
def buy_service(request, srv_id):
    abon = request.user
    service = get_object_or_404(Tariff, pk=srv_id)
    try:
        if request.method == 'POST':
            abon.pick_tariff(
                tariff=service,
                author=abon,
                comment=_("Buy the service via user side, service '%s'") %
                service)
            customer_nas_command.delay(abon.pk, 'sync')
            messages.success(
                request,
                _("The service '%s' was successfully activated") %
                service.title)
        else:
            current_service = abon.active_tariff()
            return render(
                request, 'clientsideapp/modal_service_buy.html', {
                    'service':
                    service,
                    'current_service':
                    current_service.tariff
                    if current_service is not None else None
                })
    except LogicError as e:
        messages.error(request, e)
    except NasFailedResult as e:
        messages.error(request, e)
    except OperationalError:
        pass
    return redirect('client_side:services')
예제 #2
0
파일: views.py 프로젝트: bashmak/djing
def buy_service(request, srv_id):
    abon = request.user
    service = get_object_or_404(Tariff, pk=srv_id)
    try:
        current_service = abon.active_tariff()
        if request.method == 'POST':
            abon.pick_tariff(
                service, None,
                _("Buy the service via user side, service '%s'") % service
            )
            customer_nas_command.delay(abon.pk, 'sync')
            messages.success(
                request,
                _("The service '%s' wan successfully activated") % service.title
            )
        else:
            return render(request, 'clientsideapp/modal_service_buy.html', {
                'service': service,
                'current_service': current_service.tariff
                if current_service is not None else None
            })
    except LogicError as e:
        messages.error(request, e)
    except NasFailedResult as e:
        messages.error(request, e)
    return redirect('client_side:services')
예제 #3
0
 def form_valid(self, form):
     r = super(IpUpdateView, self).form_valid(form)
     abon = self.object
     try:
         customer_nas_command.delay(abon.pk, 'sync')
     except OperationalError as e:
         messages.error(self.request, str(e))
     else:
         messages.success(self.request, _('Ip successfully updated'))
     return r
예제 #4
0
파일: views.py 프로젝트: bashmak/djing
 def post(self, request, *args, **kwargs):
     self.object = self.get_object()
     abon = self.object
     if abon.ip_address:
         abon.free_ip_addr()
         customer_nas_command.delay(abon.pk, 'remove')
         messages.success(request, _('Ip lease has been freed'))
     else:
         messages.error(request, _('User not have ip'))
     return redirect(
         'abonapp:abon_home',
         gid=self.kwargs.get('gid'),
         uname=self.kwargs.get('uname')
     )
예제 #5
0
def pick_tariff(request, gid: int, uname):
    grp = get_object_or_404(Group, pk=gid)
    abon = get_object_or_404(models.Abon, username=uname)
    tariffs = Tariff.objects.get_tariffs_by_group(grp.pk)
    try:
        if request.method == 'POST':
            trf = Tariff.objects.get(pk=request.POST.get('tariff'))
            deadline = request.POST.get('deadline')
            log_comment = _("Service '%(service_name)s' "
                            "has connected via admin until %(deadline)s") % {
                                'service_name': trf.title,
                                'deadline': deadline
                            }
            if deadline:
                deadline = datetime.strptime(deadline, '%Y-%m-%dT%H:%M')
                abon.pick_tariff(trf,
                                 request.user,
                                 deadline=deadline,
                                 comment=log_comment)
            else:
                abon.pick_tariff(trf, request.user, comment=log_comment)
            customer_nas_command.delay(abon.pk, 'sync')
            messages.success(request, _('Tariff has been picked'))
            return redirect('abonapp:abon_services',
                            gid=gid,
                            uname=abon.username)
    except (lib.LogicError, NasFailedResult, NasNetworkError,
            OperationalError) as e:
        messages.error(request, e)
        return redirect('abonapp:abon_services', gid=gid, uname=abon.username)
    except Tariff.DoesNotExist:
        messages.error(request, _('Tariff your picked does not exist'))
    except lib.MultipleException as errs:
        for err in errs.err_list:
            messages.error(request, err)
    except ValueError as e:
        messages.error(request, "%s: %s" % (_('fix form errors'), e))

    selected_tariff = request.GET.get('selected_tariff')
    if selected_tariff:
        selected_tariff = get_object_or_404(Tariff, pk=selected_tariff)

    return render(
        request, 'abonapp/buy_tariff.html', {
            'tariffs': tariffs,
            'abon': abon,
            'group': grp,
            'selected_tariff': selected_tariff
        })
예제 #6
0
 def post(self, request, *args, **kwargs):
     self.object = self.get_object()
     abon = self.object
     try:
         if abon.ip_address:
             abon.free_ip_addr()
             customer_nas_command.delay(abon.pk, 'remove')
             messages.success(request, _('Ip lease has been freed'))
         else:
             messages.error(request, _('User not have ip'))
     except OperationalError as e:
         messages.error(request, e)
     return redirect('abonapp:abon_home',
                     gid=self.kwargs.get('gid'),
                     uname=self.kwargs.get('uname'))
예제 #7
0
파일: views.py 프로젝트: bashmak/djing
def pick_tariff(request, gid: int, uname):
    grp = get_object_or_404(Group, pk=gid)
    abon = get_object_or_404(models.Abon, username=uname)
    tariffs = Tariff.objects.get_tariffs_by_group(grp.pk)
    try:
        if request.method == 'POST':
            trf = Tariff.objects.get(pk=request.POST.get('tariff'))
            deadline = request.POST.get('deadline')
            log_comment = _(
                "Service '%(service_name)s' "
                "has connected via admin until %(deadline)s") % {
                    'service_name': trf.title,
                    'deadline': deadline
                    }
            if deadline:
                deadline = datetime.strptime(deadline, '%Y-%m-%dT%H:%M')
                abon.pick_tariff(trf, request.user, deadline=deadline,
                                 comment=log_comment)
            else:
                abon.pick_tariff(trf, request.user, comment=log_comment)
            customer_nas_command.delay(abon.pk, 'sync')
            messages.success(request, _('Tariff has been picked'))
            return redirect('abonapp:abon_services', gid=gid,
                            uname=abon.username)
    except (lib.LogicError, NasFailedResult) as e:
        messages.error(request, e)
    except NasNetworkError as e:
        messages.error(request, e)
        return redirect('abonapp:abon_services', gid=gid, uname=abon.username)
    except Tariff.DoesNotExist:
        messages.error(request, _('Tariff your picked does not exist'))
    except lib.MultipleException as errs:
        for err in errs.err_list:
            messages.error(request, err)
    except ValueError as e:
        messages.error(request, "%s: %s" % (_('fix form errors'), e))

    selected_tariff = request.GET.get('selected_tariff')
    if selected_tariff:
        selected_tariff = get_object_or_404(Tariff, pk=selected_tariff)

    return render(request, 'abonapp/buy_tariff.html', {
        'tariffs': tariffs,
        'abon': abon,
        'group': grp,
        'selected_tariff': selected_tariff
    })
예제 #8
0
파일: views.py 프로젝트: bashmak/djing
 def form_valid(self, form):
     r = super(IpUpdateView, self).form_valid(form)
     abon = self.object
     customer_nas_command.delay(abon.pk, 'sync')
     messages.success(self.request, _('Ip successfully updated'))
     return r
예제 #9
0
파일: views.py 프로젝트: bashmak/djing
 def form_valid(self, form):
     r = super(AbonHomeUpdateView, self).form_valid(form)
     abon = self.object
     customer_nas_command.delay(abon.pk, 'sync')
     messages.success(self.request, _('edit abon success msg'))
     return r