-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created "madebidderids" command and removed from mod11codes. Added un…
…ittests for this.
- Loading branch information
Showing
3 changed files
with
78 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
from optparse import make_option | |||
|
|||
from django.core.management.base import BaseCommand, CommandError | |||
|
|||
from artshow.mod11codes import make_check | |||
|
|||
|
|||
class Command(BaseCommand): | |||
args = "firstcode numcodes" | |||
help = "Generate a list of valid BidderID codes" | |||
option_list = BaseCommand.option_list + ( | |||
make_option("--digits", type="int", default=3, help="pad to this many digits [%default]"), | |||
make_option("--allow-x", action="store_true", default=False, help="allow X checkdigit"), | |||
make_option("--prefix", type="str", default="", help="prefix characters [%default]"), | |||
make_option("--suffix", type="str", default="", help="suffix characters [%default]"), | |||
make_option("--offset", type="int", default=0, help="offset checkdigit [%default]"), | |||
) | |||
|
|||
def handle(self, *args, **options): | |||
try: | |||
first_code, num_codes = args | |||
except ValueError: | |||
raise CommandError("incorrect number of parameters") | |||
try: | |||
first_code = int(first_code) | |||
except ValueError: | |||
raise CommandError("firstcode is not an integer") | |||
try: | |||
num_codes = int(num_codes) | |||
except ValueError: | |||
raise CommandError("numcodes is not an integer") | |||
value = first_code | |||
digits = options['digits'] | |||
allow_x = options['allow_x'] | |||
prefix = options['prefix'] | |||
suffix = options['suffix'] | |||
offset = options['offset'] | |||
while num_codes > 0: | |||
code = "%0*d" % (digits, value) | |||
value += 1 | |||
check = make_check(code,offset=offset) | |||
if check=="X" and not allow_x: | |||
continue | |||
print prefix + code + check + suffix | |||
num_codes -= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters