feat(qrcode): Automatic generation of qrcodes

This commit is contained in:
sinavir 2024-07-03 01:50:01 +02:00
parent 541d840727
commit b95b0ccd3f
5 changed files with 40 additions and 25 deletions

View file

@ -38,6 +38,9 @@ in
ps.markdown-icons ps.markdown-icons
ps.authens ps.authens
ps.qrcode
ps.pillow
# Django haystack is drunk # Django haystack is drunk
ps.setuptools ps.setuptools
])) ]))

View file

@ -30,6 +30,9 @@
<a class="button" href="{% url "inventory:game_loan" game.slug %}"> <a class="button" href="{% url "inventory:game_loan" game.slug %}">
Emprunter ou rendre « {{ game.title }} » Emprunter ou rendre « {{ game.title }} »
</a> </a>
<a class="button" href="{% url "inventory:qrcode_borrow" game.slug %}">
Générer un QR-code
</a>
<h2 id="description">Description</h2> <h2 id="description">Description</h2>
{{ object.description|linebreaks }} {{ object.description|linebreaks }}

View file

@ -1,21 +1,10 @@
from django.urls import path from django.urls import path
from .views import (
InventoryView, from .views import (AddGameCommentView, BorrowGameView, CategoryListView,
CategoryListView, CategoryView, DetailLoanView, GameListView, GameLoanView,
CategoryView, GameView, InventorySearchView, InventoryView,
TagListView, ModifyGameCommentView, OngoingLoansView, QrCodeView,
TagView, ReturnGameView, TagListView, TagView)
GameListView,
GameView,
AddGameCommentView,
ModifyGameCommentView,
InventorySearchView,
GameLoanView,
BorrowGameView,
ReturnGameView,
OngoingLoansView,
DetailLoanView,
)
app_name = "inventory" app_name = "inventory"
@ -39,6 +28,11 @@ urlpatterns = [
path("loans/game/<slug>/", GameLoanView.as_view(), name="game_loan"), path("loans/game/<slug>/", GameLoanView.as_view(), name="game_loan"),
path("loans/return/<slug>/", ReturnGameView.as_view(), name="return_game"), path("loans/return/<slug>/", ReturnGameView.as_view(), name="return_game"),
path("loans/borrow/<slug>/", BorrowGameView.as_view(), name="borrow_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/ongoing/", OngoingLoansView.as_view(), name="ongoing_loans"),
path("loans/all/", DetailLoanView.as_view(), name="all_loans"), path("loans/all/", DetailLoanView.as_view(), name="all_loans"),
] ]

View file

@ -1,13 +1,17 @@
from django.views.generic import TemplateView, ListView, DetailView import qrcode
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
from comments.views import AddCommentView, ModifyCommentView from comments.views import AddCommentView, ModifyCommentView
from loans.views import BorrowView, ReturnView, DetailLoanView from django.contrib.auth.mixins import PermissionRequiredMixin
from .models import Category, Tag, Game, GameComment, GameLoan 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 .forms import BorrowGameForm
from .models import Category, Game, GameComment, GameLoan, Tag
from .tables import LoanTable, OngoingLoansTable from .tables import LoanTable, OngoingLoansTable
@ -102,3 +106,13 @@ class DetailLoanView(PermissionRequiredMixin, SingleTableView):
table_class = LoanTable table_class = LoanTable
template_name = "inventory/loans/loans_table.html" 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

View file

@ -7,5 +7,6 @@ django-markdownx==4.0.5
django-tables2==2.7.0 django-tables2==2.7.0
markdown-iconfonts==3.0.0 markdown-iconfonts==3.0.0
Pillow==10.1.0 Pillow==10.1.0
qrcode>=7.4.2
Whoosh==2.7.4 Whoosh==2.7.4
loadcredential==1.1 loadcredential==1.1