forked from DGNum/gestiojeux
feat(qrcode): Automatic generation of qrcodes
This commit is contained in:
parent
541d840727
commit
3a730251d4
5 changed files with 42 additions and 25 deletions
|
@ -38,6 +38,9 @@ in
|
|||
ps.markdown-icons
|
||||
ps.authens
|
||||
|
||||
ps.qrcode
|
||||
ps.pillow
|
||||
|
||||
# Django haystack is drunk
|
||||
ps.setuptools
|
||||
]))
|
||||
|
|
|
@ -30,6 +30,11 @@
|
|||
<a class="button" href="{% url "inventory:game_loan" game.slug %}">
|
||||
Emprunter ou rendre « {{ game.title }} »
|
||||
</a>
|
||||
{% if user.is_staff %}
|
||||
<a class="button" href="{% url "inventory:qrcode_borrow" game.slug %}">
|
||||
Générer un QR-code
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<h2 id="description">Description</h2>
|
||||
{{ object.description|linebreaks }}
|
||||
|
|
|
@ -1,21 +1,10 @@
|
|||
from django.urls import path
|
||||
from .views import (
|
||||
InventoryView,
|
||||
CategoryListView,
|
||||
CategoryView,
|
||||
TagListView,
|
||||
TagView,
|
||||
GameListView,
|
||||
GameView,
|
||||
AddGameCommentView,
|
||||
ModifyGameCommentView,
|
||||
InventorySearchView,
|
||||
GameLoanView,
|
||||
BorrowGameView,
|
||||
ReturnGameView,
|
||||
OngoingLoansView,
|
||||
DetailLoanView,
|
||||
)
|
||||
|
||||
from .views import (AddGameCommentView, BorrowGameView, CategoryListView,
|
||||
CategoryView, DetailLoanView, GameListView, GameLoanView,
|
||||
GameView, InventorySearchView, InventoryView,
|
||||
ModifyGameCommentView, OngoingLoansView, QrCodeView,
|
||||
ReturnGameView, TagListView, TagView)
|
||||
|
||||
app_name = "inventory"
|
||||
|
||||
|
@ -39,6 +28,11 @@ urlpatterns = [
|
|||
path("loans/game/<slug>/", GameLoanView.as_view(), name="game_loan"),
|
||||
path("loans/return/<slug>/", ReturnGameView.as_view(), name="return_game"),
|
||||
path("loans/borrow/<slug>/", BorrowGameView.as_view(), name="borrow_game"),
|
||||
path(
|
||||
"qrcode/borrow/<slug>/",
|
||||
QrCodeView.as_view(url="inventory:borrow_game"),
|
||||
name="qrcode_borrow",
|
||||
),
|
||||
path("loans/ongoing/", OngoingLoansView.as_view(), name="ongoing_loans"),
|
||||
path("loans/all/", DetailLoanView.as_view(), name="all_loans"),
|
||||
]
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
from django.views.generic import TemplateView, ListView, DetailView
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from haystack.generic_views import SearchView
|
||||
from haystack.forms import SearchForm
|
||||
from haystack.query import SearchQuerySet
|
||||
from django_tables2.views import SingleTableView
|
||||
import qrcode
|
||||
from comments.views import AddCommentView, ModifyCommentView
|
||||
from loans.views import BorrowView, ReturnView, DetailLoanView
|
||||
from .models import Category, Tag, Game, GameComment, GameLoan
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.http import HttpResponse
|
||||
from django.urls import reverse
|
||||
from django.views.generic import DetailView, ListView, TemplateView
|
||||
from django_tables2.views import SingleTableView
|
||||
from haystack.forms import SearchForm
|
||||
from haystack.generic_views import SearchView
|
||||
from haystack.query import SearchQuerySet
|
||||
from loans.views import BorrowView, DetailLoanView, ReturnView
|
||||
|
||||
from .forms import BorrowGameForm
|
||||
from .models import Category, Game, GameComment, GameLoan, Tag
|
||||
from .tables import LoanTable, OngoingLoansTable
|
||||
|
||||
|
||||
|
@ -102,3 +106,13 @@ class DetailLoanView(PermissionRequiredMixin, SingleTableView):
|
|||
table_class = LoanTable
|
||||
template_name = "inventory/loans/loans_table.html"
|
||||
|
||||
|
||||
class QrCodeView(DetailView):
|
||||
model = Game
|
||||
url = "inventory:game" # Sensible default
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
response = HttpResponse(content_type="image/png")
|
||||
img = qrcode.make(reverse(self.url, kwargs={"slug": self.get_object().slug}))
|
||||
img.save(response, "PNG")
|
||||
return response
|
||||
|
|
|
@ -7,5 +7,6 @@ django-markdownx==4.0.5
|
|||
django-tables2==2.7.0
|
||||
markdown-iconfonts==3.0.0
|
||||
Pillow==10.1.0
|
||||
qrcode>=7.4.2
|
||||
Whoosh==2.7.4
|
||||
loadcredential==1.1
|
||||
|
|
Loading…
Add table
Reference in a new issue