move code to use generic views
This commit is contained in:
		@@ -28,9 +28,9 @@
 | 
			
		||||
            </div>
 | 
			
		||||
            <div id="navbar" class="collapse navbar-collapse">
 | 
			
		||||
                <ul class="nav navbar-nav">
 | 
			
		||||
                    <li class="{% ifequal request.path '/billard/' %}active{% endifequal %}"><a href="{% url "carom_index" %}">Tische</a></li>
 | 
			
		||||
                    <li class="{% ifequal request.path '/billard/' %}active{% endifequal %}"><a href="{% url "billard:location_list" %}">Standorte</a></li>
 | 
			
		||||
{% if perms.billard.change_accounting %}
 | 
			
		||||
                    <li class="{% ifequal request.path '/billard/accounting' %}active{% endifequal %}"><a href="{% url "accounting" %}">Abrechnung</a></li>
 | 
			
		||||
                    <li class="{% ifequal request.path '/billard/accounting' %}active{% endifequal %}"><a href="{% url "billard:location_list" %}">Abrechnung</a></li>
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if user.is_superuser %}
 | 
			
		||||
                    <li class="{% ifequal request.path '/logout/' %}active{% endifequal %}"><a href="/admin/">Administration</a></li>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										30
									
								
								billard/templates/billard/location_list.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								billard/templates/billard/location_list.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
{% extends 'billard/base.html' %}
 | 
			
		||||
 | 
			
		||||
{% block title %}Location List{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
 | 
			
		||||
{% if location_list %}
 | 
			
		||||
    <table class="table table-hover">
 | 
			
		||||
        <tr>
 | 
			
		||||
            <th>Code</th>
 | 
			
		||||
            <th>Name</th>
 | 
			
		||||
            <th>Strasse</th>
 | 
			
		||||
            <th>Plz</th>
 | 
			
		||||
            <th>Ort</th>
 | 
			
		||||
        </tr>
 | 
			
		||||
{% for loc in location_list %}
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td><a href="{% url 'billard:location_detail' loc.id %}">{{ loc.code }}</a></td>
 | 
			
		||||
            <td><a href="{% url 'billard:location_detail' loc.id %}">{{ loc.name }}</a></td>
 | 
			
		||||
            <td><a href="{% url 'billard:location_detail' loc.id %}">{{ loc.street }}</a></td>
 | 
			
		||||
            <td><a href="{% url 'billard:location_detail' loc.id %}">{{ loc.plz }}</a></td>
 | 
			
		||||
            <td><a href="{% url 'billard:location_detail' loc.id %}">{{ loc.city }}</a></td>
 | 
			
		||||
        </tr>
 | 
			
		||||
{% endfor %}
 | 
			
		||||
    </table>
 | 
			
		||||
{% else %}
 | 
			
		||||
    <p>Keine Standorte Zugeordnet.</p>
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -1,16 +1,27 @@
 | 
			
		||||
from django.conf.urls import url, include
 | 
			
		||||
from django.contrib.auth.decorators import login_required
 | 
			
		||||
from rest_framework import routers
 | 
			
		||||
from billard import views
 | 
			
		||||
 | 
			
		||||
router = routers.DefaultRouter()
 | 
			
		||||
router.register(r'location_data', views.LocationDataViewSet)
 | 
			
		||||
 | 
			
		||||
app_name = 'billard'
 | 
			
		||||
urlpatterns = [
 | 
			
		||||
    url(r'^$', views.index, name='carom_index'),
 | 
			
		||||
    url(r'^(?P<pk>[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'),
 | 
			
		||||
    url(r'api/v1/', include(router.urls)),
 | 
			
		||||
    url(r'process_locationdata', views.process_locationdata, name='process_locationdata'),
 | 
			
		||||
    url(r'accounting', views.accounting, name='accounting'),
 | 
			
		||||
    url(r'accountmodal$', views.accountmodalview, name='accountmodal'),
 | 
			
		||||
    url(r'accoutmodal/confirm/(?P<pk>[0-9]+)$', views.accountmodalconfirmview, name="accountmodalconfirm")
 | 
			
		||||
    # ex. /billard/
 | 
			
		||||
    url(r'^$', login_required(views.LocationListView.as_view()), name='location_list'),
 | 
			
		||||
    # ex. /billard/1/
 | 
			
		||||
    url(r'^(?P<pk>[0-9]+)/$', login_required(views.LocationDetailView.as_view()), name='location_detail'),
 | 
			
		||||
    # ex. /billard/1/accounting/
 | 
			
		||||
    #url(r'^(?P<pk>[0-9]+)/accounting/$', views.ResultsView.as_view(), name='accounting_detail'),
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    #url(r'^$', views.index, name='carom_index'),
 | 
			
		||||
    #url(r'^(?P<pk>[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'),
 | 
			
		||||
    #url(r'api/v1/', include(router.urls)),
 | 
			
		||||
    #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]+)
 | 
			
		||||
]
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,27 @@ from django.db.models import Min, Sum
 | 
			
		||||
from django.http import HttpResponse
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class LocationListView(generic.ListView):
 | 
			
		||||
    template_name = 'billard/location_list.html'
 | 
			
		||||
    context_object_name = 'location_list'
 | 
			
		||||
 | 
			
		||||
    def get_queryset(self):
 | 
			
		||||
        """Return the last five published questions."""
 | 
			
		||||
        return Location.objects.filter(users__id=self.request.user.id).order_by('code')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class LocationDetailView(generic.ListView):
 | 
			
		||||
    template_name = 'billard/location_list.html'
 | 
			
		||||
    context_object_name = 'location_list'
 | 
			
		||||
 | 
			
		||||
    def get_queryset(self):
 | 
			
		||||
        """Return the last five published questions."""
 | 
			
		||||
        return Location.objects.filter(users__id=self.request.user.id).order_by('code')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# TODO OLD CODE, CLEAN UP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class LocationDataViewSet(viewsets.ModelViewSet):
 | 
			
		||||
    queryset = LocationData.objects.all()
 | 
			
		||||
    serializer_class = LocationDataSerializer
 | 
			
		||||
@@ -143,6 +164,18 @@ def index(request):
 | 
			
		||||
        return resp
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#@login_required
 | 
			
		||||
#@permission_required('billard.change_accounting')
 | 
			
		||||
class AccountingView(generic.ListView):
 | 
			
		||||
    template_name = 'billard/accounting.html'
 | 
			
		||||
    context_object_name = 'accounting'
 | 
			
		||||
 | 
			
		||||
    def get_queryset(self):
 | 
			
		||||
        return Accounting.objects.filter(billed=False).exclude(time_to__isnull=True)\
 | 
			
		||||
            #.\
 | 
			
		||||
            #filter(desk__client__location_id=loc).order_by('-time_from')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def process_locationdata(request):
 | 
			
		||||
    process_location_data()
 | 
			
		||||
    return HttpResponse('DONE')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user