try and assert the status of user
from django.contrib import messages
from django.contrib.auth.models import User
+from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse, reverse_lazy
from django.http import Http404, HttpResponseRedirect
from django.utils.translation import ugettext as _
@@ -68,38 +69,6 @@ class PartnersDetailView(DetailView):
context['total_apps_approved_or_sent'] = context['total_apps_approved'] + context['total_apps_sent']
- # This if else block supports the template with the number of accounts available
- partner_streams = Stream.objects.filter(partner=partner)
- context['partner_streams'] = partner_streams
-
- if partner_streams.count() > 0:
- context['total_accounts_available_stream'] = {}
- context['stream_unique_accepted'] = {}
-
- for stream in partner_streams:
- if stream.accounts_available is not None:
- total_apps_approved_or_sent_stream = User.objects.filter(
- editor__applications__partner=partner,
- editor__applications__status__in=(Application.APPROVED, Application.SENT),
- editor__applications__specific_stream=stream).count()
-
- total_accounts_available = stream.accounts_available
-
- context['total_accounts_available_stream'][stream.name] = total_accounts_available - total_apps_approved_or_sent_stream
-
- stream_unique_accepted = User.objects.filter(
- editor__applications__partner=partner,
- editor__applications__status__in=(Application.APPROVED, Application.SENT),
- editor__applications__specific_stream=stream).distinct().count()
- context['stream_unique_accepted'][stream.name] = stream_unique_accepted
-
- else:
- context['total_accounts_available_stream'] = None
- context['stream_unique_accepted'] = None
-
- if partner.accounts_available is not None:
- context['total_accounts_available_partner'] = partner.accounts_available - context['total_apps_approved_or_sent']
-
context['unique_users'] = User.objects.filter(
editor__applications__partner=partner).distinct().count()
@@ -247,7 +216,7 @@ class PartnerUsers(CoordinatorOrSelf, DetailView):
-class PartnerSuggestView(EditorsOnly, FormView):
+class PartnerSuggestView(FormView):
model=Suggest
template_name = 'resources/suggest.html'
form_class = SuggestForm
@@ -256,8 +225,12 @@ class PartnerSuggestView(EditorsOnly, FormView):
return Suggest.objects.order_by('suggested_company_name')
def form_valid(self, form):
+ # Right now, we only hide the suggestion form on the template.
+ # Adding an extra check to ensure the user is looged in
+ # so as to not break things.
+ try:
+ assert self.request.user.is_authenticated()
suggest = Suggest()
-
suggest.suggested_company_name = form.cleaned_data['suggested_company_name']
suggest.description = form.cleaned_data['description']
suggest.company_url = form.cleaned_data['company_url']
@@ -268,6 +241,13 @@ class PartnerSuggestView(EditorsOnly, FormView):
# Translators: Shown to users when they successfully add a new partner suggestion.
_('Your suggestion has been added.'))
return HttpResponseRedirect(reverse('suggest'))
+ except AssertionError:
+ messages.add_message (request, messages.WARNING,
+ # Translators: This message is shown to users who attempt to post data to suggestion form without logging in
+ _('You must be logged in to do that.'))
+ raise PermissionDenied
+
+ return self.request.user.editor
def get_context_data(self, **kwargs):
context = super(PartnerSuggestView, self).get_context_data(**kwargs)
