Fix organization creation, make reusable for API
This commit is contained in:
parent
98e114dc79
commit
8f719b0d65
2 changed files with 14 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
@ -33,6 +34,18 @@ class Organization(ServalaModelMixin, models.Model):
|
|||
user=user, organization=self, role=OrganizationRole.OWNER
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create_organization(cls, instance, owner):
|
||||
try:
|
||||
instance.origin
|
||||
except Exception:
|
||||
instance.origin = OrganizationOrigin.objects.get(
|
||||
pk=settings.SERVALA_DEFAULT_ORIGIN
|
||||
)
|
||||
instance.save()
|
||||
instance.set_owner(owner)
|
||||
return instance
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Organization")
|
||||
verbose_name_plural = _("Organizations")
|
||||
|
|
|
@ -8,8 +8,7 @@ class OrganizationCreateView(FormView):
|
|||
template_name = "frontend/organizations/create.html"
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
form.instance.set_owner(self.request.user)
|
||||
form.instance.create_organization(form.instance, owner=self.request.user)
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue