Fix registration views

Hide client profile for partners
This commit is contained in:
Kumi 2021-04-14 13:15:36 +02:00
parent 8594574ebe
commit 558c072986
6 changed files with 32 additions and 19 deletions

View file

@ -14,7 +14,7 @@ class ClientRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateView
model = ClientProfile model = ClientProfile
exclude = ["user"] exclude = ["user"]
template_name = "clients/signup.html" template_name = "clients/signup.html"
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"] fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country", "phone"]
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
try: try:
@ -43,11 +43,15 @@ class ClientRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateView
"city": partner.city, "city": partner.city,
"zip": partner.zip, "zip": partner.zip,
"state": partner.state, "state": partner.state,
"country": partner.country "country": partner.country,
"phone": partner.phone,
} }
except: except:
return {} return {
"country": "AT",
"phone": "+43"
}
class ClientProfileView(InConstructionMixin, LoginRequiredMixin, UpdateView): class ClientProfileView(InConstructionMixin, LoginRequiredMixin, UpdateView):
model = ClientProfile model = ClientProfile

View file

@ -22,7 +22,6 @@ class UserManager(BaseUserManager):
email = self.normalize_email(email) email = self.normalize_email(email)
user = self.model( user = self.model(
email=email, email=email,
display_name=display_name,
**extra_fields **extra_fields
) )
user.set_password(password) user.set_password(password)
@ -64,11 +63,11 @@ class User(AbstractBaseUser):
has_perm = has_permission has_perm = has_permission
class AddressMixin(models.Model): class AddressMixin(models.Model):
street = models.CharField(max_length=64) street = models.CharField("Straße", max_length=64)
city = models.CharField(max_length=64) city = models.CharField("Stadt", max_length=64)
zip = models.CharField(max_length=16) zip = models.CharField("PLZ", max_length=16)
state = models.CharField(max_length=64, null=True, blank=True) state = models.CharField("Bundesland", max_length=64, null=True, blank=True)
country = CountryField() country = CountryField("Staat")
@property @property
def full_address(self): def full_address(self):
@ -96,17 +95,17 @@ class ImageMixin(models.Model):
abstract = True abstract = True
class PhoneMixin(models.Model): class PhoneMixin(models.Model):
phone = PhoneNumberField() phone = PhoneNumberField("Mobiltelefon")
class Meta: class Meta:
abstract = True abstract = True
class Profile(AddressMixin, PhoneMixin): class Profile(AddressMixin, PhoneMixin):
user = models.OneToOneField(User, models.CASCADE) user = models.OneToOneField(User, models.CASCADE)
company = models.CharField(max_length=64, null=True, blank=True) company = models.CharField("Firma", max_length=64, null=True, blank=True)
vat_id = models.CharField(max_length=32, null=True, blank=True) vat_id = models.CharField("UID-Nummer", max_length=32, null=True, blank=True)
first_name = models.CharField(max_length=64) first_name = models.CharField("Vorname", max_length=64)
last_name = models.CharField(max_length=64) last_name = models.CharField("Nachname", max_length=64)
verified = models.BooleanField(default=False) verified = models.BooleanField(default=False)
enabled = models.BooleanField(default=True) enabled = models.BooleanField(default=True)

View file

@ -26,6 +26,8 @@ class RegistrationView(Login):
def form_valid(self, form): def form_valid(self, form):
user = User.objects.create_user(form.cleaned_data["email"]) user = User.objects.create_user(form.cleaned_data["email"])
user.set_password(form.cleaned_data["password1"]) user.set_password(form.cleaned_data["password1"])
user.save()
login(self.request, user) login(self.request, user)
messages.success(self.request, "Erfolgreich registriert!") messages.success(self.request, "Erfolgreich registriert!")

View file

@ -16,7 +16,7 @@ class PartnerRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateVie
model = PartnerProfile model = PartnerProfile
exclude = ["user"] exclude = ["user"]
template_name = "partners/signup.html" template_name = "partners/signup.html"
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"] fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country", "phone"]
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
try: try:
@ -46,11 +46,15 @@ class PartnerRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateVie
"city": client.city, "city": client.city,
"zip": client.zip, "zip": client.zip,
"state": client.state, "state": client.state,
"country": client.country "country": client.country,
"phone": client.phone
} }
except: except:
return {} return {
"country": "AT",
"phone": "+43"
}
class PartnerProfileView(InConstructionMixin, PartnerProfileRequiredMixin, UpdateView): class PartnerProfileView(InConstructionMixin, PartnerProfileRequiredMixin, UpdateView):
model = PartnerProfile model = PartnerProfile

View file

@ -145,6 +145,7 @@
<li class="nav-item active"> <li class="nav-item active">
<a href="/" class="nav-link" id="navbarDropdown" role="button">{% trans "Home" %}</a> <a href="/" class="nav-link" id="navbarDropdown" role="button">{% trans "Home" %}</a>
</li> </li>
{% if request.user.is_superuser or not request.user.partnerprofile %}
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a href="#" class="nav-link" data-toggle="dropdown">{% trans "Mein&nbsp;Urlaub" %}<span><i class="fa fa-angle-down"></i></span></a> <a href="#" class="nav-link" data-toggle="dropdown">{% trans "Mein&nbsp;Urlaub" %}<span><i class="fa fa-angle-down"></i></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
@ -158,6 +159,7 @@
{% endif %} {% endif %}
</ul> </ul>
</li> </li>
{% endif %}
{% if request.user.partnerprofile %} {% if request.user.partnerprofile %}
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a href="#" class="nav-link" data-toggle="dropdown">Partnerprofil<span><i class="fa fa-angle-down"></i></span></a> <a href="#" class="nav-link" data-toggle="dropdown">Partnerprofil<span><i class="fa fa-angle-down"></i></span></a>

View file

@ -36,6 +36,7 @@
</ul> </ul>
</div><!-- end slider --> </div><!-- end slider -->
{% if request.user.is_superuser or not request.user.partnerprofile %}
<div class="search-tabs" id="search-tabs-1"> <div class="search-tabs" id="search-tabs-1">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
@ -148,6 +149,7 @@
</div><!-- end row --> </div><!-- end row -->
</div><!-- end container --> </div><!-- end container -->
</div><!-- end search-tabs --> </div><!-- end search-tabs -->
{% endif %}
</section><!-- end flexslider-container --> </section><!-- end flexslider-container -->
@ -187,8 +189,8 @@
</div><!-- end arrow --> </div><!-- end arrow -->
<div class="main-title hotel-title"> <div class="main-title hotel-title">
<a href="#">Herta Berlin Hotel</a> <a href="#">Habbo Hotel</a>
<p>1020 Wien</p> <p>1010 Wien</p>
</div><!-- end hotel-title --> </div><!-- end hotel-title -->
</div><!-- end hotel-info --> </div><!-- end hotel-info -->
</div><!-- end hotel-block --> </div><!-- end hotel-block -->