drugs/core/views/favourites.py

86 lines
2.4 KiB
Python
Raw Normal View History

from django.contrib.auth.mixins import LoginRequiredMixin
# from mixins.restrictions import StaffMemberRequiredMixin
from mixins.views import (
ObjectCreate,
ObjectDelete,
ObjectList,
ObjectRead,
ObjectUpdate,
)
from core.forms import FavouriteForm
from core.models import Favourite
class FavouriteList(LoginRequiredMixin, ObjectList):
list_template = "partials/favourite-list.html"
model = Favourite
page_title = "Global list of favourites"
list_url_name = "favourites"
list_url_args = ["type"]
submit_url_name = "favourite_create"
class FavouriteCreate(LoginRequiredMixin, ObjectCreate):
model = Favourite
form_class = FavouriteForm
submit_url_name = "favourite_create"
class FavouriteUpdate(LoginRequiredMixin, ObjectUpdate):
model = Favourite
form_class = FavouriteForm
submit_url_name = "favourite_update"
class FavouriteDelete(LoginRequiredMixin, ObjectDelete):
model = Favourite
class FavouriteDetail(LoginRequiredMixin, ObjectRead):
model = Favourite
form_class = FavouriteForm
detail_template = "partials/drug-detail.html"
detail_url_name = "favourite_detail"
detail_url_args = ["type", "pk"]
def get_object(self, **kwargs):
pk = kwargs.get("pk")
info = Favourite.objects.get(pk=pk, user=self.request.user)
return info.__dict__
# class FavouriteClear(LoginRequiredMixin, APIView):
# def delete(self, request):
# template_name = "mixins/partials/notify.html"
# favourites_all = Favourite.objects.all()
# favourites_all.delete()
# context = {
# "message": "Deleted all favourites",
# "class": "success",
# }
# response = render(request, template_name, context)
# response["HX-Trigger"] = "drugEvent"
# return response
# class FavouritePullMerge(LoginRequiredMixin, APIView):
# def post(self, request):
# template_name = "mixins/partials/notify.html"
# # Do something
# run = synchronize_async_helper(PsychWikiClient())
# result = synchronize_async_helper(run.update_favourites())
# context = {
# "message": f"Favourites fetched: {result}",
# "class": "success",
# }
# response = render(request, template_name, context)
# response["HX-Trigger"] = "drugEvent"
# return response