Keep view code in the respective apps, implement the template in the profiles app.

This commit is contained in:
Víðir Valberg Guðmundsson 2019-03-26 21:22:54 +01:00
parent 50d40eb7df
commit 0b2075425e
18 changed files with 165 additions and 186 deletions

View file

@ -46,14 +46,16 @@
{% if user.orders.exists %} {% if user.orders.exists %}
<li><b>Shop</b></li> <li><b>Shop</b></li>
<li {% if view.active_menu == "orders" %}class="active"{% endif %}> {% url 'shop:order_list' as orders_list_url %}
<a href="{% url 'shop:order_list' %}"> <li {% if "shop/order" in request.path %}class="active"{% endif %}>
<a href="{{ orders_list_url }}">
Orders Orders
</a> </a>
</li> </li>
<li {% if view.active_menu == "tickets" %}class="active"{% endif %}> {% url 'tickets:shopticket_list' as ticket_list_url %}
<a href="{% url 'tickets:shopticket_list' %}"> <li {% if "tickets" in request.path %}class="active"{% endif %}>
<a href="{{ ticket_list_url }}">
Tickets Tickets
</a> </a>
</li> </li>
@ -69,7 +71,7 @@
{% endif %} {% endif %}
<li><b>Misc.</b></li> <li><b>Misc.</b></li>
{% url 'profiles:tokenfind_list' as tokenfind_list_url %} {% url 'tokens:tokenfind_list' as tokenfind_list_url %}
<li {% if request.path == tokenfind_list_url %}class="active"{% endif %}> <li {% if request.path == tokenfind_list_url %}class="active"{% endif %}>
<a href="{{ tokenfind_list_url }}"> <a href="{{ tokenfind_list_url }}">
Secret Tokens Secret Tokens

View file

@ -1,8 +1,9 @@
{% extends 'shop_base.html' %} {% extends 'profile_base.html' %}
{% load bootstrap3 %} {% load bootstrap3 %}
{% load shop_tags %} {% load shop_tags %}
{% block shop_content %} {% block profile_content %}
<div class="panel-group"> <div class="panel-group">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel panel-heading"> <div class="panel panel-heading">

View file

