53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.shortcuts import render
|
|
from rest_framework.views import APIView
|
|
|
|
from core.forms import DrugForm
|
|
from core.models import Drug
|
|
from mxs.restrictions import StaffMemberRequiredMixin
|
|
from mxs.views import ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate
|
|
|
|
|
|
class DrugList(LoginRequiredMixin, StaffMemberRequiredMixin, ObjectList):
|
|
list_template = "partials/drug-list.html"
|
|
model = Drug
|
|
page_title = "Global list of drugs"
|
|
|
|
list_url_name = "drugs"
|
|
list_url_args = ["type"]
|
|
|
|
submit_url_name = "drug_create"
|
|
delete_all_url_name = "drug_clear"
|
|
|
|
|
|
class DrugCreate(LoginRequiredMixin, StaffMemberRequiredMixin, ObjectCreate):
|
|
model = Drug
|
|
form_class = DrugForm
|
|
|
|
submit_url_name = "drug_create"
|
|
|
|
|
|
class DrugUpdate(LoginRequiredMixin, StaffMemberRequiredMixin, ObjectUpdate):
|
|
model = Drug
|
|
form_class = DrugForm
|
|
|
|
submit_url_name = "drug_update"
|
|
|
|
|
|
class DrugDelete(LoginRequiredMixin, StaffMemberRequiredMixin, ObjectDelete):
|
|
model = Drug
|
|
|
|
|
|
class DrugClear(LoginRequiredMixin, StaffMemberRequiredMixin, APIView):
|
|
def delete(self, request):
|
|
template_name = "mixins/partials/notify.html"
|
|
drugs_all = Drug.objects.all()
|
|
drugs_all.delete()
|
|
context = {
|
|
"message": "Deleted all drugs",
|
|
"class": "success",
|
|
}
|
|
response = render(request, template_name, context)
|
|
response["HX-Trigger"] = "drugEvent"
|
|
return response
|