2021-10-28 07:26:17 +00:00
|
|
|
from django.views.generic import CreateView, UpdateView, ListView, DetailView, FormView, View
|
2021-03-23 18:23:04 +00:00
|
|
|
from django.urls import reverse_lazy
|
2021-04-08 09:30:19 +00:00
|
|
|
from django.http import HttpResponseRedirect
|
2021-04-11 14:19:43 +00:00
|
|
|
from django.shortcuts import get_list_or_404, redirect, get_object_or_404
|
|
|
|
from django.contrib import messages
|
2021-10-28 07:26:17 +00:00
|
|
|
from django.http.response import JsonResponse
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-03-01 09:56:10 +00:00
|
|
|
|
2021-04-20 06:36:59 +00:00
|
|
|
from .models import PartnerProfile, Establishment, RoomCategory
|
2021-04-11 06:36:19 +00:00
|
|
|
from .mixins import PartnerProfileRequiredMixin
|
2021-04-17 18:35:29 +00:00
|
|
|
from .forms import VerificationForm
|
2021-03-22 17:42:07 +00:00
|
|
|
|
2021-04-08 16:34:21 +00:00
|
|
|
from auction.models import Inquiry, Offer
|
2021-05-30 14:10:08 +00:00
|
|
|
from frontend.mixins import InConstructionMixin
|
2021-04-17 18:35:29 +00:00
|
|
|
from localauth.mixins import LoginRequiredMixin, SuperUserRequiredMixin
|
2021-05-30 10:30:14 +00:00
|
|
|
from gallery.models import Image
|
2021-03-22 17:42:07 +00:00
|
|
|
|
2021-05-30 17:54:23 +00:00
|
|
|
from django_starfield import Stars
|
|
|
|
|
2021-10-28 07:26:17 +00:00
|
|
|
import uuid
|
|
|
|
|
2021-04-08 09:30:19 +00:00
|
|
|
class PartnerRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateView):
|
2021-03-22 17:42:07 +00:00
|
|
|
model = PartnerProfile
|
2021-03-23 18:23:04 +00:00
|
|
|
exclude = ["user"]
|
|
|
|
template_name = "partners/signup.html"
|
2021-04-14 11:15:36 +00:00
|
|
|
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country", "phone"]
|
2021-03-23 18:23:04 +00:00
|
|
|
|
2021-04-08 09:30:19 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
try:
|
|
|
|
PartnerProfile.objects.get(user=request.user)
|
|
|
|
return HttpResponseRedirect(reverse_lazy("partners:profile"))
|
|
|
|
except (PartnerProfile.DoesNotExist, TypeError):
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
2021-03-23 18:23:04 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.user = self.request.user
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
def get_success_url(self):
|
2021-10-28 07:26:17 +00:00
|
|
|
messages.success(self.request, _("Profil erfolgreich angelegt!"))
|
2021-03-23 18:23:04 +00:00
|
|
|
return reverse_lazy("partners:profile")
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
try:
|
|
|
|
client = self.request.user.clientprofile
|
|
|
|
|
|
|
|
return {
|
|
|
|
"company": client.company,
|
|
|
|
"vat_id": client.vat_id,
|
|
|
|
"first_name": client.first_name,
|
|
|
|
"last_name": client.last_name,
|
|
|
|
"street": client.street,
|
|
|
|
"city": client.city,
|
|
|
|
"zip": client.zip,
|
|
|
|
"state": client.state,
|
2021-04-14 11:15:36 +00:00
|
|
|
"country": client.country,
|
|
|
|
"phone": client.phone
|
2021-03-23 18:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
except:
|
2021-04-14 11:15:36 +00:00
|
|
|
return {
|
|
|
|
"country": "AT",
|
|
|
|
"phone": "+43"
|
|
|
|
}
|
2021-03-23 18:23:04 +00:00
|
|
|
|
2021-04-11 08:11:05 +00:00
|
|
|
class PartnerProfileView(InConstructionMixin, PartnerProfileRequiredMixin, UpdateView):
|
2021-03-23 18:23:04 +00:00
|
|
|
model = PartnerProfile
|
|
|
|
exclude = ["user"]
|
|
|
|
template_name = "partners/profile.html"
|
|
|
|
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"]
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse_lazy("partners:profile")
|
|
|
|
|
|
|
|
def get_object(self, queryset=None):
|
2021-04-08 16:34:21 +00:00
|
|
|
return self.request.user.partnerprofile
|
|
|
|
|
2021-04-11 08:11:05 +00:00
|
|
|
class OffersListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
|
2021-04-08 16:34:21 +00:00
|
|
|
model = Offer
|
|
|
|
template_name = "partners/offer_list.html"
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2021-04-20 11:37:36 +00:00
|
|
|
return Offer.objects.filter(roomcategory__in=self.request.user.partnerprofile.roomcategory_set.all())
|
2021-04-09 15:01:33 +00:00
|
|
|
|
2021-04-11 08:11:05 +00:00
|
|
|
class EstablishmentsListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
|
2021-04-09 15:01:33 +00:00
|
|
|
model = Establishment
|
|
|
|
template_name = "partners/establishment_list.html"
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2021-04-17 18:35:29 +00:00
|
|
|
return self.request.user.partnerprofile.establishment_set.all()
|
2021-04-11 06:36:19 +00:00
|
|
|
|
2021-04-20 06:36:59 +00:00
|
|
|
class RoomCategoryListView(InConstructionMixin, PartnerProfileRequiredMixin, CreateView, ListView):
|
|
|
|
model = RoomCategory
|
|
|
|
template_name = "partners/roomcategory_list.html"
|
|
|
|
fields = ["name", "average_price"]
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
self.establishment = self.get_establishment()
|
|
|
|
|
|
|
|
if not self.establishment:
|
2021-10-28 07:26:17 +00:00
|
|
|
messages.warning(request, _("Um bieten zu können, muss zuerst eine Unterkunft im System hinterlegt werden!"))
|
2021-04-20 06:36:59 +00:00
|
|
|
return redirect("partners:establishment_register")
|
|
|
|
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_establishment(self):
|
|
|
|
establishment = self.kwargs.get("id", None)
|
|
|
|
kwargs = {"owner": self.request.user.partnerprofile}
|
|
|
|
|
|
|
|
if establishment:
|
|
|
|
kwargs["id"] = establishment
|
|
|
|
return get_object_or_404(Establishment, **kwargs)
|
|
|
|
else:
|
|
|
|
return Establishment.objects.filter(**kwargs).first()
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
establishment = self.establishment
|
|
|
|
return RoomCategory.objects.filter(establishment=establishment)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["establishment"] = self.establishment
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.establishment = self.establishment
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse_lazy("partners:roomcategories", args=[self.establishment.id])
|
|
|
|
|
2021-04-11 14:19:43 +00:00
|
|
|
class EstablishmentRequestView(InConstructionMixin, PartnerProfileRequiredMixin, CreateView):
|
2021-04-11 06:36:19 +00:00
|
|
|
model = Establishment
|
2021-04-11 14:19:43 +00:00
|
|
|
template_name = "partners/establishment_register.html"
|
2021-04-17 18:35:29 +00:00
|
|
|
fields = ["name", "stars", "superior", "street", "city", "zip", "state", "country", "image"]
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.owner = self.request.user.partnerprofile
|
2021-05-30 11:55:10 +00:00
|
|
|
retval = super().form_valid(form)
|
|
|
|
|
2021-10-28 07:26:17 +00:00
|
|
|
RoomCategory.objects.create(name=_("Einzelzimmer"), average_price=100, active=False, establishment=form.instance) # TODO: Move somewhere better
|
|
|
|
RoomCategory.objects.create(name=_("Doppelzimmer"), average_price=100, active=False, establishment=form.instance)
|
2021-05-30 11:55:10 +00:00
|
|
|
|
|
|
|
return retval
|
2021-04-17 18:35:29 +00:00
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse_lazy("partners:establishments")
|
2021-04-13 12:44:22 +00:00
|
|
|
|
2021-05-30 17:54:23 +00:00
|
|
|
def get_form(self, form_class=None):
|
|
|
|
form = super().get_form(form_class)
|
|
|
|
form.fields['stars'].widget = Stars()
|
|
|
|
return form
|
|
|
|
|
2021-04-13 12:44:22 +00:00
|
|
|
class PartnerDashboardView(InConstructionMixin, PartnerProfileRequiredMixin, DetailView):
|
|
|
|
model = PartnerProfile
|
|
|
|
template_name = "partners/dashboard.html"
|
|
|
|
|
|
|
|
def get_object(self):
|
2021-04-17 18:35:29 +00:00
|
|
|
return self.request.user.partnerprofile
|
|
|
|
|
|
|
|
class EstablishmentVerificationView(SuperUserRequiredMixin, FormView):
|
|
|
|
form_class = VerificationForm
|
|
|
|
template_name = "partners/establishment_verify.html"
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
eid = form.cleaned_data["establishment"]
|
2021-04-18 06:12:15 +00:00
|
|
|
eobj = Establishment.objects.filter(id=eid)
|
2021-04-17 18:35:29 +00:00
|
|
|
eobj.update(verified=True)
|
|
|
|
|
2021-10-28 07:26:17 +00:00
|
|
|
messages.success(self.request, _("Unterkunft %s bestätigt!") % eobj[0].name)
|
2021-04-17 18:35:29 +00:00
|
|
|
|
2021-05-30 10:30:14 +00:00
|
|
|
return HttpResponseRedirect(reverse_lazy("partners:establishment_verify"))
|
|
|
|
|
|
|
|
class EstablishmentGalleryManagementView(PartnerProfileRequiredMixin, CreateView, ListView):
|
|
|
|
model = Image
|
|
|
|
template_name = "partners/establishment_gallery_manage.html"
|
|
|
|
fields = ["image", "title", "comment"]
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
self.establishment = self.get_establishment()
|
|
|
|
self.object_list = self.get_queryset()
|
|
|
|
|
|
|
|
if not self.establishment:
|
|
|
|
return redirect("partners:establishment_register")
|
|
|
|
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_establishment(self):
|
|
|
|
establishment = self.kwargs.get("id", None)
|
|
|
|
kwargs = {"owner": self.request.user.partnerprofile}
|
|
|
|
|
|
|
|
if establishment:
|
|
|
|
kwargs["id"] = establishment
|
|
|
|
return get_object_or_404(Establishment, **kwargs)
|
|
|
|
else:
|
|
|
|
return Establishment.objects.filter(**kwargs).first()
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
establishment = self.establishment
|
|
|
|
return establishment.image_set.all()
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["establishment"] = self.establishment
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.content_object = self.establishment
|
|
|
|
|
|
|
|
for filename, file in self.request.FILES.items():
|
|
|
|
name = self.request.FILES[filename].name
|
|
|
|
|
2021-10-28 07:26:17 +00:00
|
|
|
form.instance.upload_path = f"userfiles/{self.request.user.id}/{uuid.uuid4()}/{name}"
|
2021-05-30 10:30:14 +00:00
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
def get_success_url(self):
|
2021-05-30 10:41:30 +00:00
|
|
|
return reverse_lazy("partners:establishment_gallery", args=[self.establishment.id])
|
|
|
|
|
|
|
|
class RoomCategoryGalleryManagementView(PartnerProfileRequiredMixin, CreateView, ListView):
|
|
|
|
model = Image
|
|
|
|
template_name = "partners/roomcategory_gallery_manage.html"
|
|
|
|
fields = ["image", "title", "comment"]
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
self.roomcategory = self.get_roomcategory()
|
|
|
|
self.object_list = self.get_queryset()
|
|
|
|
|
|
|
|
if not self.roomcategory:
|
|
|
|
return redirect("partners:establishment_register")
|
|
|
|
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_roomcategory(self):
|
|
|
|
roomcategory = self.kwargs.get("cid", None)
|
2021-10-28 07:26:17 +00:00
|
|
|
kwargs = {"establishment_owner": self.request.user}
|
2021-05-30 10:41:30 +00:00
|
|
|
|
|
|
|
if roomcategory:
|
|
|
|
kwargs["id"] = roomcategory
|
|
|
|
return get_object_or_404(RoomCategory, **kwargs)
|
|
|
|
else:
|
|
|
|
return RoomCategory.objects.filter(**kwargs).first()
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
roomcategory = self.roomcategory
|
|
|
|
return roomcategory.image_set.all()
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["roomcategory"] = self.roomcategory
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.content_object = self.roomcategory
|
|
|
|
|
|
|
|
for filename, file in self.request.FILES.items():
|
|
|
|
name = self.request.FILES[filename].name
|
|
|
|
|
2021-10-28 07:26:17 +00:00
|
|
|
form.instance.upload_path = f"userfiles/{self.request.user.id}/{uuid.uuid4()}/{name}"
|
2021-05-30 10:41:30 +00:00
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
def get_success_url(self):
|
2021-10-28 07:26:17 +00:00
|
|
|
return reverse_lazy("partners:roomcategory_gallery", args=[self.roomcategory.establishment.id, self.roomcategory.id])
|
|
|
|
|
|
|
|
class RoomCategoryCalendarAPIView(View):
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
rc = get_object_or_404(RoomCategory, id=kwargs["room"], establishment__id=kwargs["establishment"], establishment__owner=request.user)
|
|
|
|
|
|
|
|
events = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return JsonResponse(events, safe=False)
|
|
|
|
|
|
|
|
class RoomCategoryDefaultPricingView(FormView):
|
|
|
|
form_class = None
|
|
|
|
template_name = "partners/default_pricing.html"
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
pass
|