@ -0,0 +1,55 @@
{% extends 'profile_base.html' %}
{% load bootstrap3 %}
{% load shop_tags %}
{% load bornhack %}
{% block profile_content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4>Orders</h4>
</div>
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th>Order ID</th>
<th>Items</th>
<th>Total amount</th>
<th>Open?</th>
<th>Paid?</th>
<th>Delivered?</th>
<th>Invoice</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for order in orders %}
{% if order.products.exists %}
<tr {% if not order.open and order.paid and order.is_fully_handed_out %}style="color: lightgrey"{% endif %}>
<td>{{ order.id }}</td>
<td>{{ order.get_number_of_items }}</td>
<td>{{ order.total|currency }}</td>
<td class="text-center">{{ order.open|truefalseicon }}</td>
<td class="text-center">{{ order.paid|truefalseicon }}</td>
<td class="text-center">{{ order.handed_out_status }}</td>
<td>
{% if order.invoice.pdf %}
{% url 'shop:download_invoice' pk=order.pk as invoice_download_url %}
{% bootstrap_button "PDF" icon="save-file" href=invoice_download_url button_class="btn-primary btn-xs" %}
{% else %}
N/A
{% endif %}
</td>
<td>
{% url 'shop:order_detail' pk=order.pk as order_detail_url %}
{% bootstrap_button "Order details" icon="th-list" href=order_detail_url button_class="btn-primary btn-xs" %}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,24 @@
{% extends 'profile_base.html' %}
{% load bootstrap3 %}
{% load tickets_tags %}
{% block profile_content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4>Your Tickets</h4>
</div>
<div class="panel-body">
<h2>{% if ticket.checked_in %}This ticket has been used{% else %}This ticket is unused{% endif %}</h2>
<form method="POST" class="form">
{% csrf_token %}
{% bootstrap_field form.name %}
{% bootstrap_field form.email %}
<button class="btn btn-primary form-control" type="submit"><i class="glyphicon glyphicon-check"></i> Save</button>
</form>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,60 @@
{% extends 'profile_base.html' %}
{% load bootstrap3 %}
{% load tickets_tags %}
{% block profile_content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4>Your Tickets</h4>
</div>
<div class="panel-body">
{% if tickets %}
<table class="table table-hover">
<thead>
<tr>
<th>
Ticket owner
<th>
Product name
<th>
Price
<th>
Checked in
<th>
Actions
<tbody>
{% for ticket in tickets %}
<tr>
<td>
{% if ticket.name %}
{{ ticket.name }}
{% else %}
Anonymous
{% endif %}
<td>
{{ ticket.product.name }}
<td>
{{ ticket.product.price|currency }}
<td>
{% if ticket.checked_in %}
Yes
{% else %}
Not yet
{% endif %}
<td>
<a href="{% url 'tickets:shopticket_download' pk=ticket.pk %}" class="btn btn-primary"><i class="fas fa-download" aria-hidden="true"></i> Download PDF</a>
{% if not ticket.name %}
<a href="{% url 'tickets:shopticket_edit' pk=ticket.pk %}" class="btn btn-primary"><i class="fas fa-edit" aria-hidden="true"></i> Set name</a>
{% else %}
<a href="{% url 'tickets:shopticket_edit' pk=ticket.pk %}" class="btn btn-primary"><i class="fas fa-edit" aria-hidden="true"></i> Edit name</a>
{% endif %}
{% endfor %}
</table>
{% else %}
<h3> You don't have any tickets yet. We hope to see you at the next BornHack!</h3>
{% endif %}
</div>
{% endblock %}

View file

@ -1,14 +1,12 @@
from django.urls import path from django.urls import path
from .views import ProfileDetail, ProfileUpdate, ProfileTokenFindsView from .views import (
ProfileDetail,
ProfileUpdate,
)
app_name = 'profiles' app_name = 'profiles'
urlpatterns = [ urlpatterns = [
path('', ProfileDetail.as_view(), name='detail'), path('', ProfileDetail.as_view(), name='detail'),
path('edit', ProfileUpdate.as_view(), name='update'), path('edit', ProfileUpdate.as_view(), name='update'),
path(
'tokens',
ProfileTokenFindsView.as_view(),
name='tokenfind_list'
),
] ]

View file

@ -3,7 +3,6 @@ from django.views.generic import DetailView, UpdateView
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.contrib import messages from django.contrib import messages
from tokens.views import TokenFindListBaseView
from . import models from . import models
@ -32,7 +31,3 @@ class ProfileUpdate(LoginRequiredMixin, UpdateView):
form.instance.save() form.instance.save()
messages.success(self.request, 'Your profile has been updated.') messages.success(self.request, 'Your profile has been updated.')
return super().form_valid(form, **kwargs) return super().form_valid(form, **kwargs)
class ProfileTokenFindsView(TokenFindListBaseView):
template_name = "tokenfind_list.html"

View file

@ -1,49 +0,0 @@
{% extends 'shop_base.html' %}
{% load bootstrap3 %}
{% load shop_tags %}
{% load bornhack %}
{% block shop_content %}
<h3>Orders</h3>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Order ID</th>
<th>Items</th>
<th>Total amount</th>
<th>Open?</th>
<th>Paid?</th>
<th>Delivered?</th>
<th>Invoice</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for order in orders %}
{% if order.products.exists %}
<tr {% if not order.open and order.paid and order.is_fully_handed_out %}style="color: lightgrey"{% endif %}>
<td>{{ order.id }}</td>
<td>{{ order.get_number_of_items }}</td>
<td>{{ order.total|currency }}</td>
<td class="text-center">{{ order.open|truefalseicon }}</td>
<td class="text-center">{{ order.paid|truefalseicon }}</td>
<td class="text-center">{{ order.handed_out_status }}</td>
<td>
{% if order.invoice.pdf %}
{% url 'shop:download_invoice' pk=order.pk as invoice_download_url %}
{% bootstrap_button "PDF" icon="save-file" href=invoice_download_url button_class="btn-primary btn-xs" %}
{% else %}
N/A
{% endif %}
</td>
<td>
{% url 'shop:order_detail' pk=order.pk as order_detail_url %}
{% bootstrap_button "Order details" icon="th-list" href=order_detail_url button_class="btn-primary btn-xs" %}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endblock %}

