Commits

Kevin Veroneau  committed 3296926

Updated PCBank app to be compatible with newer versions of Django.

  • Participants
  • Parent commits c4ed59d

Comments (0)

Files changed (4)

File pcbank/forms.py

 from django import forms
-from pcbank.models import Bill, Cheque
+from pcbank.models import Bill, Cheque, Income, CreditCard, Payee, Bank,\
+    Roommate
+
+class IncomeForm(forms.ModelForm):
+    class Meta:
+        model = Income
+
+class CreditCardForm(forms.ModelForm):
+    class Meta:
+        model = CreditCard
+
+class PayeeForm(forms.ModelForm):
+    class Meta:
+        model = Payee
+
+class BillForm(forms.ModelForm):
+    class Meta:
+        model = Bill
+
+class BankForm(forms.ModelForm):
+    class Meta:
+        model = Bank
+
+class RoommateForm(forms.ModelForm):
+    class Meta:
+        model = Roommate
 
 class NewBillForm(forms.ModelForm):
     class Meta:

File pcbank/templates/pcbank/base.html

     <title>Kevin's PC Bank</title>
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!-- Le styles -->
-    <link href="{{STATIC_URL}}css/bootstrap.min.css" rel="stylesheet">
+    <link href="http://c286041.r41.cf1.rackcdn.com/css/bootstrap.min.css" rel="stylesheet">
     <style>
       body {
         padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
       }
     </style>
-    <link href="{{STATIC_URL}}css/bootstrap-responsive.min.css" rel="stylesheet">
+    <link href="http://c286041.r41.cf1.rackcdn.com/css/bootstrap-responsive.min.css" rel="stylesheet">
     <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
     <!--[if lt IE 9]>
       <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
             <span class="icon-bar"></span>
             <span class="icon-bar"></span>
           </a>
-          <a class="brand" href="{% url pcbank.views.overview %}">PCBank</a>
+          <a class="brand" href="/myFinance/">myFinance</a>
           <div class="nav-collapse">
             <ul class="nav">
-              <li><a href="{% url pcbank.views.overview %}">Home</a></li>
+              <li><a href="{% url pcbank-overview %}">Home</a></li>
               <li class="dropdown">
                 <a href="#" class="dropdown-toggle" data-toggle="dropdown">New<b class="caret"></b></a>
                 <ul class="dropdown-menu">
                   <li><a href="{% url add-income %}">Income</a></li>
                   <li><a href="{% url add-cc %}">Credit Card</a></li>
                   <li><a href="{% url add-payee %}">Payee</a></li>
-                  <li><a href="{% url add-bill %}">Bill</a></li>
                   <li><a href="{% url add-bank %}">Bank</a></li>
                   <li><a href="{% url add-cheque %}">Cheque</a></li>
                   <li><a href="{% url add-roommate %}">Roommate</a></li>
           <div class="well sidebar-nav">
             <ul class="nav nav-list">
               <li class="nav-header">Kevin's PC Bank</li>
-              <li><a href="{% url pcbank.views.overview %}">Home</a></li>
+              <li><a href="{% url pcbank-overview %}">Home</a></li>
               <li><a href="{% url list-income %}">Income</a></li>
               <li><a href="{% url list-cc %}">Credit Cards</a></li>
               <li><a href="{% url list-payee %}">Payees</a></li>
       <div class="row-fluid">
         <div class="span12">
         <center><address>
-<a href="http://www.python.org/">Python</a> Powered | &copy; 2012 Kevin Veroneau
+<a href="http://www.python.org/">Python</a> Powered | &copy; 2012-2014 Kevin Veroneau
         </address></center>
         </div>
       </div>
     </div> <!-- /container -->
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
-    <script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/bootstrap-dropdown.js"></script>
+    <script type="text/javascript" src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-dropdown.js"></script>
     <!-- Le javascript
     ================================================== -->
     <!-- Placed at the end of the document so the pages load faster

File pcbank/urls.py

-# -*- coding: utf-8 -*-
-from django.conf.urls.defaults import patterns, url
-from pcbank.models import Income, CreditCard, Payee, Bill, Bank, Transaction, Roommate, RoommateBill,\
-    Cheque
-from pcbank.forms import NewBillForm, NewChequeForm
+from django.conf.urls import patterns, url, include
 from pcbank.feeds import BankingBookmarks
