From 092d1279e5b1b12332eb3a98d7615e2dee988903 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sun, 6 May 2012 08:12:53 +0200 Subject: [PATCH] Lots of development --- invoice/admin.py | 7 ++ invoice/forms.py | 11 +++ invoice/models.py | 7 +- invoice/urls.py | 16 ++++ invoice/views.py | 62 +++++++++++++++- peojumk/settings.py | 1 + peojumk/urls.py | 4 +- templates/base.html | 77 ++++++++++++++++++++ templates/base_site.html | 10 +++ templates/invoice/client_confirm_delete.html | 13 ++++ templates/invoice/client_detail.html | 14 ++++ templates/invoice/client_form.html | 12 +++ templates/invoice/index.html | 18 +++++ templates/invoice/invoice_form.html | 12 +++ templates/registration/login.html | 57 +++++++++++++++ 15 files changed, 316 insertions(+), 5 deletions(-) create mode 100644 invoice/admin.py create mode 100644 invoice/forms.py create mode 100644 invoice/urls.py create mode 100644 templates/base.html create mode 100644 templates/base_site.html create mode 100644 templates/invoice/client_confirm_delete.html create mode 100644 templates/invoice/client_detail.html create mode 100644 templates/invoice/client_form.html create mode 100644 templates/invoice/index.html create mode 100644 templates/invoice/invoice_form.html create mode 100644 templates/registration/login.html diff --git a/invoice/admin.py b/invoice/admin.py new file mode 100644 index 0000000..89d2555 --- /dev/null +++ b/invoice/admin.py @@ -0,0 +1,7 @@ +from invoice.models import Client, Invoice, InvoiceLine, VAT +from django.contrib import admin + +admin.site.register(Client) +admin.site.register(Invoice) +admin.site.register(InvoiceLine) +admin.site.register(VAT) diff --git a/invoice/forms.py b/invoice/forms.py new file mode 100644 index 0000000..438b6b3 --- /dev/null +++ b/invoice/forms.py @@ -0,0 +1,11 @@ +from django.forms import ModelForm +from invoice.models import Client, Invoice +from django.views.generic.edit import ModelFormMixin + +class ClientForm(ModelFormMixin, ModelForm): + class Meta: + model = Client + +class InvoiceForm(ModelFormMixin, ModelForm): + class Meta: + model = Invoice diff --git a/invoice/models.py b/invoice/models.py index 3129dd0..8ec1945 100644 --- a/invoice/models.py +++ b/invoice/models.py @@ -7,6 +7,9 @@ class Client(models.Model): email = models.CharField(max_length=100) address = models.TextField() + def __unicode__(self): + return '%s' % self.name + INVOICE_STATUS_CHOICES = ( ('N', 'New'), ('S', 'Sent'), @@ -28,8 +31,8 @@ class VAT(models.Model): decimal_places=2) class Meta: - verbose_name = _('tax') - verbose_name_plural = _('taxes') + verbose_name = _('VAT level') + verbose_name_plural = _('VAT levels') def __unicode__(self): return '%s' % self.name diff --git a/invoice/urls.py b/invoice/urls.py new file mode 100644 index 0000000..f7b5850 --- /dev/null +++ b/invoice/urls.py @@ -0,0 +1,16 @@ +from django.conf.urls import patterns, include, url +import django.contrib.auth.views +from invoice.views import UpdateClient, DeleteClient, CreateClient, DetailClient, \ + CreateInvoice + +import invoice.views + +urlpatterns = patterns('invoice.views', + url(r'^$', 'index'), + url(r'^client/new$', CreateClient.as_view()), + url(r'^client/(?P\d+)$', DetailClient.as_view()), + url(r'^client/(?P\d+)/edit$', UpdateClient.as_view(), name='c_edit'), + url(r'^client/(?P\d+)/delete$', DeleteClient.as_view(), name='c_delete'), + url(r'^accounts/login/$', django.contrib.auth.views.login), + url(r'^invoice/new$', CreateInvoice.as_view(), name="invoice_new"), +) diff --git a/invoice/views.py b/invoice/views.py index 60f00ef..283ee07 100644 --- a/invoice/views.py +++ b/invoice/views.py @@ -1 +1,61 @@ -# Create your views here. +from django.shortcuts import render_to_response, get_object_or_404 +from django.contrib.auth.decorators import login_required, permission_required +from django.http import HttpResponse +from django.forms.models import inlineformset_factory +from django.template import RequestContext +from django.views.generic.create_update import get_model_and_form_class, apply_extra_context, redirect, update_object, lookup_object, delete_object +from django.views.generic import UpdateView, DeleteView, CreateView, DetailView +from django.utils.decorators import method_decorator + +from invoice.models import Client, Invoice +from invoice.forms import ClientForm, InvoiceForm + +@login_required +def index(request): + clients = Client.objects.all() + return render_to_response('invoice/index.html', {'clients': clients}) + +class DetailClient(DetailView): + model = Client + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(DetailView, self).dispatch(*args, **kwargs) + +class CreateClient(CreateView): + model = Client + form_class = ClientForm + success_url = '/' + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(CreateClient, self).dispatch(*args, **kwargs) + +class UpdateClient(UpdateView): + model = Client + form_class = ClientForm + success_url = '/' + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(UpdateClient, self).dispatch(*args, **kwargs) + +class DeleteClient(DeleteView): + model = Client + form_class = ClientForm + success_url = '/' + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(DeleteClient, self).dispatch(*args, **kwargs) + + +# ------------------- INVOICE --------------- +class CreateInvoice(CreateView): + model = Invoice + form_class = InvoiceForm + success_url = '/' + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(CreateInvoice, self).dispatch(*args, **kwargs) + diff --git a/peojumk/settings.py b/peojumk/settings.py index db5c415..15df212 100644 --- a/peojumk/settings.py +++ b/peojumk/settings.py @@ -111,6 +111,7 @@ TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. + os.path.abspath(os.path.join(os.path.dirname(__file__))) + "/../templates", ) INSTALLED_APPS = ( diff --git a/peojumk/urls.py b/peojumk/urls.py index 19c58aa..0cda338 100644 --- a/peojumk/urls.py +++ b/peojumk/urls.py @@ -1,12 +1,11 @@ from django.conf.urls import patterns, include, url -# Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Examples: - # url(r'^$', 'peojumk.views.home', name='home'), + #url(r'^$', 'invoice.views.home', name='home'), # url(r'^peojumk/', include('peojumk.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: @@ -14,4 +13,5 @@ urlpatterns = patterns('', # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), + url(r'^', include('invoice.urls', namespace='invoice')), ) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..28bd966 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,77 @@ +{% load admin_static %}{% load url from future %} + + +{% block title %}{% endblock %} + +{% block extrastyle %}{% endblock %} + +{% if LANGUAGE_BIDI %}{% endif %} + +{% block extrahead %}{% endblock %} +{% block blockbots %}{% endblock %} + +{% load i18n %} + + + + +
+ + {% if not is_popup %} + + + + {% block breadcrumbs %} + + {% endblock %} + {% endif %} + + {% block messages %} + {% if messages %} +
    {% for message in messages %} + {{ message }} + {% endfor %}
