Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def pie_view(request, what, choice_dict, page_title):
  2.     numbers = SortedDict()
  3.     year, month = request.GET.get('year'), request.GET.get('month')
  4.     numbers['all'] = _make_numbers(
  5.         what, year=year, month=month)
  6.  
  7.     for group in _office_groups():
  8.         numbers[group] = _make_numbers(
  9.             what, office_title=group, year=year, month=month)
  10.  
  11.     json_data = []
  12.     for office_title, amount in numbers.items():
  13.  
  14.         amount_items = sorted(
  15.             amount.items(), key=lambda l: -l[1]) # sort by no of clients
  16.  
  17.         info = {}
  18.         data = []
  19.         info['store'] = dict(
  20.             fields=['category', 'total'],
  21.             data=data)
  22.         office_title = office_title == u'all' and u'Gesamt' or office_title
  23.         info['title'] = u'Kontaktaufnahme: %s' % office_title
  24.         for key, value in amount_items:
  25.             data.append(dict(
  26.                 category=choice_dict[key],
  27.                 total=value
  28.                 ))
  29.  
  30.         json_data.append(info)
  31.  
  32.     return render_to_response(
  33.         'lotsen/pie.html', template_variables(
  34.             request,
  35.             page_title=page_title,
  36.             numbers=numbers,
  37.             json_data=json.dumps(json_data),
  38.             ))
  39.  
  40. @user_passes_test(is_teamleader_or_superuser)
  41. def contacted_through(request):
  42.     return pie_view(
  43.         request,
  44.         'issue__client__contacted_through',
  45.         choices.CONTACTED_THROUGH_DICT,
  46.         'Kontaktaufnahme',
  47.         )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement