JourneyJoker/clients/views.py

46 lines
1.5 KiB
Python
Raw Normal View History

2021-03-23 18:23:04 +00:00
from django.views.generic import CreateView, UpdateView
from django.urls import reverse_lazy
2021-03-01 09:56:10 +00:00
2021-03-23 18:23:04 +00:00
from .models import ClientProfile
from localauth.mixins import LoginRequiredMixin
class ClientRegistrationView(LoginRequiredMixin, CreateView):
model = ClientProfile
exclude = ["user"]
template_name = "clients/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("clients:profile")
def get_initial(self):
try:
partner = self.request.user.partnerprofile
return {
"company": partner.company,
"vat_id": partner.vat_id,
"first_name": partner.first_name,
"last_name": partner.last_name,
"street": partner.street,
"city": partner.city,
"zip": partner.zip,
"state": partner.state,
"country": partner.country
}
except:
return {}
class ClientProfileView(LoginRequiredMixin, UpdateView):
model = ClientProfile
exclude = ["user"]
template_name = "clients/profile.html"
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"]
def get_success_url(self):
return reverse_lazy("clients:profile")