cleanup code

This commit is contained in:
Robert Einsle 2017-04-27 14:03:57 +02:00
parent f0ed2a5195
commit 857af8d54d
2 changed files with 4 additions and 121 deletions

View File

@ -20,14 +20,8 @@ urlpatterns = [
url(r'^account_modal/$', views.account_modal_view, name='account_modal'), url(r'^account_modal/$', views.account_modal_view, name='account_modal'),
# ex. /billard/1/account_modal/confirm/ # ex. /billard/1/account_modal/confirm/
url(r'^account_modal/(?P<pk>[0-9]+)/confirm/$', views.account_modal_confirm_view, name='account_modal_confirm'), url(r'^account_modal/(?P<pk>[0-9]+)/confirm/$', views.account_modal_confirm_view, name='account_modal_confirm'),
# rest api # ex. /billard/api/v1/ (rest api)
url(r'api/v1/', include(router.urls)), url(r'api/v1/', include(router.urls)),
# ex. /billard/process_location_data/
#url(r'^$', views.index, name='carom_index'), url(r'^process_location_data/$', views.process_location_data, name='process_location_data'),
#url(r'^(?P<pk>[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'),
#url(r'process_locationdata', views.process_locationdata, name='process_locationdata'),
#url(r'^accounting/$', views.AccountingView.as_view(), name='accounting'),
#url(r'^accountmodal$', views.accountmodalview, name='accountmodal'),
#url(r'^accoutmodal/confirm/(?P<pk>[0-9]+)$', views.accountmodalconfirmview, name="accountmodalconfirm")
# (?P<pk>[0-9]+)
] ]

View File

@ -89,122 +89,11 @@ def account_modal_confirm_view(request, pk):
return redirect('billard:location_detail', pk=account.desk.client.location_id) return redirect('billard:location_detail', pk=account.desk.client.location_id)
# TODO OLD CODE, CLEAN UP
class LocationDataViewSet(viewsets.ModelViewSet): class LocationDataViewSet(viewsets.ModelViewSet):
queryset = LocationData.objects.all() queryset = LocationData.objects.all()
serializer_class = LocationDataSerializer serializer_class = LocationDataSerializer
class IndexView(generic.ListView): def process_location_data(request):
model = LocationData
def get_template_names(self):
if self.request.is_ajax():
return ('billard/locationdata_list_ajax.html',)
return super().get_template_names()
class LocationDataDetailView(DetailView):
model = LocationData
def get_template_names(self):
if self.request.is_ajax():
return ('billard/locationdata_detail_ajax.html',)
return super().get_template_names()
@login_required
@permission_required('billard.change_accounting')
def accounting(request):
if request.method == 'GET':
template = 'billard/accounting.html'
loc = None
min_loc = Location.objects.filter(users__id=request.user.id).aggregate(Min('id'))['id__min']
if 'loc' in request.GET:
loc = request.GET['loc']
if not Location.objects.filter(users__id=request.user.id).filter(id=loc).exists():
resp = redirect('accounting')
if min_loc is not None:
resp['Location'] += '?loc={}'.format(str(min_loc))
request.session['loc'] = str(min_loc)
return resp
else:
return render(request, accounting)
if loc is None:
loc = min_loc
locations = Location.objects.filter(users__id=request.user.id).order_by('code')
acc = Accounting.objects.filter(billed=False).exclude(time_to__isnull=True). \
filter(desk__client__location_id=loc).order_by('-time_from')
acc_sum = acc.aggregate(Sum('prize'))
acc_ids = list()
for a in acc:
acc_ids.append(a.id)
context = {
'location_id': int(loc),
'locations': locations,
'accounting': acc,
'acc_ids': ','.join(str(e) for e in acc_ids),
}
if acc_sum['prize__sum'] is None:
context['acc_sum'] = 0
else:
context['acc_sum'] = acc_sum['prize__sum']
return render(request, template_name=template, context=context)
if request.method == 'POST':
loc = request.POST['location-selector']
if 'accountings' in request.POST:
acc_ids = request.POST['accountings'].split(',')
Accounting.objects.filter(id__in=acc_ids).update(billed=True)
Accounting.objects.filter(id__in=acc_ids).update(account_user=request.user.username)
request.session['loc'] = str(loc)
resp = redirect('accounting')
resp['Location'] += '?loc={}'.format(str(loc))
return resp
@login_required
def index(request):
if request.method == 'GET':
template = 'billard/index.html'
loc = None
if request.is_ajax():
template = 'billard/index_ajax.html'
loc = request.session.get('loc')
min_loc = Location.objects.filter(users__id=request.user.id).aggregate(Min('id'))['id__min']
if 'loc' in request.GET:
loc = request.GET['loc']
if not Location.objects.filter(users__id=request.user.id).filter(id=loc).exists():
resp = redirect('carom_index')
if min_loc is not None:
resp['Location'] += '?loc={}'.format(str(min_loc))
request.session['loc'] = str(min_loc)
return resp
else:
return render(request, template)
if loc is None:
loc = min_loc
locations = Location.objects.filter(users__id=request.user.id).order_by('code')
clients = Client.objects.filter(location_id=loc).order_by('id')
context = {
'range': range(1, 9),
'locations': locations,
'clients': clients,
'location_id': int(loc),
}
return render(request, template, context=context)
if request.method == 'POST':
loc = request.POST['location-selector']
request.session['loc'] = str(loc)
resp = redirect('carom_index')
resp['Location'] += '?loc={}'.format(str(loc))
return resp
def process_locationdata(request):
process_location_data() process_location_data()
return HttpResponse('DONE') return HttpResponse('DONE')