Skip to content

Commit

Permalink
add summary archives
Browse files Browse the repository at this point in the history
  • Loading branch information
dfalk committed Apr 7, 2012
1 parent 88103c5 commit 020ccfa
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 8 deletions.
38 changes: 38 additions & 0 deletions fprice/templates/fprice/summary_archive_month.html
@@ -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 %}
38 changes: 38 additions & 0 deletions fprice/templates/fprice/summary_archive_year.html
@@ -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 %}
10 changes: 10 additions & 0 deletions fprice/templates/fprice/summary_list.html
Expand Up @@ -13,14 +13,24 @@ <h1>Мои отчеты</h1>
<a href="{% url price_trade_add %}">Добавьте вашу покупку прямо сейчас!</a> <a href="{% url price_trade_add %}">Добавьте вашу покупку прямо сейчас!</a>
</div> </div>
<br /> <br />
<h2>За последние 30 дней</h2>
<div id="summary-entries"> <div id="summary-entries">
<table> <table>
{% for item in object_list %} {% 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> <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 %} {% endfor %}
<tr><td></td><td><b>{{ sum.summary__sum }}</b></td><td>р</td></tr>
</table> </table>
</div><!-- /#trade-entries --> </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 is_paginated %}<div class="pagination">Страницы:
{% if has_previous %}<a class="page-previous" href="?page={{ previous }}">позже</a>{% endif %} {% if has_previous %}<a class="page-previous" href="?page={{ previous }}">позже</a>{% endif %}
<span class="page-position">{{ page }}/{{ pages }}</span> <span class="page-position">{{ page }}/{{ pages }}</span>
Expand Down
25 changes: 18 additions & 7 deletions fprice/urls.py
Expand Up @@ -6,29 +6,40 @@


urlpatterns = patterns('fprice.views', 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/$', view='shop_list', name='price_shop_list'),
url(r'^shops/(?P<shop_id>\d+)/$', view='shop_detail', name='price_shop_detail'), 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/$', 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+)/$', 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'^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/$', view='price_list', name='price_list'),
url(r'^profile/prices/admin/$', view='price_admin', name='price_admin'), 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/$', view='trade_list', name='price_trade_list'),
url(r'^profile/trades/admin/$', view='trade_admin', name='price_trade_admin'), 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'^profile/trades/add/$', view='trade_add', name='price_trade_add'),
url(r'^lookup/(shop|product)/$', view='lookup', name='json_lookup'), url(r'^lookup/(shop|product)/$', view='lookup', name='json_lookup'),

url(r'^prices/(?P<price_id>\d+)/up/$', view='price_up', name='price_up'),
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'),


) )


Expand Down
34 changes: 33 additions & 1 deletion fprice/views.py
Expand Up @@ -122,14 +122,46 @@ def price_up(request, price_id, **kwargs):


@login_required @login_required
def summary_list(request, page=0, template_name='fprice/summary_list.html', **kwargs): 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( return list_detail.object_list(
request, request,
queryset = Summary.objects.filter(user=request.user), queryset = queryset,
paginate_by = 30, paginate_by = 30,
page = page, page = page,
template_name = template_name, template_name = template_name,
extra_context = {'sum':summary_sum, 'month_list': month_list},
**kwargs) **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 @login_required
def summary_detail(request, summary_id, page=0, template_name='fprice/summary_detail.html', **kwargs): def summary_detail(request, summary_id, page=0, template_name='fprice/summary_detail.html', **kwargs):
summary = Summary.objects.get(id=summary_id) summary = Summary.objects.get(id=summary_id)
Expand Down

0 comments on commit 020ccfa

Please sign in to comment.