2018-02-11 10:56:44 +01:00
|
|
|
from django import forms
|
2017-08-03 19:52:43 +02:00
|
|
|
from django.conf.urls import url
|
|
|
|
from django.contrib import admin, messages
|
2018-02-11 10:56:44 +01:00
|
|
|
from django.core.exceptions import ValidationError
|
2017-08-03 19:52:43 +02:00
|
|
|
from django.shortcuts import redirect
|
|
|
|
|
2017-01-03 19:40:35 +01:00
|
|
|
from .models import *
|
2017-01-03 19:26:51 +01:00
|
|
|
|
2017-01-03 19:40:35 +01:00
|
|
|
|
2017-02-25 18:34:28 +01:00
|
|
|
class LocationAdminForm(forms.ModelForm):
|
|
|
|
|
|
|
|
def clean_happy_hour_end(self):
|
|
|
|
hh_start = self.cleaned_data['happy_hour_start']
|
|
|
|
hh_end = self.cleaned_data['happy_hour_end']
|
|
|
|
if hh_start is None and hh_end is not None:
|
|
|
|
raise ValidationError('Start und Ende Zeit muss angegeben werden')
|
|
|
|
if hh_start is not None and hh_end is None:
|
|
|
|
raise ValidationError('Start und Ende Zeit muss angegeben werden')
|
2017-03-10 19:48:58 +01:00
|
|
|
if hh_start is not None and hh_end is not None and not (hh_end > hh_start):
|
2017-02-25 18:34:28 +01:00
|
|
|
raise ValidationError('Ende-Zeit muss nach Start-Zeit liegen')
|
|
|
|
return self.cleaned_data['happy_hour_end']
|
|
|
|
|
|
|
|
|
2017-01-03 19:48:00 +01:00
|
|
|
@admin.register(Location)
|
2017-01-03 19:40:35 +01:00
|
|
|
class LocationAdmin(admin.ModelAdmin):
|
2017-02-25 18:34:28 +01:00
|
|
|
form = LocationAdminForm
|
|
|
|
list_display = ('code', 'name', 'city', 'happy_hour_start', 'happy_hour_end')
|
2018-02-11 10:56:44 +01:00
|
|
|
fields = ['users', 'code', 'happy_hour_start', 'happy_hour_end', 'name', 'street', 'plz', 'city', 'phone', 'email',
|
|
|
|
'url', ]
|
2017-01-03 19:40:35 +01:00
|
|
|
|
|
|
|
|
2017-01-03 19:48:00 +01:00
|
|
|
@admin.register(Client)
|
2017-01-03 19:40:35 +01:00
|
|
|
class ClientAdmin(admin.ModelAdmin):
|
2018-02-11 11:18:15 +01:00
|
|
|
list_display = ('uuid', 'location', 'report_user', 'last_seen')
|
|
|
|
fields = ['location', 'uuid', 'report_user', 'last_seen']
|
2017-01-06 20:16:21 +01:00
|
|
|
|
|
|
|
|
2018-02-19 10:33:09 +01:00
|
|
|
@admin.register(ClientData)
|
|
|
|
class ClientDataAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('uuid', 'last_seen')
|
|
|
|
fields = ['location', 'last_seen']
|
|
|
|
|
|
|
|
|
2017-01-06 20:24:36 +01:00
|
|
|
@admin.register(LocationData)
|
|
|
|
class LocationDataAdmin(admin.ModelAdmin):
|
2017-08-03 19:52:43 +02:00
|
|
|
def get_urls(self):
|
|
|
|
urls = super().get_urls()
|
|
|
|
my_urls = [
|
2018-02-11 10:56:44 +01:00
|
|
|
url(r'^process_locationdata/$', self.admin_site.admin_view(self.process_locationdata),
|
|
|
|
name='process_locationdata'),
|
2017-08-03 19:52:43 +02:00
|
|
|
]
|
|
|
|
return my_urls + urls
|
|
|
|
|
|
|
|
def process_locationdata(self, request):
|
2018-03-31 15:59:03 +02:00
|
|
|
from .tasks import process_location_data
|
2018-03-31 16:40:32 +02:00
|
|
|
process_location_data(sender=None)
|
2017-08-04 19:41:44 +02:00
|
|
|
messages.success(request, 'Items processed.')
|
2017-08-03 19:52:43 +02:00
|
|
|
return redirect('admin:billard_locationdata_changelist')
|
2018-02-11 10:56:44 +01:00
|
|
|
|
2017-02-10 20:49:38 +01:00
|
|
|
list_display = ('client_id', 'desk_no', 'tst', 'on_off', 'processed', 'error_msg')
|
2019-02-28 19:04:24 +01:00
|
|
|
list_filter = ('client_id', 'desk_no', 'processed')
|
2017-02-10 20:49:38 +01:00
|
|
|
fields = ['client_id', 'desk_no', 'tst', 'on_off', 'processed', 'error_msg']
|
2017-02-01 20:25:33 +01:00
|
|
|
|
|
|
|
|
2017-02-11 18:36:32 +01:00
|
|
|
class DeskAdminForm(forms.ModelForm):
|
|
|
|
|
|
|
|
def clean_desk_no(self):
|
|
|
|
id = self.instance.id
|
2017-02-11 20:10:24 +01:00
|
|
|
client = self.cleaned_data['client']
|
2017-02-11 18:36:32 +01:00
|
|
|
desk_no = self.cleaned_data['desk_no']
|
|
|
|
t = Desk.objects.filter(desk_no=desk_no, client=client).exclude(id=id)
|
|
|
|
if t.count() > 0:
|
|
|
|
raise ValidationError('Tischnummer bereits vergeben.')
|
|
|
|
return self.cleaned_data['desk_no']
|
|
|
|
|
|
|
|
|
2017-02-10 18:37:36 +01:00
|
|
|
@admin.register(Desk)
|
|
|
|
class DeskAdmin(admin.ModelAdmin):
|
2017-02-11 18:36:32 +01:00
|
|
|
form = DeskAdminForm
|
2017-02-10 18:37:36 +01:00
|
|
|
list_display = ('client', 'desk_no', 'name', 'enabled', 'prize', 'prize_hh')
|
|
|
|
|
|
|
|
|
2017-02-01 20:25:33 +01:00
|
|
|
@admin.register(Accounting)
|
|
|
|
class AccountingAdmin(admin.ModelAdmin):
|
2017-04-29 11:15:26 +02:00
|
|
|
list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed', 'account_user', 'account_tst')
|
|
|
|
list_filter = ('desk__client__location', 'account_user', 'account_tst', 'billed')
|
|
|
|
|
|
|
|
def has_add_permission(self, request):
|
2017-04-29 11:34:18 +02:00
|
|
|
if request.user.username == 'reinsle':
|
|
|
|
return True
|
2017-04-29 11:15:26 +02:00
|
|
|
return False
|