def send_mail(self, request): form = forms.SendMailForm(request.POST) if form.is_valid(): subscribers = models.Subscriber.objects.all() recipients = [s.email for s in subscribers] self.mail_sender.send_mail(form.data["subject"], form.data["body"], recipients) context = {"subscribers": subscribers} return response.TemplateResponse(request, "subscribers_mail_sent.html", context) context = {"form": form} return response.TemplateResponse(request, "send_subscribers_mail.html", context)
def compute_summary(self, request, queryset): income = decimal.Decimal(0) expenditure = decimal.Decimal(0) balance = decimal.Decimal(0) for transaction in queryset: balance += transaction.amount if transaction.amount > 0: income += transaction.amount else: expenditure -= transaction.amount context = { 'title': _("Summary"), 'opts': self.model._meta, 'app_label': self.model._meta.app_label, 'count': queryset.count(), 'income': income, 'expenditure': expenditure, 'balance': balance, } return response.TemplateResponse(request, 'accounting/admin_summary.html', context, current_app=self.admin_site.name)
def redirect_operations(request): """Redirect method Redirects users either to their C2 interface or to the login window. :param request: HTTP request """ return django_response.TemplateResponse(request, 'angular/users_operations.html')
def post(self, request): form = forms.SubscriberForm(request.POST) if form.is_valid(): form.save() return http.HttpResponseRedirect(self.success_url) template_name = getattr(self, "template_name", "subscribe.html") context = {"form": form} return response.TemplateResponse(request, template_name, context)
def get(self, request, id): session = shortcuts.get_object_or_404(Session, pk=id, speakers=request.user) form = self.form_class(instance=session) tracks = Track.objects.all() return response.TemplateResponse(request, self.template_name, { "session": session, "form": form, "tracks": tracks })
def redirect_leop(request, identifier): """Redirect method Redirects staff either to the LEOP interface or to the login page. :param request: HTTP request :param identifier: Identifier for the LEOP """ user_profile = accounts_backend.authenticate_anonymous(request) return django_response.TemplateResponse( request, 'angular/staff_leop.html', { 'leop_id': identifier, 'is_anonymous': user_profile.anonymous })
def post(self, request): tutorials = [] regexp = re.compile(r"tutorial-(\d{14})") for k, v in request.POST.iteritems(): m = regexp.match(k) if m: tutorial = Session.objects.get( pk=v, date=datetime.datetime.strptime(m.groups()[0], "%Y%m%d%H%M%S"), type="tutorial", ) tutorials.append(tutorial) status = "pending" if request.user.subscription_set.filter( type="talk", status__in=("confirmed", "sponsor")).exists(): status = "confirmed" subscription = Subscription.objects.create( user=request.user, type="tutorial", status=status, ) subscription.tutorials = tutorials subscription.save() if status == "confirmed": return response.TemplateResponse( request, "subscription/tutorials_confirmed.html", context={"subscription": subscription}, ) transaction = Transaction.generate(subscription) return response.TemplateResponse( request, "subscription/tutorials_success.html", context={ "transaction": transaction, "subscription": subscription, }, )
def compute_summary(self, request, queryset): summary = decimal.Decimal(0) for donation in queryset: summary += donation.amount context = { 'title': _("Summary"), 'opts': self.model._meta, 'app_label': self.model._meta.app_label, 'count': queryset.count(), 'summary': summary, } return response.TemplateResponse(request, 'donations/admin_summary.html', context, current_app=self.admin_site.name)
def post(self, request, id): session = shortcuts.get_object_or_404(Session, pk=id, speakers=request.user) form = self.form_class(request.POST, instance=session) if form.is_valid(): form.save() messages.success(request, _("Session successfully updated!"), fail_silently=True) return http.HttpResponseRedirect(reverse("dashboard-sessions")) tracks = Track.objects.all() return response.TemplateResponse(request, self.template_name, { "session": session, "form": form, "tracks": tracks })
def get(self, request): subscriptions = Subscription.objects.\ filter(user=request.user, status="confirmed", type="tutorial").\ prefetch_related("tutorials") subscribed = [] if subscriptions: subscribed = subscriptions[0].tutorials.all() tutorials = Session.objects.\ filter(type="tutorial", status__in=["accepted", "confirmed"]).\ exclude(date__in=[t.date for t in subscribed]).\ order_by("date") slots = [] current_slot = None for tutorial in tutorials: if current_slot is None: current_slot = TutorialSlot([tutorial]) elif tutorial.date == current_slot.date: current_slot.tutorials.append(tutorial) else: slots.append(current_slot) current_slot = TutorialSlot([tutorial]) if current_slot: slots.append(current_slot) return response.TemplateResponse( request, "subscription/tutorials.html", context={ "tutorials": slots, "subscribed": subscribed, "confirmed": request.user.subscription_set.filter( type="talk", status__in=("confirmed", "sponsor")).exists(), }, )
def show_mail_form(self, request): if request.method == "POST": return self.send_mail(request) context = {"form": forms.SendMailForm()} return response.TemplateResponse(request, "send_subscribers_mail.html", context)
def get(self, request): return response.TemplateResponse(request, self.template_name)
def get(self, request): template_name = getattr(self, "template_name", "subscribe.html") context = {"form": forms.SubscriberForm()} return response.TemplateResponse(request, template_name, context)
def error500(request, template_name='500.haml'): return response.TemplateResponse(request, template_name, status=500)
def error404(request, template_name='404.html', **kwargs): return response.TemplateResponse(request, template_name, status=404)