Intitial teams support #147
@ -128,13 +128,19 @@ class ExtensionManager(models.Manager):
|
|||||||
def unlisted(self):
|
def unlisted(self):
|
||||||
return self.exclude(status=self.model.STATUSES.APPROVED)
|
return self.exclude(status=self.model.STATUSES.APPROVED)
|
||||||
|
|
||||||
def authored_by(self, user_id: int):
|
def authored_by(self, user):
|
||||||
return self.filter(maintainer__user_id=user_id)
|
filter = Q(maintainer__user_id=user.pk)
|
||||||
|
user_teams = user.teams.all()
|
||||||
|
if user_teams:
|
||||||
|
filter = filter | Q(team__in=[t.pk for t in user_teams])
|
||||||
|
return self.filter(filter).distinct()
|
||||||
|
|
||||||
def listed_or_authored_by(self, user_id: int):
|
def listed_or_authored_by(self, user):
|
||||||
return self.filter(
|
filter = Q(status=self.model.STATUSES.APPROVED) | Q(maintainer__user_id=user.pk)
|
||||||
Q(status=self.model.STATUSES.APPROVED) | Q(maintainer__user_id=user_id)
|
user_teams = user.teams.all()
|
||||||
).distinct()
|
if user_teams:
|
||||||
|
filter = filter | Q(team__in=[t.pk for t in user_teams])
|
||||||
|
return self.filter(filter).distinct()
|
||||||
|
|
||||||
|
|
||||||
class Extension(CreatedModifiedMixin, RatingMixin, TrackChangesMixin, models.Model):
|
class Extension(CreatedModifiedMixin, RatingMixin, TrackChangesMixin, models.Model):
|
||||||
|
@ -24,7 +24,7 @@ class ExtensionQuerysetMixin:
|
|||||||
if self.request.user.is_staff:
|
if self.request.user.is_staff:
|
||||||
return Extension.objects.all()
|
return Extension.objects.all()
|
||||||
if self.request.user.is_authenticated:
|
if self.request.user.is_authenticated:
|
||||||
return Extension.objects.listed_or_authored_by(user_id=self.request.user.pk)
|
return Extension.objects.listed_or_authored_by(user=self.request.user)
|
||||||
return Extension.objects.listed
|
return Extension.objects.listed
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class UploadFileView(LoginRequiredMixin, CreateView):
|
|||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
drafts = Extension.objects.authored_by(user_id=self.request.user.pk).filter(
|
drafts = Extension.objects.authored_by(user=self.request.user).filter(
|
||||||
status=Extension.STATUSES.INCOMPLETE
|
status=Extension.STATUSES.INCOMPLETE
|
||||||
)
|
)
|
||||||
context['drafts'] = drafts
|
context['drafts'] = drafts
|
||||||
@ -41,7 +41,7 @@ class UploadFileView(LoginRequiredMixin, CreateView):
|
|||||||
if parsed_extension_fields:
|
if parsed_extension_fields:
|
||||||
# Try to look up extension by the same author and file info
|
# Try to look up extension by the same author and file info
|
||||||
extension = (
|
extension = (
|
||||||
Extension.objects.authored_by(user_id=self.request.user.pk)
|
Extension.objects.authored_by(user=self.request.user)
|
||||||
.filter(type=self.file.type, **parsed_extension_fields)
|
.filter(type=self.file.type, **parsed_extension_fields)
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user