View file

@ -16,9 +16,6 @@
{% if user.creditnotes.exists %} {% if user.creditnotes.exists %}
<li class="pull-right"><a href="{% url 'shop:creditnote_list' %}">Credit Notes</a></li> <li class="pull-right"><a href="{% url 'shop:creditnote_list' %}">Credit Notes</a></li>
{% endif %} {% endif %}
{% if has_tickets %}
<li class="pull-right"><a href="{% url 'tickets:shopticket_list' %}">Tickets</a></li>
{% endif %}
<li class="pull-right"><a href="{% url 'shop:order_list' %}">Orders</a></li> <li class="pull-right"><a href="{% url 'shop:order_list' %}">Orders</a></li>
<li class="pull-right no-before"> <li class="pull-right no-before">

View file

@ -278,7 +278,7 @@ class ProductDetailView(FormView, DetailView):
class OrderListView(LoginRequiredMixin, ListView): class OrderListView(LoginRequiredMixin, ListView):
model = Order model = Order
template_name = "order_list.html" template_name = "shop/order_list.html"
context_object_name = 'orders' context_object_name = 'orders'
def get_queryset(self): def get_queryset(self):
@ -288,7 +288,7 @@ class OrderListView(LoginRequiredMixin, ListView):
class OrderDetailView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureOrderHasProductsMixin, EnsureOrderIsNotCancelledMixin, DetailView): class OrderDetailView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureOrderHasProductsMixin, EnsureOrderIsNotCancelledMixin, DetailView):
model = Order model = Order
template_name = 'order_detail.html' template_name = 'shop/order_detail.html'
context_object_name = 'order' context_object_name = 'order'
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):

View file

@ -1,30 +0,0 @@
{% extends 'tickets_base.html' %}
{% load bootstrap3 %}
{% load tickets_tags %}
{% block tickets_content %}
<div class="well">
<div class="row">
<div class="col-md-7">
<div class="pull-right">
<h2>{% if ticket.checked_in %}This ticket has been used{% else %}This ticket is unused{% endif %}</h2>
<form method="POST" class="form">
{% csrf_token %}
{% bootstrap_field form.name %}
{% bootstrap_field form.email %}
<button class="btn btn-primary form-control" type="submit"><i class="glyphicon glyphicon-check"></i> Save</button>
</form>
<hr />
</div>
</div>
</div>
</div>
{% endblock %}

View file

@ -1,55 +0,0 @@
{% extends 'tickets_base.html' %}
{% load bootstrap3 %}
{% load tickets_tags %}
{% block tickets_content %}
{% if tickets %}
<h3>Tickets</h3>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>
Ticket owner
<th>
Product name
<th>
Price
<th>
Checked in
<th>
Actions
<tbody>
{% for ticket in tickets %}
<tr>
<td>
{% if ticket.name %}
{{ ticket.name }}
{% else %}
Anonymous
{% endif %}
<td>
{{ ticket.product.name }}
<td>
{{ ticket.product.price|currency }}
<td>
{% if ticket.checked_in %}
Yes
{% else %}
Not yet
{% endif %}
<td>
<a href="{% url 'tickets:shopticket_download' pk=ticket.pk %}" class="btn btn-primary"><i class="fas fa-download" aria-hidden="true"></i> Download PDF</a>
{% if not ticket.name %}
<a href="{% url 'tickets:shopticket_edit' pk=ticket.pk %}" class="btn btn-primary"><i class="fas fa-edit" aria-hidden="true"></i> Set name</a>
{% else %}
<a href="{% url 'tickets:shopticket_edit' pk=ticket.pk %}" class="btn btn-primary"><i class="fas fa-edit" aria-hidden="true"></i> Edit name</a>
{% endif %}
{% endfor %}
</table>
{% else %}
<h3> You dont have any tickets yet. We hope to see you at the next BornHack!</h3>
{% endif %}
{% endblock %}

