summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/TODO4
-rw-r--r--app/income/admin.py52
-rw-r--r--app/pages/models.py12
-rw-r--r--design/templates/admin/income_month.html123
-rw-r--r--design/templates/admin/index.html3
5 files changed, 180 insertions, 14 deletions
diff --git a/app/TODO b/app/TODO
index 502002d..ed6720c 100644
--- a/app/TODO
+++ b/app/TODO
@@ -16,7 +16,9 @@ revamp notes to be like my own personal instagram
income app:
-Add admin pages for viewing income by month, including future. So page with list of months and links to months: /admin/income/month/ default to current month, add option GET param to show past months, add code to views and call it from base_urls before main admin include. show everything with status accepted and then the separately show pitched as possibilities, then show totals alongside how much we need to live. If invoice is submitted show date submitted and create a probably pay date for each publisher.
+- Add pitched stories as possibilities below total, t
+- show totals alongside how much we need to live.
+- add pay_turnaround field for each publisher and show in admin
---
diff --git a/app/income/admin.py b/app/income/admin.py
index d8430be..02c01ef 100644
--- a/app/income/admin.py
+++ b/app/income/admin.py
@@ -1,9 +1,17 @@
+import datetime
from django.contrib import admin
+from django.db.models import Sum
+from django.contrib.admin import helpers
+from django.contrib.gis.admin import OSMGeoAdmin
+from django.conf.urls import patterns
+from django.conf.urls import url
+from django.shortcuts import render
+
from .models import Gig
-class GigAdmin(admin.ModelAdmin):
+class GigAdmin(OSMGeoAdmin):
list_display = ('title', 'status', 'payment_status', 'invoice_date', 'payment', 'publisher', 'pub_date', 'word_count')
list_filter = ('publisher', 'status', 'payment_status')
fieldsets = (
@@ -11,8 +19,8 @@ class GigAdmin(admin.ModelAdmin):
'fields': (
'title',
'pitch',
- ('payment', 'pay_type','payment_status', 'invoice_date'),
- ('status', 'pub_date', 'word_count' ),
+ ('payment', 'pay_type', 'payment_status', 'invoice_date'),
+ ('status', 'pub_date', 'word_count'),
'publisher',
'pub_item'
),
@@ -24,4 +32,42 @@ class GigAdmin(admin.ModelAdmin):
}
),
)
+
+ def get_urls(self):
+ urls = super(GigAdmin, self).get_urls()
+ custom_urls = patterns('',
+ url(r'^monthly/$',
+ self.admin_site.admin_view(self.get_monthly),
+ name='monthly_admin')
+ )
+ return custom_urls + urls
+
+ def get_monthly(self, request):
+ context = {
+ 'title': ("This month's income"),
+ 'app_label': self.model._meta.app_label,
+ 'opts': self.model._meta,
+ 'has_change_permission': self.has_change_permission(request)
+ }
+ try:
+ year = request.GET["m"].split("-")[0]
+ month = request.GET["m"].split("-")[1]
+ except:
+ year = datetime.datetime.now().strftime('%Y')
+ month = datetime.datetime.now().strftime('%m')
+ qs = self.model.objects.filter(
+ created__year=year,
+ created__month=month,
+ status__in=[1, 2, 3]
+ )
+ context['date'] = datetime.datetime.now()
+ context['billed'] = qs.filter(payment_status=1)
+ context['billed_total'] = qs.filter(payment_status=1).aggregate(total_payment=Sum('payment'))
+ context['unbilled'] = qs.filter(payment_status=0)
+ context['unbilled_total'] = qs.filter(payment_status=0).aggregate(total_payment=Sum('payment'))
+ context['total_outstanding'] = qs.aggregate(total_payment=Sum('payment'))
+ context['months'] = self.model.objects.dates('created', 'month')
+ return render(request, 'admin/income_month.html', context)
+
+
admin.site.register(Gig, GigAdmin)
diff --git a/app/pages/models.py b/app/pages/models.py
index 832b958..0062bd9 100644
--- a/app/pages/models.py
+++ b/app/pages/models.py
@@ -1,15 +1,6 @@
from django.db import models
from django.contrib.sitemaps import Sitemap
-import markdown
-from mdx_attr_list.mdx_attr_list import AttrListExtension
-def markdown_processor(txt):
- md = markdown.Markdown(
- extensions=[AttrListExtension(),'footnotes',],
- output_format='html5',
- safe_mode=False
- )
- return md.convert(txt)
class Page(models.Model):
title = models.CharField(max_length=200)
@@ -17,6 +8,7 @@ class Page(models.Model):
body_html = models.TextField(blank=True)
body_markdown = models.TextField()
meta_description = models.CharField(max_length=256, null=True, blank=True)
+ #path = models.CharField(max_length=200, null=True, blank=True)
def __unicode__(self):
return self.title
@@ -25,7 +17,7 @@ class Page(models.Model):
return "/%s/" % (self.slug)
def save(self):
- #run markdown
+ # run markdown
self.body_html = markdown_processor(self.body_markdown)
super(Page, self).save()
diff --git a/design/templates/admin/income_month.html b/design/templates/admin/income_month.html
new file mode 100644
index 0000000..e34cdbf
--- /dev/null
+++ b/design/templates/admin/income_month.html
@@ -0,0 +1,123 @@
+{% extends "admin/base_site.html" %}
+{% load i18n admin_urls admin_static %}
+
+{# Admin styling code largely taken from http://www.dmertl.com/blog/?p=116 #}
+
+{% block extrastyle %}
+ {{ block.super }}
+<script type="text/javascript" src="/admin/jsi18n/"></script>
+<script type="text/javascript" src="/static/admin/js/core.js"></script>
+<script type="text/javascript" src="/static/admin/js/admin/RelatedObjectLookups.js"></script>
+<script type="text/javascript" src="/static/admin/js/jquery.js"></script>
+<script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>
+<script type="text/javascript" src="/static/admin/js/actions.js"></script>
+<script type="text/javascript" src="/static/admin/js/calendar.js"></script>
+<script type="text/javascript" src="/static/admin/js/admin/DateTimeShortcuts.js"></script>
+ <link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}"/>
+ <style>
+ .field-title {min-width: 200px;}
+ .results {margin-bottom: 4em;}
+ </style>
+{% endblock %}
+
+{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
+
+{% block breadcrumbs %}
+ <div class="breadcrumbs">
+ <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
+ &rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ app_label|capfirst|escape }}</a>
+ &rsaquo; {% if has_change_permission %}<a href="{% url opts|admin_urlname:'changelist' %}">
+ {{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %}
+ &rsaquo; {% trans 'Upload' %}
+ </div>
+{% endblock %}
+
+{% block content_title %}{% endblock %}
+
+{% block content %}
+
+<h1>{% trans "Income for the month of" %} {{date|date:"F Y"}}</h1>
+<h2>{% trans "Billed" %}</h2>
+
+
+<div style="float: left; width: 40%">
+<div class="results">
+<table id="result_list">
+<thead>
+<tr>
+
+<th scope="col" class="sortable column-title">
+ <div class="text"><a href="?o=1">Title</a></div>
+ <div class="clear"></div>
+</th>
+<th scope="col" class="sortable column-status">
+ <div class="text"><a href="?o=5">Amount</a></div>
+ <div class="clear"></div>
+</th>
+<th scope="col" class="sortable column-status">
+ <div class="text"><a href="?o=5">Source</a></div>
+ <div class="clear"></div>
+</th>
+<th scope="col" class="sortable column-status">
+ <div class="text"><a href="?o=5">Date Invoiced</a></div>
+ <div class="clear"></div>
+</th>
+</tr>
+</thead>
+<tbody>
+
+{% for gig in billed %}
+
+<tr class="{% cycle 'row1' 'row2' %}"><th class="field-title">{{gig.title}}</th><td class="field-status">${{gig.payment}}</td><td class="field-payment_status">{{gig.publisher}}</td><td class="field-pub_date nowrap">{{gig.invoice_date}}</td></tr>
+{%endfor%}
+<tr class="row2"><th class="field-title">&nbsp;</th><td class="field-status"></td><td class="field-payment_status"></td><td class="field-pub_date nowrap"></td></tr>
+<tr class="row2"><th class="field-title">Total Billed:</th><td class="field-status">${{billed_total.total_payment}}</td><td class="field-payment_status"></td><td class="field-pub_date nowrap"></td></tr>
+</tbody>
+</table>
+</div>
+
+<h2>{% trans "Unbilled" %}</h2>
+<div class="results">
+<table id="result_list_2">
+<thead>
+<tr>
+
+<th scope="col" class="sortable column-title">
+ <div class="text"><a href="?o=1">Title</a></div>
+ <div class="clear"></div>
+</th>
+<th scope="col" class="sortable column-status">
+ <div class="text"><a href="?o=5">Amount</a></div>
+ <div class="clear"></div>
+</th>
+<th scope="col" class="sortable column-status">
+ <div class="text"><a href="?o=5">Source</a></div>
+ <div class="clear"></div>
+</th>
+<th scope="col" class="sortable column-status">
+ <div class="text"><a href="?o=5">Date Invoiced</a></div>
+ <div class="clear"></div>
+</th>
+</tr>
+</thead>
+<tbody>
+
+{% for gig in unbilled %}
+
+<tr class="{% cycle 'row1' 'row2' %}"><th class="field-title">{{gig.title}}</th><td class="field-status">${{gig.payment}}</td><td class="field-payment_status">{{gig.publisher}}</td><td class="field-pub_date nowrap">{{gig.invoice_date}}</td></tr>
+{%endfor%}
+<tr class="row2"><th class="field-title">&nbsp;</th><td class="field-status"></td><td class="field-payment_status"></td><td class="field-pub_date nowrap"></td></tr>
+<tr class="row2"><th class="field-title">Total Billed:</th><td class="field-status">${{unbilled_total.total_payment}}</td><td class="field-payment_status"></td><td class="field-pub_date nowrap"></td></tr>
+</tbody>
+</table>
+</div>
+<h2>{% trans "Total Outstanding:" %} ${{total_outstanding.total_payment}}</h2>
+</div>
+
+<div style="float:left; margin-left: 4em;">
+<h3>{% trans "Income by Month" %}</h3>
+<ul>{% for month in months %}
+<li><a href="?m={{month|date:"Y-m"|slugify}}">{{month|date:"F Y"}}</a></li>
+{%endfor%}</ul>
+</div>
+{% endblock %}
diff --git a/design/templates/admin/index.html b/design/templates/admin/index.html
index cbaa89f..19a5d1b 100644
--- a/design/templates/admin/index.html
+++ b/design/templates/admin/index.html
@@ -41,6 +41,9 @@
<td>&nbsp;</td>
{% endif %}
</tr>
+ {% if model.name == "Gigs"%}
+ <tr> <th scope="row"><a href="{{ model.admin_url }}monthly/">Income for month</a></th></tr>
+ {% endif %}
{% endfor %}
</table>
</div>