Compare commits

...

4 Commits

6 changed files with 13 additions and 17 deletions

View File

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

View File

@ -31,6 +31,6 @@ def rpc_roll_dice(request):
result_str = roller.do_roll(dice_str)
return Response({'dice': dice_str, 'result': result_str})
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:
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()
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'^dispatch/', include('dispatch.urls')),

View File

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

View File

@ -3,7 +3,7 @@
{% block title %}{{ site.domain }}{% endblock %}
{% 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 %}
{% block content %}

View File

@ -5,7 +5,7 @@
{% endblock %}
{% 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 %}
{% block content %}