Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
Fix isbn problem, add mail errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiphoseer committed Oct 23, 2017
1 parent e2533dc commit 48546a1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
35 changes: 32 additions & 3 deletions pyBuchaktion/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def export(self, request, queryset):
# The admin action for rejecting all selected orders at once.
def reject_selected(self, request, queryset):
if request.POST.get('_proceed'):
errors = []
hint = request.POST.get('hint')
sendmails = '_sendmails' in request.POST
for order in queryset:
Expand All @@ -222,7 +223,18 @@ def reject_selected(self, request, queryset):
order.save()
if sendmails:
email = OrderRejectedMessage(order)
email.send()
try:
email.send()
except Exception:
errors += [order.student.email]
if len(errors) > 0:
context = dict(
self.admin_site.each_context(request),
title=_("Errors"),
intro=_("The following emails could not be sent"),
errors=errors
)
return TemplateResponse(request, 'pyBuchaktion/admin/order_error.html', context)
elif not request.POST.get('_cancel'):
context = dict(
self.admin_site.each_context(request),
Expand All @@ -240,6 +252,7 @@ def reject_selected(self, request, queryset):
# The admin action for marking all selected orders as arrived.
def mark_arrived_selected(self, request, queryset):
if request.POST.get('_proceed'):
errors=[]
sendmails = '_sendmails' in request.POST
hint = request.POST.get('hint', "")
for order in queryset:
Expand All @@ -248,7 +261,18 @@ def mark_arrived_selected(self, request, queryset):
order.save()
if sendmails:
email = OrderArrivedMessage(order)
email.send()
try:
email.send()
except Exception:
errors += [order.student.email]
if len(errors) > 0:
context = dict(
self.admin_site.each_context(request),
title=_("Errors"),
intro=_("The following emails could not be sent"),
errors=errors
)
return TemplateResponse(request, 'pyBuchaktion/admin/order_error.html', context)
elif not request.POST.get('_cancel'):
context = dict(
self.admin_site.each_context(request),
Expand All @@ -266,6 +290,7 @@ def mark_arrived_selected(self, request, queryset):
# The admin action for ordering the selected books
def order_selected(self, request, queryset):
if request.POST.get('_proceed'):
errors=[]
sendmails = '_sendmails' in request.POST
hint = request.POST.get('hint', "")
for order in queryset:
Expand All @@ -274,12 +299,16 @@ def order_selected(self, request, queryset):
order.save()
if sendmails:
email = OrderAcceptedMessage(order)
email.send()
try:
email.send()
except Exception:
errors += [order.student.email]
context = dict(
self.admin_site.each_context(request),
title=_("Ordering: CSV-Export"),
queryset=queryset,
opts=self.opts,
errors=[],
action_checkbox_name=helpers.ACTION_CHECKBOX_NAME,
)
return TemplateResponse(request, 'pyBuchaktion/admin/order_order_selected_csv.html', context)
Expand Down
6 changes: 5 additions & 1 deletion pyBuchaktion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ class Book(models.Model):

# The default string output for a book as "<title> (<author>) [ISBN: <isbn>)"
def __str__(self):
return '%s (%s) [ISBN: %s]' % (self.title, self.author, mask(self.isbn_13))
try:
isbn = mask(self.isbn_13)
except Exception:
isbn = self.isbn_13
return '%s (%s) [ISBN: %s]' % (self.title, self.author, isbn)

# Get the name of the current state from the options
def statename(self):
Expand Down
9 changes: 9 additions & 0 deletions pyBuchaktion/templates/pyBuchaktion/admin/order_error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "pyBuchaktion/admin/admin_action_page.html" %}
{% load i18n l10n %}

{% block content %}
{% if len(errors) > 0 %}
<p>{{ intro }}</p>
<ul>{{ errors|unordered_list }}</ul>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

{% block content %}
<form action="" method="post">{% csrf_token %}
{% if errors|length > 0 %}
<h4>{% trans "E-Mails that failed to send" %}</h4>
<ul>{{ errors|unordered_list }}</ul>
{% endif %}
<p>{% trans "Copy the following list into the bulk-order mask at net-library!" %}</p>
<textarea name="hint" rows="{{ queryset|length|add:1 }}">{{ queryset|net_csv }}</textarea><br/><br/>
<div>
Expand Down
4 changes: 3 additions & 1 deletion tucan-export/tucan-export.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
GOOGLE_BOOKS_BASE_PATH = '/books/v1/volumes?'
# CSS Selectors.
TUCAN_CC_SELECTOR = '#pageTopNavi ul a'
TUCAN_DEPT_SELECTOR = '#auditRegistration_list li[title="Dept. 20 - Computer Science"] a'
#TUCAN_DEPT_SELECTOR = '#auditRegistration_list li[title="Dept. 20 - Computer Science"] a'
TUCAN_DEPT_SELECTOR = '#auditRegistration_list li[title="FB20 - Informatik"] a'
# TUCAN_DEPT_SELECTOR = '#auditRegistration_list li[title="FB04 - Mathematik"] a'

TUCAN_MODULE_CONTAINER_SELECTOR = '#auditRegistration_list li a'
TUCAN_BREADCRUMBS_SELECTOR = '.pageElementTop > h2 > a'
TUCAN_MODULE_COURSE_IDNAME_SELECTOR = '#pageContent form h1';
Expand Down

0 comments on commit 48546a1

Please sign in to comment.