示例#1
0
def login(request, *args, **kwargs):
    if not request.user.is_authenticated():
        return auth_login(request, *args, **kwargs)
    else:
        if checkCredentials(request):
            return HttpResponseRedirect(reverse('meter-readings-add'))
        return HttpResponseRedirect(reverse('home'))
示例#2
0
def login(request, *args, **kwargs):
    if not request.user.is_authenticated():
        return auth_login(request, *args, **kwargs)
    else:
        if checkCredentials(request):
            return HttpResponseRedirect(reverse('meter-readings-add'))
        return HttpResponseRedirect(reverse('home'))
示例#3
0
def payment_mode (request, pk=None, action=None, template_name="payments/payment_mode_form.html"):
    data = {}
    if request.method == "GET":
        if action in ("create", "read", "update"):
            if pk:
                data['paymentMode'] = get_object_or_404(PaymentMode, pk=pk)
                if action == "update":
                    paymentModeForm = PaymentModeForm(instance=get_object_or_404(PaymentMode, pk=pk))
            else:
                paymentModeForm = PaymentModeForm()
    elif request.method == "POST":
        if action in ("create", "update"):
            if pk:
                paymentModeForm = PaymentModeForm(request.POST, instance=get_object_or_404(PaymentMode, pk=pk))
            else:
                paymentModeForm = PaymentModeForm(request.POST)
            if paymentModeForm.is_valid():
                paymentMode = paymentModeForm.save(commit=False)
                paymentMode.save()
                return HttpResponseRedirect(reverse("payment-mode-details", args=[paymentMode.pk]))
        else:
            paymentMode = get_object_or_404(PaymentMode, pk=pk)
            paymentMode.delete()
    if action in ("create", "update"):
        data['paymentModeForm'] = paymentModeForm
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return render_to_response(template_name, data, context_instance=RequestContext(request))
示例#4
0
def active_accounts(request):
    data = {}
    data['active_accounts'] = get_list_or_404(Account, is_active = True)
    data['pagesize'] = 'A4'
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return make_pdf("reports/active_accounts.html", data)
示例#5
0
def account(request,
            pk=None,
            action=None,
            template_name="consumer/consumer_account.html"):
    data = {}
    if request.method == "GET":
        if pk:
            data['account'] = get_object_or_404(Account, pk=pk)
            accountForm = AccountForm(
                instance=get_object_or_404(Account, pk=pk))
    if request.method == "POST":
        if action in ("C", "U", "R"):
            if action in ("U", "R"):
                if checkDirector(request):
                    return HttpResponseRedirect(reverse("account-list"))
            if pk:
                accountForm = AccountForm(request.POST,
                                          instance=get_object_or_404(Account,
                                                                     pk=pk))
            else:
                accountForm = AccountForm(request.POST)
            if accountForm.is_valid():
                account = accountForm.save(commit=False)
                account.date_activated = datetime.datetime.today()
                account.save()
                return HttpResponseRedirect(
                    reverse("consumer-details",
                            args=[account.application.consumer.pk]))
        elif action in ("activate", "close"):
            account = get_object_or_404(Account, pk=pk)
            if action == "activate":
                account.closed = False
                account.is_active = True
                account.date_activated = datetime.datetime.today()
            elif action == "close":
                account.closed = True
                account.is_active = False
                account.date_closed = datetime.datetime.today()
            account.save()
    if action in ("C", "U", "R"):
        if action in ("U", "R"):
            if checkDirector(request):
                return HttpResponseRedirect(reverse("account-list"))
        if action in ("C", "U"):
            if checkReceptionist(request):
                return HttpResponseRedirect(reverse("account-list"))
        data["accountForm"] = accountForm
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return render_to_response(template_name,
                                  data,
                                  context_instance=RequestContext(request))
