JourneyJoker/partners/views.py

50 lines
No EOL
1.6 KiB
Python

from django.views.generic import CreateView, UpdateView
from django.urls import reverse_lazy
from .models import PartnerProfile
from localauth.mixins import LoginRequiredMixin
class PartnerRegistrationView(LoginRequiredMixin, CreateView):
model = PartnerProfile
exclude = ["user"]
template_name = "partners/signup.html"
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"]
def form_valid(self, form):
form.instance.user = self.request.user
return super().form_valid(form)
def get_success_url(self):
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,
"country": client.country
}
except:
return {}
class PartnerProfileView(LoginRequiredMixin, UpdateView):
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):
return self.request.user.partnerprofile