-from pcbank.views import ChequeDetail
+from pcbank.views import ChequeDetail, IncomeList, AddIncome, UpdateIncome,\
+    IncomeDetail, CreditCardList, AddCreditCard, UpdateCreditCard,\
+    CreditCardDetail, PayeeList, AddPayee, UpdatePayee, PayeeDetail, BillList,\
+    UpdateBill, BillDetail, BankList, AddBank, UpdateBank, BankDetail,\
+    ChequeList, AddCheque, RoommateList, AddRoommate, UpdateRoommate,\
+    RoommateDetail, TransactionList, TransactionDetail, RoommateBillList,\
+    RoommateBillDetail
+
+income_urls = patterns('pcbank.views',
+    url(r'^add.py$', AddIncome.as_view(), name='add-income'),
+    url(r'^$', IncomeList.as_view(), name='list-income'),
+    url(r'^(?P<pk>\d+)/edit.py$', UpdateIncome.as_view(), name='edit-income'),
+    url(r'^(?P<pk>\d+)/$', IncomeDetail.as_view(), name='view-income'),
+    url(r'^(?P<object_id>\d+)/payday.py$', 'payday'),
+)
+
+cc_urls = patterns('pcbank.views',
+    url(r'^add.py$', AddCreditCard.as_view(), name='add-cc'),
+    url(r'^$', CreditCardList.as_view(), name='list-cc'),
+    url(r'^(?P<pk>\d+)/edit.py$', UpdateCreditCard.as_view(), name='edit-cc'),
+    url(r'^(?P<pk>\d+)/$', CreditCardDetail.as_view(), name='view-cc'),
+    url(r'^table.py$', 'credit_table'),
+)
+
+payee_urls = patterns('pcbank.views',
+    url(r'^add.py$', AddPayee.as_view(), name='add-payee'),
+    url(r'^$', PayeeList.as_view(), name='list-payee'),
+    url(r'^(?P<pk>\d+)/edit.py$', UpdatePayee.as_view(), name='edit-payee'),
+    url(r'^(?P<pk>\d+)/$', PayeeDetail.as_view(), name='view-payee'),
+    url(r'^(?P<object_id>\d+)/add_bill.py$', 'add_bill'),
+)
+
+bill_urls = patterns('pcbank.views',
+    url(r'^$', BillList.as_view(), name='list-bill'),
+    url(r'^(?P<pk>\d+)/edit.py$', UpdateBill.as_view(), name='edit-bill'),
+    url(r'^(?P<pk>\d+)/$', BillDetail.as_view(), name='view-bill'),
+    url(r'^table.py$', 'bill_table'),
+    url(r'^(?P<object_id>\d+)/mark_paid.py$', 'mark_paid'),
+    url(r'^(?P<object_id>\d+)/bank_payment.py$', 'make_bank_payment'),
+    url(r'^(?P<object_id>\d+)/cc_payment.py$', 'make_cc_payment'),
+)
+
+bank_urls = patterns('pcbank.views',
+    url(r'^add.py$', AddBank.as_view(), name='add-bank'),
+    url(r'^$', BankList.as_view(), name='list-bank'),
+    url(r'^(?P<pk>\d+)/edit.py$', UpdateBank.as_view(), name='edit-bank'),
+    url(r'^(?P<pk>\d+)/$', BankDetail.as_view(), name='view-bank'),
+    url(r'^(?P<object_id>\d+)/transfer.py$', 'bank_transfer', name='bank-transfer'),
+)
+
+cb_urls = patterns('pcbank.views',
+    url(r'^$', ChequeList.as_view(), name='list-cheques'),
+    url(r'^add.py$', AddCheque.as_view(), name='add-cheque'),
+    url(r'^(?P<cheque_id>\d+)/assign_transaction.py$', 'assign_transaction', name='assign-transaction'),
+    url(r'^(?P<slug>\d+)/$', ChequeDetail.as_view(), name='view-cheque'),
+    url(r'^(?P<cheque_id>\d+)/upload_cheque.py$', 'upload_cheque', name='upload-cheque'),
+)
+
+roommate_urls = patterns('pcbank.views',
+    url(r'^add.py$', AddRoommate.as_view(), name='add-roommate'),
+    url(r'^$', RoommateList.as_view(), name='list-roommate'),
+    url(r'^(?P<pk>\d+)/edit.py$', UpdateRoommate.as_view(), name='edit-roommate'),
+    url(r'^(?P<pk>\d+)/$', RoommateDetail.as_view(), name='view-roommate'),
+    url(r'^(?P<object_id>\d+)/add_bill.py$', 'add_roommatebill'),
+)
 
 urlpatterns = patterns('pcbank.views',
-    (r'^$', 'overview'),
-    url(r'^Income/add.py$', 'create', {'model':Income}, name='add-income'),
-    url(r'^Income/$', 'show_list', {'queryset':Income.objects.filter(active=True)}, name='list-income'),
-    url(r'^Income/(?P<object_id>\d+)/edit.py$', 'update', {'model':Income}, name='edit-income'),
-    url(r'^Income/(?P<object_id>\d+)/$', 'details', {'queryset':Income.objects.all()}, name='view-income'),
-    url(r'^CreditCard/add.py$', 'create', {'model':CreditCard}, name='add-cc'),
-    url(r'^CreditCard/$', 'show_list', {'queryset':CreditCard.objects.filter(active=True)}, name='list-cc'),
-    url(r'^CreditCard/(?P<object_id>\d+)/edit.py$', 'update', {'model':CreditCard}, name='edit-cc'),
-    url(r'^CreditCard/(?P<object_id>\d+)/$', 'details', {'queryset':CreditCard.objects.all()}, name='view-cc'),
-    url(r'^Payee/add.py$', 'create', {'model':Payee}, name='add-payee'),
-    url(r'^Payee/$', 'show_list', {'queryset':Payee.objects.filter(active=True)}, name='list-payee'),
-    url(r'^Payee/(?P<object_id>\d+)/edit.py$', 'update', {'model':Payee}, name='edit-payee'),
-    url(r'^Payee/(?P<object_id>\d+)/$', 'details', {'queryset':Payee.objects.all(), 'extra_context':{'form':NewBillForm()}}, name='view-payee'),
-    url(r'^Bill/add.py$', 'create', {'model':Bill}, name='add-bill'),
-    url(r'^Bill/$', 'show_list', {'queryset':Bill.objects.filter(paid=False)}, name='list-bill'),
-    url(r'^Bill/(?P<object_id>\d+)/edit.py$', 'update', {'model':Bill}, name='edit-bill'),
-    url(r'^Bill/(?P<object_id>\d+)/$', 'details', {'queryset':Bill.objects.all()}, name='view-bill'),
-    url(r'^Bank/add.py$', 'create', {'model':Bank}, name='add-bank'),
-    url(r'^Bank/$', 'show_list', {'queryset':Bank.objects.filter(active=True)}, name='list-bank'),
-    url(r'^Bank/(?P<object_id>\d+)/edit.py$', 'update', {'model':Bank}, name='edit-bank'),
-    url(r'^Bank/(?P<object_id>\d+)/$', 'details', {'queryset':Bank.objects.all()}, name='view-bank'),
-    url(r'^Transaction/$', 'show_list', {'queryset':Transaction.objects.all(),'paginate_by':20}, name='list-transaction'),
-    url(r'^Transaction/(?P<object_id>\d+)/$', 'details', {'queryset':Transaction.objects.all()}, name='view-transaction'),
-    url(r'^ChequeBook/$', 'show_list', {'queryset':Cheque.objects.all()}, name='list-cheques'),
-    url(r'^ChequeBook/add.py$', 'create', {'model':Cheque, 'form_class':NewChequeForm}, name='add-cheque'),
-    url(r'^ChequeBook/(?P<cheque_id>\d+)/assign_transaction.py$', 'assign_transaction', name='assign-transaction'),
-    url(r'^ChequeBook/(?P<slug>\d+)/$', ChequeDetail.as_view(), name='view-cheque'),
-    url(r'^ChequeBook/(?P<cheque_id>\d+)/upload_cheque.py$', 'upload_cheque', name='upload-cheque'),
-    url(r'^Roommate/add.py$', 'create', {'model':Roommate}, name='add-roommate'),
-    url(r'^Roommate/$', 'show_list', {'queryset':Roommate.objects.filter(active=True)}, name='list-roommate'),
-    url(r'^Roommate/(?P<object_id>\d+)/edit.py$', 'update', {'model':Roommate}, name='edit-roommate'),
-    url(r'^Roommate/(?P<object_id>\d+)/$', 'details', {'queryset':Roommate.objects.all()}, name='view-roommate'),
-    url(r'^RoommateBill/$', 'show_list', {'queryset':RoommateBill.objects.all()}, name='list-roommatebill'),
-    url(r'^RoommateBill/(?P<object_id>\d+)/$', 'details', {'queryset':RoommateBill.objects.all()}, name='view-roommatebill'),
-    (r'^CreditCard/table.py$', 'credit_table'),
-    (r'^Bill/table.py$', 'bill_table'),
-    (r'^Bill/(?P<object_id>\d+)/mark_paid.py$', 'mark_paid'),
-    (r'^Income/(?P<object_id>\d+)/payday.py$', 'payday'),
-    (r'^Bill/(?P<object_id>\d+)/bank_payment.py$', 'make_bank_payment'),
-    (r'^Bill/(?P<object_id>\d+)/cc_payment.py$', 'make_cc_payment'),
-    (r'^Payee/(?P<object_id>\d+)/add_bill.py$', 'add_bill'),
-    (r'^Roommate/(?P<object_id>\d+)/add_bill.py$', 'add_roommatebill'),
-    (r'^RoommateBill/(?P<object_id>\d+)/payment.py$', 'roommate_payment'),
-    url(r'^Bank/(?P<object_id>\d+)/transfer.py$', 'bank_transfer', name='bank-transfer'),
+    url(r'^$', 'overview', name='pcbank-overview'),
+    url(r'^Income/', include(income_urls)),
+    url(r'^CreditCard/', include(cc_urls)),
+    url(r'^Payee/', include(payee_urls)),
+    url(r'^Bill/', include(bill_urls)),
+    url(r'^Bank/', include(bank_urls)),
+    url(r'^Transaction/$', TransactionList.as_view(), name='list-transaction'),
+    url(r'^Transaction/(?P<pk>\d+)/$', TransactionDetail.as_view(), name='view-transaction'),
+    url(r'^ChequeBook/', include(cb_urls)),
+    url(r'^Roommate/', include(roommate_urls)),
+    url(r'^RoommateBill/$', RoommateBillList.as_view(), name='list-roommatebill'),
+    url(r'^RoommateBill/(?P<pk>\d+)/$', RoommateBillDetail.as_view(), name='view-roommatebill'),
+    url(r'^RoommateBill/(?P<object_id>\d+)/payment.py$', 'roommate_payment'),
     url(r'^MonthlyBudget.py$', 'monthly_budget', name='monthly-budget'),
-    (r'^Service.py$', 'json_service'),
-    (r'^Bookmarks.rss$', BankingBookmarks()),
+    url(r'^Service.py$', 'json_service'),
+    url(r'^Bookmarks.rss$', BankingBookmarks()),
 )