示例#6
0
def pdf_view(request):
    template = get_template("reports/report.html")
    context = Context({'pagesize':'A4'})
    html  = template.render(context)
    result = StringIO.StringIO()
    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
    if not pdf.err:
        return http.HttpResponse(result.getvalue(), mimetype='application/pdf')
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return http.HttpResponse('We had some errors<pre>%s</pre>' % cgi.escape(html))
示例#7
0
def zone(request,
         pk=None,
         region_pk=None,
         action=None,
         template_name="meter/location_form.html"):
    data = {}
    ZoneForm = ZoneConRegionForm if region_pk else ZoneSinRegionForm
    if request.method == "GET":
        if action in ("C", "U", "R"):
            if pk:
                data['zone'] = get_object_or_404(Zone, pk=pk)
                data['subzones'] = data['zone'].subzone_set.all()
                if action == "U":
                    zoneForm = ZoneForm(
                        instance=get_object_or_404(Zone, pk=pk))
            else:
                zoneForm = ZoneForm()
    if request.method == "POST":
        if action in ("C", "U", "D"):
            if action in ("C", "U"):
                if pk:
                    zoneForm = ZoneForm(request.POST,
                                        instance=get_object_or_404(Zone,
                                                                   pk=pk))
                else:
                    zoneForm = ZoneForm(request.POST)
                if zoneForm.is_valid():
                    zone = zoneForm.save(commit=False)
                    if region_pk:
                        zone.region = get_object_or_404(Region, id=region_pk)
                    zone.save()
                    return HttpResponseRedirect(
                        reverse("zone-details", args=[zone.pk]))
            else:
                if checkReceptionist(request):
                    return HttpResponseRedirect(reverse("subzone-list"))
                zone = get_object_or_404(Zone, pk=pk)
                zone.delete()
    if action in ("C", "U"):
        if checkReceptionist(request):
            return HttpResponseRedirect(reverse("zone-list"))
        if checkDirector(request):
            return HttpResponseRedirect(reverse("zone-list"))
        data['zoneForm'] = zoneForm
        data['locationForm'] = zoneForm
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return render_to_response(template_name,
                                  data,
                                  context_instance=RequestContext(request))