+ {% endif %} + {% endblock messages %} + + +
+ {% block pretitle %}{% endblock %} + {% block content_title %}{% if title %}

{{ title }}

{% endif %}{% endblock %} + {% block content %} + {% block object-tools %}{% endblock %} + {{ content }} + {% endblock %} + {% block sidebar %}{% endblock %} +
+
+ + + {% block footer %}{% endblock %} +
+ + + + diff --git a/templates/base_site.html b/templates/base_site.html new file mode 100644 index 0000000..4b891d4 --- /dev/null +++ b/templates/base_site.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% load i18n %} + +{% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %} + +{% block branding %} +

{% trans 'Invoices' %}

+{% endblock %} + +{% block nav-global %}{% endblock %} diff --git a/templates/invoice/client_confirm_delete.html b/templates/invoice/client_confirm_delete.html new file mode 100644 index 0000000..8421346 --- /dev/null +++ b/templates/invoice/client_confirm_delete.html @@ -0,0 +1,13 @@ +{% extends "base_site.html" %} + +{% block content %} + +Are you sure you want to delete the client named {{client.name}} ? + +
+{% csrf_token %} + + +
+ +{% endblock %} diff --git a/templates/invoice/client_detail.html b/templates/invoice/client_detail.html new file mode 100644 index 0000000..84e12d7 --- /dev/null +++ b/templates/invoice/client_detail.html @@ -0,0 +1,14 @@ +{% extends "base_site.html" %} + +{% block content %} + +
    +
  • Client: {{client.name}}
  • +
  • Email: {{client.email}}
  • +
  • Address:
    {{client.address}}
  • +
+ +Edit +Delete + +{% endblock %} diff --git a/templates/invoice/client_form.html b/templates/invoice/client_form.html new file mode 100644 index 0000000..984348f --- /dev/null +++ b/templates/invoice/client_form.html @@ -0,0 +1,12 @@ +{% extends "base_site.html" %} + +{% block content %} + +
+{% csrf_token %} +
    + {{ form.as_ul}} +
+ +
+{% endblock %} diff --git a/templates/invoice/index.html b/templates/invoice/index.html new file mode 100644 index 0000000..2e951db --- /dev/null +++ b/templates/invoice/index.html @@ -0,0 +1,18 @@ +{% extends "base_site.html" %} + +{% block content %} + +New invoice + +
    +{% if clients %} + {% for c in clients %} +
  • {{ c.name }}
  • + {% endfor %} +{% else %} +

    No clients.

    +{% endif %} +
  • New client
  • +
+ +{% endblock %} diff --git a/templates/invoice/invoice_form.html b/templates/invoice/invoice_form.html new file mode 100644 index 0000000..984348f --- /dev/null +++ b/templates/invoice/invoice_form.html @@ -0,0 +1,12 @@ +{% extends "base_site.html" %} + +{% block content %} + +
+{% csrf_token %} +
    + {{ form.as_ul}} +
+ +
+{% endblock %} diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..92c85d6 --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,57 @@ +{% extends "base_site.html" %} +{% load i18n admin_static %} +{% load url from future %} + +{% block extrastyle %}{{ block.super }}{% endblock %} + +{% block bodyclass %}login{% endblock %} + +{% block nav-global %}{% endblock %} + +{% block content_title %}{% endblock %} + +{% block breadcrumbs %}{% endblock %} + +{% block content %} +{% if form.errors and not form.non_field_errors and not form.this_is_the_login_form.errors %} +

+{% blocktrans count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} +

+{% endif %} + +{% if form.non_field_errors or form.this_is_the_login_form.errors %} +{% for error in form.non_field_errors|add:form.this_is_the_login_form.errors %} +

+ {{ error }} +

+{% endfor %} +{% endif %} + +
+
{% csrf_token %} +
+ {% if not form.this_is_the_login_form.errors %}{{ form.username.errors }}{% endif %} + {{ form.username }} +
+
+ {% if not form.this_is_the_login_form.errors %}{{ form.password.errors }}{% endif %} + {{ form.password }} + + +
+ {% url 'admin_password_reset' as password_reset_url %} + {% if password_reset_url %} + + {% endif %} +
+ +
+
+ + +
+{% endblock %} -- 2.39.5