Commit 954a0e0b authored by Michal Čihař's avatar Michal Čihař

Gracefully handle users without profile

Those can be imported or manually created.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 77b45c05
...@@ -33,6 +33,7 @@ from django.contrib.auth.models import Permission, User, Group ...@@ -33,6 +33,7 @@ from django.contrib.auth.models import Permission, User, Group
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache from django.core.cache import cache
from weblate.accounts.models import Profile
from weblate.lang.models import Language, get_english_lang from weblate.lang.models import Language, get_english_lang
from weblate.trans.mixins import PercentMixin, URLMixin, PathMixin from weblate.trans.mixins import PercentMixin, URLMixin, PathMixin
from weblate.trans.site import get_site_url from weblate.trans.site import get_site_url
...@@ -200,12 +201,21 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -200,12 +201,21 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
"""Adds user based on username of email.""" """Adds user based on username of email."""
group = Group.objects.get(name=self.name) group = Group.objects.get(name=self.name)
user.groups.add(group) user.groups.add(group)
user.profile.subscriptions.add(self) self.add_subscription(user)
def add_subscription(self, user):
"""Adds user subscription to current project"""
try:
profile = user.profile
except Profile.DoesNotExist:
profile = Profile.objects.create(user=user)
profile.subscriptions.add(self)
def add_owner(self, user): def add_owner(self, user):
"""Adds owner to the project""" """Adds owner to the project"""
self.owners.add(user) self.owners.add(user)
user.profile.subscriptions.add(self) self.add_subscription(user)
def remove_user(self, user): def remove_user(self, user):
"""Adds user based on username of email.""" """Adds user based on username of email."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment