Compare commits

...

4 Commits

6 changed files with 13 additions and 17 deletions

View File

@ -70,7 +70,7 @@ class DiceRoller(object):
output = "" output = ""
repeat = 1 repeat = 1
if trials != None: if trials is not None:
repeat = trials repeat = trials
for i in range(repeat): for i in range(repeat):
mode = 1 mode = 1
@ -86,19 +86,15 @@ class DiceRoller(object):
# m[0] = (keep, num dice) # m[0] = (keep, num dice)
# m[1] = num faces on the die # m[1] = num faces on the die
if type(m) == tuple: if type(m) == tuple:
if m[0] != None: if m[0] is not None:
if m[0][0] != None: if m[0][0] is not None:
keep = m[0][0] keep = m[0][0]
dice = m[0][1] dice = m[0][1]
size = m[1] size = m[1]
if keep > dice or keep == 0: if keep > dice or keep == 0:
keep = dice keep = dice
if size < 1: assert size >= 1, f"Die must have at least one side."
output = "# of sides for die is incorrect: %d" % size assert dice >= 1, f"At least one die must be rolled."
return output
if dice < 1:
output = "# of dice is incorrect: %d" % dice
return output
res = self.roll_dice(keep, dice, size) res = self.roll_dice(keep, dice, size)
curr_str += "%d%s" % (res[0], res[1]) curr_str += "%d%s" % (res[0], res[1])
res = res[0] res = res[0]
@ -113,14 +109,14 @@ class DiceRoller(object):
curr_str += str(m) curr_str += str(m)
total += mode * res total += mode * res
if repeat == 1: if repeat == 1:
if comment != None: if comment is not None:
output = "%d %s (%s)" % (total, comment.strip(), curr_str) output = "%d %s (%s)" % (total, comment.strip(), curr_str)
else: else:
output = "%d (%s)" % (total, curr_str) output = "%d (%s)" % (total, curr_str)
else: else:
output += "%d (%s)" % (total, curr_str) output += "%d (%s)" % (total, curr_str)
if i == repeat - 1: if i == repeat - 1:
if comment != None: if comment is not None:
output += " (%s)" % (comment.strip()) output += " (%s)" % (comment.strip())
return output return output

View File

@ -31,6 +31,6 @@ def rpc_roll_dice(request):
result_str = roller.do_roll(dice_str) result_str = roller.do_roll(dice_str)
return Response({'dice': dice_str, 'result': result_str}) return Response({'dice': dice_str, 'result': result_str})
except AssertionError as aex: except AssertionError as aex:
return Response({'detail': f"Could not roll dice: {aex}"}, status=400) return Response({'detail': f"Could not roll dice: {aex}", 'dice': dice_str}, status=400)
except ValueError: except ValueError:
return Response({'detail': f"Could not parse requested dice '{dice_str}'."}, status=400) return Response({'detail': f"Could not parse requested dice '{dice_str}'.", 'dice': dice_str}, status=400)

View File

@ -11,7 +11,7 @@ admin.sites.site = admin.site
admin.autodiscover() admin.autodiscover()
urlpatterns = [ urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'), url(r'^$', TemplateView.as_view(template_name='index.html'), name='index'),
url(r'^dice/', include('dice.urls')), url(r'^dice/', include('dice.urls')),
url(r'^dispatch/', include('dispatch.urls')), url(r'^dispatch/', include('dispatch.urls')),

View File

@ -15,7 +15,7 @@
<div class="container"> <div class="container">
<div class="navbar-header"> <div class="navbar-header">
{% block navbarbrand %} {% block navbarbrand %}
<a class="navbar-brand" href="{% url 'home' %}">{{ site.domain }}</a> <a class="navbar-brand" href="{% url 'index' %}">{{ site.domain }}</a>
{% endblock %} {% endblock %}
<!-- .navbar-toggle is used as the toggle for collapsed navbar content --> <!-- .navbar-toggle is used as the toggle for collapsed navbar content -->

View File

@ -3,7 +3,7 @@
{% block title %}{{ site.domain }}{% endblock %} {% block title %}{{ site.domain }}{% endblock %}
{% block navbarbrand %} {% block navbarbrand %}
<a class="navbar-brand navbar-brand-active" href="{% url 'home' %}">{{ site.domain }}</a> <a class="navbar-brand navbar-brand-active" href="{% url 'index' %}">{{ site.domain }}</a>
{% endblock %} {% endblock %}
{% block content %} {% block content %}

View File

@ -5,7 +5,7 @@
{% endblock %} {% endblock %}
{% block navbarbrand %} {% block navbarbrand %}
<a class="navbar-brand navbar-brand-active" href="{% url 'home' %}">{{ site.domain }}</a> <a class="navbar-brand navbar-brand-active" href="{% url 'index' %}">{{ site.domain }}</a>
{% endblock %} {% endblock %}
{% block content %} {% block content %}