summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/expenses/admin.py7
-rw-r--r--app/expenses/build.py34
-rw-r--r--app/expenses/models.py20
-rw-r--r--app/expenses/urls.py19
-rw-r--r--app/expenses/views.py35
-rw-r--r--config/base_urls.py5
-rw-r--r--design/templates/archives/expenses.html26
7 files changed, 127 insertions, 19 deletions
diff --git a/app/expenses/admin.py b/app/expenses/admin.py
index 76af266..28c8869 100644
--- a/app/expenses/admin.py
+++ b/app/expenses/admin.py
@@ -1,6 +1,10 @@
from django.contrib import admin
-from .models import Expense
+from .models import Expense, Trip
+
+
+class TripAdmin(admin.ModelAdmin):
+ list_display = ('name', 'start')
class ExpenseAdmin(admin.ModelAdmin):
@@ -8,3 +12,4 @@ class ExpenseAdmin(admin.ModelAdmin):
list_filter = ('date', 'category')
admin.site.register(Expense, ExpenseAdmin)
+admin.site.register(Trip, TripAdmin)
diff --git a/app/expenses/build.py b/app/expenses/build.py
new file mode 100644
index 0000000..7241a70
--- /dev/null
+++ b/app/expenses/build.py
@@ -0,0 +1,34 @@
+import os
+from django.core.urlresolvers import reverse
+from builder.base import BuildNew
+
+
+class BuildExpenses(BuildNew):
+
+ def build(self):
+ self.build_detail_view()
+ self.build_list_view(
+ base_path=reverse("expenses:list_trip"),
+ paginate_by=24
+ )
+
+ def get_model_queryset(self):
+ return self.model.objects.all()
+
+ def build_detail_view(self):
+ '''
+ write out all the expenses for each trip
+ '''
+ for obj in self.get_model_queryset():
+ url = obj.get_absolute_url()
+ path, slug = os.path.split(url)
+ path = '%s/' % path
+ # write html
+ response = self.client.get(url)
+ print(path, slug)
+ self.write_file(path, response.content, filename=slug)
+
+
+def builder():
+ j = BuildExpenses("expenses", "trip")
+ j.build()
diff --git a/app/expenses/models.py b/app/expenses/models.py
index ef9352f..bca23bf 100644
--- a/app/expenses/models.py
+++ b/app/expenses/models.py
@@ -1,7 +1,6 @@
from django.db import models
+from django.core.urlresolvers import reverse
from django.utils import timezone
-from django.template.defaultfilters import slugify
-import datetime
CATS = (
('1', "Travco"),
@@ -13,12 +12,28 @@ CATS = (
('7', "Misc"),
)
+
+class Trip(models.Model):
+ name = models.CharField(max_length=200)
+ slug = models.SlugField()
+ start = models.DateTimeField(default=timezone.now, blank=True, null=True)
+ end = models.DateTimeField(default=timezone.now, blank=True, null=True)
+ dek = models.TextField(null=True, blank=True)
+
+ def __str__(self):
+ return self.name
+
+ def get_absolute_url(self):
+ return reverse("expenses:list_expense", kwargs={"slug": self.slug})
+
+
class Expense(models.Model):
name = models.CharField(max_length=200)
amount = models.DecimalField(max_digits=8, decimal_places=2)
date = models.DateTimeField(default=timezone.now)
notes = models.TextField(null=True, blank=True)
category = models.CharField(max_length=2, choices=CATS, default=1)
+ trip = models.ForeignKey(Trip, null=True)
class Meta:
ordering = ('-date',)
@@ -28,4 +43,3 @@ class Expense(models.Model):
def date_month(self):
return self.date.strftime("%b %Y")
-
diff --git a/app/expenses/urls.py b/app/expenses/urls.py
index fffdfaa..a2cf35a 100644
--- a/app/expenses/urls.py
+++ b/app/expenses/urls.py
@@ -1,7 +1,16 @@
-from django.conf.urls import *
-from django.views.generic.base import RedirectView
+from django.conf.urls import url
+from . import views
-urlpatterns = patterns('',
- url(r'travco-trip-costs/', 'expenses.views.detail'),
-)
+urlpatterns = [
+ url(
+ regex=r'(?P<slug>[-\w]+)$',
+ view=views.ExpenseListView.as_view(),
+ name='list_expense'
+ ),
+ url(
+ regex=r'^$',
+ view=views.TripListView.as_view(),
+ name='list_trip'
+ )
+]
diff --git a/app/expenses/views.py b/app/expenses/views.py
index 7442178..3a8d2cb 100644
--- a/app/expenses/views.py
+++ b/app/expenses/views.py
@@ -1,12 +1,29 @@
-from django.shortcuts import render_to_response, get_object_or_404
-from django.template import RequestContext
+from django.views.generic import ListView
-from .models import Expense, CATS
+from .models import Expense, Trip, CATS
-def detail(request):
- context = {
- 'object_list': Expense.objects.all(),
- 'categories': CATS
- }
- return render_to_response('details/expenses.html', context, context_instance=RequestContext(request))
+class ExpenseListView(ListView):
+ model = Expense
+ context_object_name = 'object_list'
+ template_name = 'details/expenses.html'
+
+ def get_queryset(self):
+ return Expense.objects.filter(
+ trip__slug=self.kwargs['slug']
+ )
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(ExpenseListView, self).get_context_data(**kwargs)
+ context['categories'] = CATS
+ return context
+
+
+class TripListView(ListView):
+ model = Trip
+ context_object_name = 'object_list'
+ template_name = 'archives/expenses.html'
+
+ def get_queryset(self):
+ return Trip.objects.all()
diff --git a/config/base_urls.py b/config/base_urls.py
index e5aa79d..7ba9196 100644
--- a/config/base_urls.py
+++ b/config/base_urls.py
@@ -52,7 +52,10 @@ urlpatterns += patterns('',
),
(r'^projects/', include('projects.urls')),
(r'^locations/', include('locations.urls')),
- (r'^expenses/', include('expenses.urls')),
+ url(
+ regex=r'^expenses/',
+ view=include('expenses.urls', namespace='expenses')
+ ),
(r'^photos/', include('photos.urls')),
url(
regex=r'^books/',
diff --git a/design/templates/archives/expenses.html b/design/templates/archives/expenses.html
new file mode 100644
index 0000000..0007270
--- /dev/null
+++ b/design/templates/archives/expenses.html
@@ -0,0 +1,26 @@
+{% extends 'base.html' %}
+{% load expense_total%}
+{% load typogrify_tags %}
+
+{% block pagetitle %}Luxagraf: Expenses{% endblock %}
+
+{% block metadescription %}Think is costs a lot to drive around North America in a vintage Dodge Travco? Well, judge for yourself, here's how much is costs us.{% endblock %}
+
+{% block primary %}
+ <main role="main">
+ <article class="post--article">
+ <header class="post--header">
+ <h1 class="p-name entry-title post--title">Trip Costs</h1>
+ </header>
+ <div id="article" class="post--body post--body--single expense-wrapper">
+ <p>When we were planning our trips the people who posted their finances were invaluably helpful for calculating how much we needed to make it work. It's also something many people don't like to talk about so expense breakdowns are sort of rare in the online travel world. In the spirit of (hopefully, maybe) inspiring someone else to get out there, here is a rough breakdown of our costs (sorry I didn't track expenses in much detail prior to the Travco trip).</p>
+ {% for object in object_list %}
+ <h2>{{object.name}}</h2>
+ <p>{{object.dek}} <a href="{{object.get_absolute_url}}">View Details &#8674;</a></p>
+ {%endfor%}
+ <h2>Around the world in 2010</h2>
+ <p>This trip cost us (two) roughly ~4k, including all airfare. That's horribly expense for 2 months of traveling and I would never do it again. But sometimes you have to spend some money to learn</p>
+ <h2>Around the world in 2005-06</h2>
+ <p>This trip cost me roughly ~10k, including all airfare. I was solo back then and could have probably spent about ~2k less without really cramping my style much, but a fair amount of the time was spent trying to drink myself into an early grave and alcohol is expensive. I don't know how those numbers translate to today's money, but I wouldn't hesitate to set out again with half that much.</p>
+
+{%endblock%}