View file

@ -1,21 +0,0 @@
{% extends 'base.html' %}
{% block content %}
<div class="row">
<div class="col-md-12">
<ol class="breadcrumb">
<li><a href="{% url 'tickets:shopticket_list' %}">Tickets</a></li>
<li class="pull-right no-before">
</li>
</ol>
</div>
</div>
{% block tickets_content %}
{% endblock %}
{% endblock %}

View file

@ -20,7 +20,7 @@ logger = logging.getLogger("bornhack.%s" % __name__)
class ShopTicketListView(LoginRequiredMixin, ListView): class ShopTicketListView(LoginRequiredMixin, ListView):
model = ShopTicket model = ShopTicket
template_name = 'ticket_list.html' template_name = 'tickets/ticket_list.html'
context_object_name = 'tickets' context_object_name = 'tickets'
def get_queryset(self): def get_queryset(self):
@ -50,7 +50,7 @@ class ShopTicketDownloadView(LoginRequiredMixin, SingleObjectMixin, View):
class ShopTicketDetailView(LoginRequiredMixin, UpdateView, DetailView): class ShopTicketDetailView(LoginRequiredMixin, UpdateView, DetailView):
model = ShopTicket model = ShopTicket
template_name = 'ticket_detail.html' template_name = 'tickets/ticket_detail.html'
context_object_name = 'ticket' context_object_name = 'ticket'
fields = ['name', 'email'] fields = ['name', 'email']

View file

@ -11,6 +11,6 @@ Secret Token Found! | {{ block.super }}
<p class="lead text-center">You found a secret token:</p> <p class="lead text-center">You found a secret token:</p>
<p class="lead text-center"><span class="badge">{{ token.description }}</span></p> <p class="lead text-center"><span class="badge">{{ token.description }}</span></p>
<p class="lead text-center">Your visit has been registered! Keep hunting, there might be more tokens out there.</p> <p class="lead text-center">Your visit has been registered! Keep hunting, there might be more tokens out there.</p>
<p class="lead text-center"><a href="{% url 'tokens:tokenfind_list' %}">List All Tokens</a></p> <p class="lead text-center"><a href="{% url 'tokens:tokenfind_list' %}">List All Found Tokens</a></p>
{% endblock %} {% endblock %}

View file

@ -1,9 +1,10 @@
from django.urls import re_path from django.urls import re_path, path
from .views import TokenDetailView from .views import TokenDetailView, TokenFindListView
app_name = 'tokens' app_name = 'tokens'
urlpatterns = [ urlpatterns = [
path('', TokenFindListView.as_view(), name='tokenfind_list'),
re_path( re_path(
'(?P<token>[0-9a-zA-Z\.@]+)/$', '(?P<token>[0-9a-zA-Z\.@]+)/$',
TokenDetailView.as_view(), TokenDetailView.as_view(),

View file

@ -19,11 +19,12 @@ class TokenDetailView(LoginRequiredMixin, DetailView):
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
class TokenFindListBaseView(LoginRequiredMixin, ListView): class TokenFindListView(LoginRequiredMixin, ListView):
""" """
This class is meant to be extended in other apps like `profiles`. This class is meant to be extended in other apps like `profiles`.
""" """
model = TokenFind model = TokenFind
template_name = "tokens/tokenfind_list.html"
def get_queryset(self): def get_queryset(self):
return TokenFind.objects.filter(user=self.request.user) return TokenFind.objects.filter(user=self.request.user)