add is_public property to UserSubmittedModel and permit showing non-approved speakers in list and detail only to the owner user when logged in

This commit is contained in:
Thomas Steen Rasmussen 2017-03-10 00:45:50 +01:00
parent c7571ed9a3
commit d799240dae
2 changed files with 22 additions and 1 deletions

View file

@ -38,6 +38,13 @@ class UserSubmittedModel(CampRelatedModel):
default=SUBMISSION_DRAFT,
)
@property
def is_public(self):
if self.submission_status == self.SUBMISSION_APPROVED:
return True
else:
return False
class EventLocation(CampRelatedModel):
""" The places where stuff happens """

View file

@ -118,16 +118,30 @@ class SpeakerDetailView(CampViewMixin, DetailView):
model = models.Speaker
template_name = 'speaker_detail.html'
def get(self, request, *args, **kwargs):
if not self.get_object().is_public and self.get_object().user != request.user:
raise Http404()
else:
return super().get(request, *args, **kwargs)
class SpeakerListView(CampViewMixin, ListView):
model = models.Speaker
template_name = 'speaker_list.html'
def get_queryset(self, *args, **kwargs):
return models.Speaker.objects.filter(
# get all approved speakers
speakers = models.Speaker.objects.filter(
camp=self.camp,
submission_status=models.Speaker.SUBMISSION_APPROVED
)
# also get the users own speaker, in case he has an unapproved
userspeakers = models.Speaker.objects.filter(
camp=self.camp,
user=self.request.user
).exclude(submission_status=models.Speaker.SUBMISSION_APPROVED)
return speakers | userspeakers
class EventListView(CampViewMixin, ListView):