File pcbank/views.py

-# -*- coding: utf-8 -*-
 from django.core.exceptions import PermissionDenied
-from django.views.generic.create_update import create_object, update_object, delete_object
-from django.views.generic.list_detail import object_list, object_detail
-from django.views.generic.simple import direct_to_template
 from pcbank.models import CreditCard, Bill, Income, Bank, Payee, Transaction, Roommate, RoommateBill,\
     Cheque
 from decimal import Decimal
 from django.shortcuts import render_to_response, redirect
-from pcbank.forms import NewBillForm, UploadChequeForm
+from pcbank.forms import NewBillForm, UploadChequeForm, IncomeForm,\
+    CreditCardForm, PayeeForm, BillForm, BankForm, NewChequeForm, RoommateForm
 from django.template import RequestContext
 import datetime
 from django.contrib.auth.decorators import login_required
 from django.utils import simplejson
 from django.views.generic.detail import DetailView
 from django.contrib import messages
+from django.views.generic.list import ListView
+from django.views.generic.edit import CreateView, UpdateView
 
 class SuperMixin(object):
     def dispatch(self, request, *args, **kwargs):
             raise PermissionDenied
         return super(SuperMixin, self).dispatch(request, *args, **kwargs)
 
+class ListActive(ListView):
+    def get_queryset(self):
+        return super(ListActive, self).get_queryset().filter(active=True)
+
+class IncomeList(SuperMixin, ListActive):
+    model = Income
+
+class AddIncome(SuperMixin, CreateView):
+    model = Income
+    form_class = IncomeForm
+
+class UpdateIncome(SuperMixin, UpdateView):
+    model = Income
+    form_class = IncomeForm
+
+class IncomeDetail(SuperMixin, DetailView):
+    model = Income
+
+class CreditCardList(SuperMixin, ListActive):
+    model = CreditCard
+
+class AddCreditCard(SuperMixin, CreateView):
+    model = CreditCard
+    form_class = CreditCardForm
+
+class UpdateCreditCard(SuperMixin, UpdateView):
+    model = CreditCard
+    form_class = CreditCardForm
+
+class CreditCardDetail(SuperMixin, DetailView):
+    model = CreditCard
+
+class PayeeList(SuperMixin, ListActive):
+    model = Payee
+
+class AddPayee(SuperMixin, CreateView):
+    model = Payee
+    form_class = PayeeForm
+
+class UpdatePayee(SuperMixin, UpdateView):
+    model = Payee
+    form_class = PayeeForm
+
+class PayeeDetail(SuperMixin, DetailView):
+    model = Payee
+    def get_context_data(self, **kwargs):
+        ctx = super(PayeeDetail, self).get_context_data(**kwargs)
+        ctx.update({'form':NewBillForm()})
+        return ctx
+
+class BillList(SuperMixin, ListView):
+    model = Bill
+    def get_queryset(self):
+        return super(BillList, self).get_queryset().filter(paid=False)
+
+class UpdateBill(SuperMixin, UpdateView):
+    model = Bill
+    form_class = BillForm
+
+class BillDetail(SuperMixin, DetailView):
+    model = Bill
+
+class BankList(SuperMixin, ListActive):
+    model = Bank
+
+class AddBank(SuperMixin, CreateView):
+    model = Bank
+    form_class = BankForm
+
+class UpdateBank(SuperMixin, UpdateView):
+    model = Bank
+    form_class = BankForm
+
+class BankDetail(SuperMixin, DetailView):
+    model = Bank
+
+class ChequeList(SuperMixin, ListView):
+    model = Cheque
+
+class AddCheque(SuperMixin, CreateView):
+    model = Cheque
+    form_class = NewChequeForm
+
 class ChequeDetail(SuperMixin, DetailView):
     model = Cheque
     slug_field = 'number'
         kwargs.update({'form':UploadChequeForm()})
         return super(ChequeDetail, self).get_context_data(**kwargs)
 
