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:
parent
c7571ed9a3
commit
d799240dae
|
@ -38,6 +38,13 @@ class UserSubmittedModel(CampRelatedModel):
|
||||||
default=SUBMISSION_DRAFT,
|
default=SUBMISSION_DRAFT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_public(self):
|
||||||
|
if self.submission_status == self.SUBMISSION_APPROVED:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class EventLocation(CampRelatedModel):
|
class EventLocation(CampRelatedModel):
|
||||||
""" The places where stuff happens """
|
""" The places where stuff happens """
|
||||||
|
|
|
@ -118,16 +118,30 @@ class SpeakerDetailView(CampViewMixin, DetailView):
|
||||||
model = models.Speaker
|
model = models.Speaker
|
||||||
template_name = 'speaker_detail.html'
|
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):
|
class SpeakerListView(CampViewMixin, ListView):
|
||||||
model = models.Speaker
|
model = models.Speaker
|
||||||
template_name = 'speaker_list.html'
|
template_name = 'speaker_list.html'
|
||||||
|
|
||||||
def get_queryset(self, *args, **kwargs):
|
def get_queryset(self, *args, **kwargs):
|
||||||
return models.Speaker.objects.filter(
|
# get all approved speakers
|
||||||
|
speakers = models.Speaker.objects.filter(
|
||||||
camp=self.camp,
|
camp=self.camp,
|
||||||
submission_status=models.Speaker.SUBMISSION_APPROVED
|
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):
|
class EventListView(CampViewMixin, ListView):
|
||||||
|
|
Loading…
Reference in a new issue