Permalink
Browse files

add summary archives

  • Loading branch information...
1 parent 88103c5 commit 020ccfaf0b3de5eea90d8248e3d97812cc2ef26f @dfalk committed Apr 7, 2012
@@ -0,0 +1,38 @@
+{% extends "fprice/base_price.html" %}
+{% load comments markup %}
+
+{% block title %}Мои отчеты {{ month }} {{ year }} | {{ block.super }}{% endblock %}
+
+{% block breadcrumbs %}{{ block.super }} - Мои отчеты{% endblock %}
+
+{% block contentclass %}summary{% endblock %}
+
+{% block content %}
+<h1>Мои отчеты за {{ month.month }}.{{ month.year }}</h1>
+<div id="trade-add">
+<a href="{% url price_trade_add %}">Добавьте вашу покупку прямо сейчас!</a>
+</div>
+<br />
+<div id="summary-entries">
+ <table>
+ {% for item in object_list %}
+ <tr><td><i>{{ item.time|date:"Y, j b H:i" }}</i></td><td style="text-align: right; padding-left: 10px; padding-right: 0px;"><b><a href="{{ item.get_absolute_url }}">{{ item.summary }}</a></b></td><td>{{ item.get_currency_display }}</td><td><a href="{% url price_shop_detail item.shop.id %}">{{ item.shop.title }}</a></td></tr>
+ {% endfor %}
+ <tr><td></td><td><b>{{ sum.summary__sum }}</b></td><td>р</td></tr>
+ </table>
+</div><!-- /#trade-entries -->
+
+<h2>Архив</h2>
+<div id="summary-archive">
+<ul>
+ {% for month in month_list %}<li><a href="{% url summary_archive_month month.year month|date:"m" %}">{{ month.year }}, {{ month|date:"F" }}</a></li>
+ {% endfor %}
+</ul>
+</div>
+
+{% if is_paginated %}<div class="pagination">Страницы:
+ {% if has_previous %}<a class="page-previous" href="?page={{ previous }}">позже</a>{% endif %}
+ <span class="page-position">{{ page }}/{{ pages }}</span>
+ {% if has_next %}<a class="page-next" href="?page={{ next }}">раньше</a>{% endif %}
+</div>{% endif %}
+{% endblock %}
@@ -0,0 +1,38 @@
+{% extends "fprice/base_price.html" %}
+{% load comments markup %}
+
+{% block title %}Мои отчеты за {{ year }} | {{ block.super }}{% endblock %}
+
+{% block breadcrumbs %}{{ block.super }} - Мои отчеты - {{ year }}{% endblock %}
+
+{% block contentclass %}summary{% endblock %}
+
+{% block content %}
+<h1>Отчеты за {{ year }}</h1>
+<div id="trade-add">
+<a href="{% url price_trade_add %}">Добавьте вашу покупку прямо сейчас!</a>
+</div>
+<br />
+<div id="summary-entries">
+ <table>
+ {% for item in object_list %}
+ <tr><td><i>{{ item.time|date:"Y, j b H:i" }}</i></td><td style="text-align: right; padding-left: 10px; padding-right: 0px;"><b><a href="{{ item.get_absolute_url }}">{{ item.summary }}</a></b></td><td>{{ item.get_currency_display }}</td><td><a href="{% url price_shop_detail item.shop.id %}">{{ item.shop.title }}</a></td></tr>
+ {% endfor %}
+ <tr><td></td><td><b>{{ sum.summary__sum }}</b></td><td>р</td></tr>
+ </table>
+</div><!-- /#trade-entries -->
+
+<h2>Архив</h2>
+<div id="summary-archive">
+<ul>
+ {% for month in month_list %}<li><a href="{% url summary_archive_month month.year month|date:"m" %}">{{ month.year }}, {{ month|date:"F" }}</a></li>
+ {% endfor %}
+</ul>
+</div>
+
+{% if is_paginated %}<div class="pagination">Страницы:
+ {% if has_previous %}<a class="page-previous" href="?page={{ previous }}">позже</a>{% endif %}
+ <span class="page-position">{{ page }}/{{ pages }}</span>
+ {% if has_next %}<a class="page-next" href="?page={{ next }}">раньше</a>{% endif %}
+</div>{% endif %}
+{% endblock %}
@@ -13,14 +13,24 @@
<a href="{% url price_trade_add %}">Добавьте вашу покупку прямо сейчас!</a>
</div>
<br />
+<h2>За последние 30 дней</h2>
<div id="summary-entries">
<table>
{% for item in object_list %}
<tr><td><i>{{ item.time|date:"Y, j b H:i" }}</i></td><td style="text-align: right; padding-left: 10px; padding-right: 0px;"><b><a href="{{ item.get_absolute_url }}">{{ item.summary }}</a></b></td><td>{{ item.get_currency_display }}</td><td><a href="{% url price_shop_detail item.shop.id %}">{{ item.shop.title }}</a></td></tr>
{% endfor %}
+ <tr><td></td><td><b>{{ sum.summary__sum }}</b></td><td>р</td></tr>
</table>
</div><!-- /#trade-entries -->
+<h2>Архив</h2>
+<div id="summary-archive">
+<ul>
+ {% for month in month_list %}<li><a href="{% url summary_archive_month month.year month|date:"m" %}">{{ month.year }}, {{ month|date:"F" }}</a></li>
+ {% endfor %}
+</ul>
+</div>
+
{% if is_paginated %}<div class="pagination">Страницы:
{% if has_previous %}<a class="page-previous" href="?page={{ previous }}">позже</a>{% endif %}
<span class="page-position">{{ page }}/{{ pages }}</span>
View
@@ -6,29 +6,40 @@
urlpatterns = patterns('fprice.views',
- url(r'^search/$', view='search', name='price_search'),
-
+ # Products and shops
url(r'^shops/$', view='shop_list', name='price_shop_list'),
url(r'^shops/(?P<shop_id>\d+)/$', view='shop_detail', name='price_shop_detail'),
url(r'^products/$', view='product_list', name='price_product_list'),
url(r'^products/(?P<product_id>\d+)/$', view='product_detail', name='price_product_detail'),
- url(r'^products/(?P<product_id>\d+)/shop/(?P<shop_id>\d+)/$', view='product_and_shop', name='price_prodshop_detail'),
url(r'^products/category/(?P<slug>\w+)/$', view='product_category', name='price_product_category'),
- url(r'^prices/(?P<price_id>\d+)/up/$', view='price_up', name='price_up'),
+ url(r'^products/(?P<product_id>\d+)/shop/(?P<shop_id>\d+)/$', view='product_and_shop', name='price_prodshop_detail'),
+
+ # Profile
+ url(r'^profile/$', view='summary_list', name='price_summary_list'),
+ url(r'^profile/(?P<year>\d{4})/$',
+ view='summary_archive_year',
+ name='summary_archive_year'
+ ),
+ url(r'^profile/(?P<year>\d{4})/(?P<month>\d{2})/$',
+ view='summary_archive_month',
+ name='summary_archive_month'
+ ),
+ url(r'^profile/summary/(?P<summary_id>\d+)/$', view='summary_detail', name='price_summary_detail'),
url(r'^profile/prices/$', view='price_list', name='price_list'),
url(r'^profile/prices/admin/$', view='price_admin', name='price_admin'),
url(r'^profile/trades/$', view='trade_list', name='price_trade_list'),
url(r'^profile/trades/admin/$', view='trade_admin', name='price_trade_admin'),
+
+ # Actions
+ url(r'^search/$', view='search', name='price_search'),
url(r'^profile/trades/add/$', view='trade_add', name='price_trade_add'),
url(r'^lookup/(shop|product)/$', view='lookup', name='json_lookup'),
-
- url(r'^profile/$', view='summary_list', name='price_summary_list'),
- url(r'^profile/summary/(?P<summary_id>\d+)/$', view='summary_detail', name='price_summary_detail'),
+ url(r'^prices/(?P<price_id>\d+)/up/$', view='price_up', name='price_up'),
)
View
@@ -122,15 +122,47 @@ def price_up(request, price_id, **kwargs):
@login_required
def summary_list(request, page=0, template_name='fprice/summary_list.html', **kwargs):
+ queryset = Summary.objects.filter(user=request.user).filter(time__gt=datetime.datetime.now()-datetime.timedelta(days=30))
+ summary_sum = queryset.aggregate(Sum('summary'))
+ month_list = Summary.objects.dates('time','month',order='DESC')
return list_detail.object_list(
request,
- queryset = Summary.objects.filter(user=request.user),
+ queryset = queryset,
paginate_by = 30,
page = page,
template_name = template_name,
+ extra_context = {'sum':summary_sum, 'month_list': month_list},
**kwargs)
@login_required
+def summary_archive_year(request, year, page=0, template_name='fprice/summary_archive_year.html', **kwargs):
+ queryset = Summary.objects.filter(user=request.user).filter(time__year=year)
+ summary_sum = queryset.aggregate(Sum('summary'))
+ return list_detail.object_list(
+ request,
+ queryset = queryset,
+ paginate_by = 10,
+ page = page,
+ template_name = template_name,
+ extra_context = {'sum':summary_sum, 'year':year},
+ **kwargs)
+
+@login_required
+def summary_archive_month(request, year, month, page=0, template_name='fprice/summary_archive_month.html', **kwargs):
+ queryset = Summary.objects.filter(user=request.user).filter(time__year=year, time__month=month)
+ summary_sum = queryset.aggregate(Sum('summary'))
+ return list_detail.object_list(
+ request,
+ queryset = queryset,
+ paginate_by = 10,
+ page = page,
+ template_name = template_name,
+ extra_context = {'sum':summary_sum, 'month':datetime.date(int(year),int(month),1)},
+ **kwargs)
+
+
+
+@login_required
def summary_detail(request, summary_id, page=0, template_name='fprice/summary_detail.html', **kwargs):
summary = Summary.objects.get(id=summary_id)
# TODO: check user

0 comments on commit 020ccfa

Please sign in to comment.