示例#8
0
def invoice(request, pk=None, account=None, action=None, template_name="payments/invoice_form.html"):
    data = {}
    if account:
        data['account'] = get_object_or_404(Account, pk=account)
    if request.method == "GET":
        if action in ("create", "read"):
            if pk:
                data['invoice'] = get_object_or_404(Invoice, pk=pk)
                data['invoice_details'] = data['invoice'].invoicedetail_set.all()
    elif request.method == "POST":
        pass
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return render_to_response(template_name, data, context_instance=RequestContext(request))
示例#9
0
def account(request, pk=None, action=None, template_name="consumer/consumer_account.html"):
    data = {}
    if request.method == "GET":
        if pk:
            data['account'] = get_object_or_404(Account, pk=pk)
            accountForm = AccountForm(instance=get_object_or_404(Account, pk=pk))
    if request.method == "POST":
        if action in ("C","U", "R"):
            if action in ("U", "R"):
                if checkDirector(request):
                    return HttpResponseRedirect(reverse("account-list"))
            if pk:
                accountForm = AccountForm(request.POST, instance=get_object_or_404(Account, pk=pk))
            else:
                accountForm = AccountForm(request.POST)
            if accountForm.is_valid():
                account = accountForm.save(commit=False)
                account.date_activated = datetime.datetime.today()
                account.save()
                return HttpResponseRedirect(reverse("consumer-details", args=[account.application.consumer.pk]))
        elif action in ("activate", "close"):
            account = get_object_or_404(Account, pk=pk)
            if action == "activate":
                account.closed = False
                account.is_active = True
                account.date_activated = datetime.datetime.today()
            elif action=="close":
                account.closed = True
                account.is_active = False
                account.date_closed = datetime.datetime.today()
            account.save()
    if action in ("C","U", "R"):
        if action in ("U", "R"):
            if checkDirector(request):
                return HttpResponseRedirect(reverse("account-list"))
        if action in ("C", "U"):
            if checkReceptionist(request):
                return HttpResponseRedirect(reverse("account-list"))
        data["accountForm"] = accountForm
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return render_to_response(template_name, data, context_instance=RequestContext(request))
示例#10
0
def subzone(request, pk=None, zone_pk=None, action=None, template_name="meter/location_form.html"):
    data = {}
    SubZoneForm = SubZoneConForm if zone_pk else SubZoneSinForm
    if request.method == "GET":
        if action in ("C", "U", "R"):
            if pk:
                data['subzone'] = get_object_or_404(SubZone, pk=pk)
                data['plots'] = data['subzone'].plot_set.all()
                if action == "U":
                    subzoneForm = SubZoneForm(instance=get_object_or_404(SubZone, pk=pk))
            else:
                subzoneForm = SubZoneForm()
    if request.method == "POST":
        if action in ("C", "U", "D"):
            if action in ("C", "U"):
                if pk:
                    subzoneForm = SubZoneForm(request.POST, instance=get_object_or_404(SubZone, pk=pk))
                else:
                    subzoneForm = SubZoneForm(request.POST)
                if subzoneForm.is_valid():
                    subzone = subzoneForm.save(commit=False)
                    subzone.save()
                    return HttpResponseRedirect(reverse("subzone-details", args=[subzone.pk]))
            else:
                if checkReceptionist(request):
                    return HttpResponseRedirect(reverse("subzone-list"))
                subzone = get_object_or_404(SubZone, pk=pk)
                if zone_pk:
                    subzone.zone = get_object_or_404(Zone, id=region_pk)
                subzone.delete()
    if action in ("C", "U"):
        if checkReceptionist(request):
            return HttpResponseRedirect(reverse("subzone-list"))
        if checkDirector(request):
            return HttpResponseRedirect(reverse("subzone-list"))
        data['subzoneForm'] = subzoneForm
        data['locationForm'] = subzoneForm
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return render_to_response(template_name, data, context_instance=RequestContext(request))
示例#11
0
def region(request, pk=None, action=None, template_name="meter/location_form.html"):
    data = {}
    if request.method == "GET":
        if action in ("C", "U", "R"):
            if pk:
                data['region'] = get_object_or_404(Region, pk=pk)
                data['zones'] = data['region'].zone_set.all()
                if action == "U":
                    regionForm = RegionForm(instance=get_object_or_404(Region, pk=pk))
            else:
                regionForm = RegionForm()
    if request.method == "POST":
        if action in ("C", "U", "D"):
            if action in ("C", "U"):
                if pk:
                    regionForm = RegionForm(request.POST, instance=get_object_or_404(Region, pk=pk))
                else:
                    regionForm = RegionForm(request.POST)
                if regionForm.is_valid():
                    region= regionForm.save(commit=False)
                    region.save()
                    return HttpResponseRedirect(reverse("region-details", args=[region.pk]))
            else:
                if checkReceptionist(request):
                    return HttpResponseRedirect(reverse("subzone-list"))
                region = get_object_or_404(Region, pk=pk)
                region.delete()
    if action in ("C", "U"):
        if checkReceptionist(request):
            return HttpResponseRedirect(reverse("subzone-list"))
        if checkDirector(request):
            return HttpResponseRedirect(reverse("region-list"))
        data['regionForm'] = regionForm
        data['locationForm'] = regionForm
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return render_to_response(template_name, data, context_instance=RequestContext(request))
示例#12
0
def payment(request, pk=None, account=None, action=None, template_name="payments/payment_form.html"):
    data = {}
    if account:
        data['account'] = get_object_or_404(Account, pk=account)
    if request.method == "GET":
        if action in ("create", "read"):
            if pk:
                data['payment'] = get_object_or_404(Payment, pk=pk)
            else:
                paymentForm = PaymentForm()
    elif request.method == "POST":
        if action == "create":
            paymentForm = PaymentForm(request.POST)
            if paymentForm.is_valid():
                payment = paymentForm.save(commit=False)
                payment.account = get_object_or_404(Account, pk=account)
                payment.save()
                return HttpResponseRedirect(reverse("payment-details", args=[payment.pk]))
    if action == "create":
        data['paymentForm'] = paymentForm
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    else:
        return render_to_response(template_name, data, context_instance=RequestContext(request))
示例#13
0
def index(request):
    if checkReceptionist(request):
        return HttpResponseRedirect(reverse("consumer-list"))
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    return HttpResponseRedirect(reverse('home'))
示例#14
0
def index(request):
    if checkReceptionist(request):
        return HttpResponseRedirect(reverse("consumer-list"))
    if checkCredentials(request):
        return HttpResponseRedirect(reverse('meter-readings-add'))
    return HttpResponseRedirect(reverse('home'))