Time for bed
This commit is contained in:
1 parent
d112e1b195
commit
598e2a8e57
4 files changed
+101
-70
No files matched your search
+3
-1
@@ -7,5 +7,7 @@ urlpatterns = patterns('main.views',
|
|||||||
url(r'^log/all$', 'log', kwargs={'limit': None}, name='log-all'),
|
url(r'^log/all$', 'log', kwargs={'limit': None}, name='log-all'),
|
||||||
url(r'^stats/$', 'stats', name='stats'),
|
url(r'^stats/$', 'stats', name='stats'),
|
||||||
url(r'^stats/orders$', 'stats_orders', name='stats-orders'),
|
url(r'^stats/orders$', 'stats_orders', name='stats-orders'),
|
||||||
url(r'^stats/products$', 'products', name='stats-products'),
|
url(r'^stats/product/(?P<product>[0-9]+)$', 'stats_product', name='stats-product'),
|
||||||
|
url(r'^products/(?P<product_id>[0-9]+)', 'products', name='json-product'),
|
||||||
|
url(r'^products/$', 'products', name='json-products'),
|
||||||
)
|
)
|
||||||
+35
-15
@@ -139,25 +139,45 @@ def stats(request):
|
|||||||
|
|
||||||
return render_to_response('stats.html', locals(), context_instance=RequestContext(request))
|
return render_to_response('stats.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|
||||||
def products(request):
|
def serialize_product(product):
|
||||||
products = Product.objects.filter(active=True)
|
f_product = {}
|
||||||
|
for attr in Product._meta.get_all_field_names():
|
||||||
|
if hasattr(product, attr) and product.__getattribute__(attr):
|
||||||
|
#print type(product.__getattribute__(attr))
|
||||||
|
if type(product.__getattribute__(attr)) is datetime:
|
||||||
|
# TODO parse datetime
|
||||||
|
date = product.__getattribute__(attr)
|
||||||
|
f_product[attr] = str(product.__getattribute__(attr))
|
||||||
|
else:
|
||||||
|
f_product[attr] = product.__getattribute__(attr)
|
||||||
|
return f_product
|
||||||
|
|
||||||
f_products = []
|
def products(request, product_id=None):
|
||||||
for product in products:
|
if product_id:
|
||||||
f_product = []
|
#single
|
||||||
for attr in Product._meta.get_all_field_names():
|
products = get_object_or_404(Product, pk=product_id)
|
||||||
if hasattr(product, attr) and product.__getattribute__(attr):
|
else:
|
||||||
#print type(product.__getattribute__(attr))
|
#many
|
||||||
if type(product.__getattribute__(attr)) is datetime:
|
products = Product.objects.filter(active=True)
|
||||||
# TODO parse datetime
|
|
||||||
date = product.__getattribute__(attr)
|
if product_id:
|
||||||
f_product.append({attr : str(product.__getattribute__(attr))})
|
f_products = serialize_product(products)
|
||||||
else:
|
else:
|
||||||
f_product.append({attr : product.__getattribute__(attr)})
|
f_products = [serialize_product(product) for product in products]
|
||||||
f_products.append(f_product)
|
|
||||||
|
|
||||||
return HttpResponse(json.dumps(f_products), content_type='application/javascript; charset=utf8')
|
return HttpResponse(json.dumps(f_products), content_type='application/javascript; charset=utf8')
|
||||||
|
|
||||||
|
def stats_product(request, product):
|
||||||
|
sales = OrderLine.objects.filter(product=product)
|
||||||
|
total = float(sales.count())
|
||||||
|
per_user = sales.values('order__customer__first_name','order__customer__last_name').annotate(num=Count('order__customer')).order_by('num')
|
||||||
|
f_per_user = []
|
||||||
|
for row in per_user:
|
||||||
|
who = row['order__customer__first_name'] + " " + row['order__customer__last_name'][0]
|
||||||
|
num = row['num']
|
||||||
|
f_per_user.append([who, num])
|
||||||
|
return HttpResponse(json.dumps(f_per_user), content_type='application/javascript; charset=utf8')
|
||||||
|
|
||||||
def stats_orders(request):
|
def stats_orders(request):
|
||||||
|
|
||||||
total = float(Order.objects.count())
|
total = float(Order.objects.count())
|
||||||
|
|||||||
+62
-53
@@ -1,62 +1,71 @@
|
|||||||
var charts;
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// define the options
|
var charts = [];
|
||||||
var options = {
|
var products_url = '/products';
|
||||||
credits: {
|
|
||||||
enabled: false
|
/* drink beer and... */
|
||||||
},
|
$.getJSON(products_url, function(data) {
|
||||||
chart: {
|
var graph_mappings = [
|
||||||
renderTo: 'order_chart',
|
{
|
||||||
plotBackgroundColor: null,
|
'url' : '/stats/orders',
|
||||||
plotBorderWidth: null,
|
'render_to' : 'order_chart'
|
||||||
plotShadow: false
|
}];
|
||||||
},
|
var products = data;
|
||||||
title: {
|
for(i in products) {
|
||||||
text: 'Antall ordre per bruker'
|
var mapping = {
|
||||||
},
|
'url' : '/stats/product/' + products[i].id,
|
||||||
tooltip: {
|
'info_url' : '/products/' + products[i].id,
|
||||||
formatter: function() {
|
'render_to' : 'product_chart' + products[i].id
|
||||||
return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +' %';
|
};
|
||||||
}
|
graph_mappings.push(mapping);
|
||||||
},
|
}
|
||||||
plotOptions: {
|
for(i in graph_mappings) {
|
||||||
pie: {
|
// define the options
|
||||||
allowPointSelect: true,
|
var options = {
|
||||||
cursor: 'pointer',
|
credits: {
|
||||||
dataLabels: {
|
enabled: false
|
||||||
enabled: true,
|
},
|
||||||
color: '#000000',
|
chart: {
|
||||||
connectorColor: '#000000',
|
/* TODO this is not updated right.
|
||||||
|
* ie. how to get ajax-callback to update the right options-object?
|
||||||
|
* */
|
||||||
|
renderTo: graph_mappings[i].render_to,
|
||||||
|
plotBackgroundColor: null,
|
||||||
|
plotBorderWidth: null,
|
||||||
|
plotShadow: false
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
text: 'Antall ordre per bruker'
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
formatter: function() {
|
formatter: function() {
|
||||||
return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +' %';
|
return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +' %';
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
plotOptions: {
|
||||||
},
|
pie: {
|
||||||
series: [{
|
allowPointSelect: true,
|
||||||
type: 'pie',
|
cursor: 'pointer',
|
||||||
name: 'Orders',
|
dataLabels: {
|
||||||
data: [],
|
enabled: true,
|
||||||
}]
|
color: '#000000',
|
||||||
}
|
connectorColor: '#000000',
|
||||||
var products_url = '/stats/products';
|
formatter: function() {
|
||||||
/* drink beer and */
|
return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +' %';
|
||||||
$.getJSON(products_url, function(data) {
|
}
|
||||||
var graph_mappings = [
|
}
|
||||||
['/stats/orders', 'order_chart']
|
}
|
||||||
];
|
},
|
||||||
var products = data;
|
series: [{
|
||||||
for(i in products) {
|
type: 'pie',
|
||||||
var mapping = ['/stats/product/'+products[i].id, 'product_chart'+products[i].id];
|
name: 'Orders',
|
||||||
graph_mappings.push(mapping);
|
data: []
|
||||||
}
|
}]
|
||||||
/* TODO merere her */
|
};
|
||||||
for(i in graph_mappings) {
|
$.getJSON(graph_mappings[i].url, function(data) {
|
||||||
$.getJSON(graph_mappings, function(data) {
|
options.series[0].data = data,
|
||||||
options.series[0].data = data;
|
|
||||||
options.chart.renderTo = graph_mappings[i][1];
|
|
||||||
charts.push(new Highcharts.Chart(options));
|
charts.push(new Highcharts.Chart(options));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
console.log(charts);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<section id="product_{{ product.id }}" class="row-fluid">
|
<section id="product_{{ product.id }}" class="row-fluid">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
<h2>{{ product }}</h2>
|
<h2>{{ product }}</h2>
|
||||||
<div id="product_{{ product.id }}_chart"></div>
|
<div id="product_chart{{ product.id }}"></div>
|
||||||
<!--<div id="container" style="width: 800px; height: 400px; margin: 0 auto;"></div> -->
|
<!--<div id="container" style="width: 800px; height: 400px; margin: 0 auto;"></div> -->
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Reference in new issue
Block a user