Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit 813e839

Browse files
committed
Squashed commit of the following:
commit d382a85 Author: Marc-Andre Lemburg <[email protected]> Date: Tue May 11 12:18:14 2021 +0200 Update bulk coupon docs (#1396) * Add update functionality to the bulk coupon script * Update create coupon script docs. commit ad14175 Author: Marc-Andre Lemburg <[email protected]> Date: Tue May 11 11:52:08 2021 +0200 Add update functionality to the bulk coupon script (#1395) commit 3ad73b5 Author: Marc-Andre Lemburg <[email protected]> Date: Mon May 10 23:06:34 2021 +0200 Fix bulk coupon script (#1394) commit 7d2e20d Author: Marc-Andre Lemburg <[email protected]> Date: Tue May 4 15:22:53 2021 +0200 Fix a few additional corner cases for the automatic anchor generation (#1387) commit f7e2193 Author: Marc-Andre Lemburg <[email protected]> Date: Tue May 4 14:59:38 2021 +0200 Have the TOC script cleanup headers even more (#1385) They will now also ignore leading and trailing hyphens as well as non-breaking spaces. commit e09f78a Author: Marc-Andre Lemburg <[email protected]> Date: Tue May 4 14:11:12 2021 +0200 Scroll to the anchor, if given, after processing the TOC. (#1384) Fixes #1380.
1 parent 525e298 commit 813e839

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

assets/js/generate_toc_for_cms.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ function addTOC() {
1616
var header = $(this);
1717
var title = header.text();
1818
var header_id = title
19-
.replace(/[ :&\/\$]/g, "-")
19+
.replace(/[ \n\t:&\/\$\xa0()]/g, "-")
2020
.replace(/--+/g, "-")
21-
.replace(/[\?!,.\'\"]/g, "");
21+
.replace(/[\?!,.\'\"\’]/g, "")
22+
.replace(/^-|-$/g, "");
2223
header.attr("id", header_id);
2324
toc +=
2425
'<li class="toc-li table-of-contents-' +
@@ -31,5 +32,6 @@ function addTOC() {
3132
});
3233
toc += "</ul>" + "</p>";
3334
div_toc.replaceWith(toc);
35+
$(document).scrollTop( $($(location).attr("hash")).offset().top );
3436
}
3537
$(document).ready(addTOC);

p3/management/commands/create_bulk_coupons.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
""" Create a batch of single use discount coupons from a CSV file.
2+
""" Create/update a batch of discount coupons from a CSV file.
33
44
Parameters: <conference> <csv-file>
55
6-
Creates coupons based on the CSV file contents:
6+
Creates/updates coupons based on the CSV file contents:
77
88
code - coupon code
99
max_usage - max. number of uses
@@ -14,6 +14,9 @@
1414
1515
Use --dry-run to test drive the script.
1616
17+
Existing coupon codes will get updated by the script. Indexing is by
18+
code.
19+
1720
"""
1821
import sys
1922
import csv
@@ -54,9 +57,9 @@ def handle(self, *args, **options):
5457
csv_filename = options['csv']
5558

5659
# Get set of existing coupon codes
57-
all_codes = set(c['code'] for c in Coupon.objects\
58-
.filter(conference=conference.code)\
59-
.values('code'))
60+
all_codes = dict((c.code, c)
61+
for c in Coupon.objects\
62+
.filter(conference=conference.code))
6063

6164
# Valid fares (conference fares only)
6265
all_fares = cmodels.Fare.objects\
@@ -70,23 +73,24 @@ def handle(self, *args, **options):
7073
with csv_file:
7174
reader = csv.DictReader(csv_file)
7275
for row in reader:
76+
#print ('Row %r' % row)
7377
code = row['code'].strip()
74-
if not code:
78+
if not code or code == '0':
7579
# Skip lines without code
7680
continue
7781
if code in all_codes:
78-
# Skip coupons which already exist
79-
print ('Coupon %r already exists - skipping' % code)
80-
continue
81-
c = Coupon(conference=conference)
82-
c.code = code
82+
print ('Coupon %r already exists - updating' % code)
83+
c = all_codes[code]
84+
else:
85+
print ('New coupon %r will be created' % c.code)
86+
c = Coupon(conference=conference)
87+
c.code = code
8388
c.max_usage = int(row.get('max_usage', 1))
8489
c.items_per_usage = int(row.get('items_per_usage', 1))
8590
c.value = row['value']
8691
c.description = row.get('description', '')
8792
if not self.dry_run:
8893
c.save()
89-
c.fares = all_fares.filter(
94+
c.fares.set(all_fares.filter(
9095
code__in = [x.strip()
91-
for x in row['fares'].split(',')])
92-
print ('Coupond %r created' % c.code)
96+
for x in row['fares'].split(',')]))

0 commit comments

Comments
 (0)