2024-05-17 21:47:16 +00:00
|
|
|
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)
|
2024-05-18 02:13:31 +00:00
|
|
|
return info
|
2024-05-17 21:47:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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
|