Skip to content

Commit

Permalink
Merge pull request #2 from ervilis/change_list_context
Browse files Browse the repository at this point in the history
Putting the channel in the context of channel promos listing
  • Loading branch information
Thiago Avelino committed Dec 29, 2014
2 parents 49c5bd1 + d9f2892 commit 99a8fb6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion opps/promos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class ChannelPromoList(ListView):

context_object_name = "promos"

def __init__(self, *args, **kwargs):
self.channel = None
super(ChannelPromoList, self).__init__(*args, **kwargs)

@property
def template_name(self):
long_slug = self.kwargs.get('channel__long_slug')
Expand All @@ -53,7 +57,8 @@ def template_name(self):
def queryset(self):
site = get_current_site(self.request)
long_slug = self.kwargs['channel__long_slug'].strip('/')
get_object_or_404(Channel, long_slug=long_slug)
self.channel = get_object_or_404(Channel, long_slug=long_slug)

return Promo.objects.filter(
channel__long_slug=long_slug,
published=True,
Expand All @@ -63,6 +68,12 @@ def queryset(self):
Q(site__domain=site.domain)
).distinct()

def get_context_data(self, *args, **kwargs):
context = super(ChannelPromoList, self).get_context_data(*args,
**kwargs)
context['channel'] = self.channel
return context


class PromoDetail(DetailView):

Expand Down Expand Up @@ -174,6 +185,8 @@ def post(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
context['answers'] = self.object.answers
context['request'] = request
if self.object.channel:
context['channel'] = self.object.channel

# check if is_closed or not published
if not self.object.is_opened or not self.object.published:
Expand Down

0 comments on commit 99a8fb6

Please sign in to comment.