+class RoommateList(SuperMixin, ListActive):
+    model = Roommate
+
+class AddRoommate(SuperMixin, CreateView):
+    model = Roommate
+    form_class = RoommateForm
+
+class UpdateRoommate(SuperMixin, UpdateView):
+    model = Roommate
+    form_class = RoommateForm
+
+class RoommateDetail(SuperMixin, DetailView):
+    model = Roommate
+
+class TransactionList(SuperMixin, ListView):
+    model = Transaction
+    paginate_by = 20
+
+class TransactionDetail(SuperMixin, DetailView):
+    model = Transaction
+
+class RoommateBillList(SuperMixin, ListView):
+    model = RoommateBill
+
+class RoommateBillDetail(SuperMixin, DetailView):
+    model = RoommateBill
+
 @login_required
 def overview(req):
     if not req.user.is_superuser:
     return render_to_response('pcbank/index.html', {'income':total_income, 'bills':bills, 'credit':credit, 'debt':debt, 'worth':worth, 'available_funds':available_funds, 'roommate_due':roommate_due})
 
 @login_required
-def create(req, *args, **kwargs):
-    if not req.user.is_superuser:
-        raise PermissionDenied
-    return create_object(req, *args, **kwargs)
-
-@login_required
-def update(req, *args, **kwargs):
-    if not req.user.is_superuser:
-        raise PermissionDenied
-    return update_object(req, *args, **kwargs)
-
-@login_required
-def delete(req, *args, **kwargs):
-    if not req.user.is_superuser:
-        raise PermissionDenied
-    return delete_object(req, *args, **kwargs)
-
-@login_required
-def show_list(req, *args, **kwargs):
-    if not req.user.is_superuser:
-        raise PermissionDenied
-    return object_list(req, *args, **kwargs)
-
-@login_required
-def details(req, *args, **kwargs):
-    if not req.user.is_superuser:
-        raise PermissionDenied
-    return object_detail(req, *args, **kwargs)
-
-@login_required
-def flatpage(req, *args, **kwargs):
-    if not req.user.is_superuser:
-        raise PermissionDenied
-    return direct_to_template(req, *args, **kwargs)
-
-@login_required
 def credit_table(req):
     if not req.user.is_superuser:
         raise PermissionDenied