diff --git a/main/urls.py b/main/urls.py index 6edb152..04d6acd 100644 --- a/main/urls.py +++ b/main/urls.py @@ -7,4 +7,5 @@ urlpatterns = patterns('main.views', url(r'^log/all$', 'log', kwargs={'limit': None}, name='log-all'), url(r'^stats/$', 'stats', name='stats'), url(r'^stats/orders$', 'stats_orders', name='stats-orders'), + url(r'^stats/products$', 'products', name='stats-products'), ) diff --git a/main/views.py b/main/views.py index 5cbcbf0..faa8709 100755 --- a/main/views.py +++ b/main/views.py @@ -135,9 +135,26 @@ def log(request, limit=datetime.now()-timedelta(days=2)): return render_to_response('log.html', locals(), context_instance=RequestContext(request)) def stats(request): + products = Product.objects.filter(active=True) return render_to_response('stats.html', locals(), context_instance=RequestContext(request)) +def products(request): + products = Product.objects.filter(active=True) + + f_products = [] + for product in products: + for attr in Product._meta.get_all_field_names(): + if hasattr(product, attr): + #print type(product.__getattribute__(attr)) + if type(product.__getattribute__(attr)) is datetime: + # TODO parse datetime + f_products.append({attr : product.__getattribute__(attr.())}) + else: + f_products.append({attr : product.__getattribute__(attr)}) + + return HttpResponse(json.dumps(f_products), content_type='application/javascript; charset=utf8') + def stats_orders(request): total = float(Order.objects.count()) diff --git a/settings-sample.py b/settings-sample.py index ff53692..cd7ad91 100755 --- a/settings-sample.py +++ b/settings-sample.py @@ -124,7 +124,6 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', 'django.contrib.admin', 'main', - 'gravatar', ) # A sample logging configuration. The only tangible logging diff --git a/static/js/stats.js b/static/js/stats.js index 19fd2e3..ec7f27f 100644 --- a/static/js/stats.js +++ b/static/js/stats.js @@ -1,4 +1,4 @@ -var chart; +var charts; $(document).ready(function() { // define the options var options = { @@ -39,9 +39,24 @@ $(document).ready(function() { data: [], }] } - var url = '/stats/orders'; - $.getJSON(url, function(data) { - options.series[0].data = data; - chart = new Highcharts.Chart(options); + var products_url = '/stats/products'; + /* drink beer and */ + $.getJSON(products_url, function(data) { + var graph_mappings = [ + ['/stats/orders', 'order_chart'] + ]; + var products = data; + for(i in products) { + var mapping = ['/stats/product/'+products[i].id, 'product_chart'+products[i].id]; + graph_mappings.push(mapping); + } + /* TODO merere her */ + for(i in graph_mappings) { + $.getJSON(graph_mappings, function(data) { + options.series[0].data = data; + options.chart.renderTo = graph_mappings[i][1]; + charts.push(new Highcharts.Chart(options)); + }); + } }); }); diff --git a/templates/deposit.html b/templates/deposit.html index 9467df0..7b5d1dd 100644 --- a/templates/deposit.html +++ b/templates/deposit.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% load gravatar %} {% block header %} {% include "nav.html" with active="deposit" %} {% endblock %} @@ -30,7 +29,7 @@ {% if user.get_profile.image %}   Profile picture
{% else %} -   Profile picture
+   Profile picture
{% endif %} {{ user.first_name }} {{ user.last_name|slice:":1"}}
{{ user.get_profile.balance }} diff --git a/templates/log.html b/templates/log.html index 3864b7f..4fdeb29 100644 --- a/templates/log.html +++ b/templates/log.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% load gravatar %} {% block header %} {% include "nav.html" with active="log" %} {% endblock %} diff --git a/templates/register.html b/templates/register.html index 007fbe3..f524521 100644 --- a/templates/register.html +++ b/templates/register.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% load gravatar %} {% block header %} {% include "nav.html" with active="register" %} {% endblock %} @@ -37,7 +36,7 @@ {% if user.get_profile.image %}   Profile picture
{% else %} -   Profile picture
+   Profile picture
{% endif %} {{ user.first_name }} {{ user.last_name|slice:":1"}}
{{ user.get_profile.balance }} diff --git a/templates/stats.html b/templates/stats.html index f901fcc..3aae54b 100644 --- a/templates/stats.html +++ b/templates/stats.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% load gravatar %} {% block header %} {% include "nav.html" with active="stats" %} {% endblock %} @@ -13,6 +12,16 @@ + + {% for product in products %} +
+
+

{{ product }}

+
+ +
+
+ {% endfor %} {% endblock %} {% block tailinc %} diff --git a/unknown_person.png b/unknown_person.png new file mode 100644 index 0000000..c01cf9b Binary files /dev/null and b/unknown_person.png differ