Skip to content

Commit

Permalink
/kodegolf open for everyone.
Browse files Browse the repository at this point in the history
Hid the "Send"-button. Submitting as Anonymous will result in error.
  • Loading branch information
Kajrakso committed Oct 12, 2024
1 parent af623b2 commit 80e2552
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions nablapps/interactive/models/code_golf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json

from django import template
from django.contrib.auth.models import AnonymousUser
from django.db import models
from django.db.models.functions import Concat
from django.utils import timezone
Expand Down Expand Up @@ -68,10 +69,12 @@ def best_by_user(self, task, prefetch_user=True):

def best_specific_user(self, task, user):
"""Gets the best result for a specific user. Returns result object"""

best_result = (
Result.objects.filter(user=user, task=task).order_by("length").first()
)
if user != AnonymousUser():
best_result = (
Result.objects.filter(user=user, task=task).order_by("length").first()
)
else:
best_result = None

return best_result

Expand Down
2 changes: 2 additions & 0 deletions nablapps/interactive/templates/interactive/code_golf.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ <h3>{{ task }}</h3>
{% csrf_token %}
{{ form.as_p }}
<button class="btn btn-nabla-blue-dark mr-1" type="button" @click="runit">Kjør</button>
{% if logged_in %}
<input class="btn btn-secondary" type="submit" value="Send" :disabled="status!='correct'" />
{% endif %}
<br />
</form>

Expand Down
4 changes: 2 additions & 2 deletions nablapps/interactive/views/code_golf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def clean(self):
raise ValidationError("Output does not match correct output")


class CodeGolf(LoginRequiredMixin, CreateView):
class CodeGolf(CreateView):
"""View for writing and submitting solutions"""

model = Result
Expand Down Expand Up @@ -142,7 +142,7 @@ def code_golf_score(request, task_id):
return render(request, "interactive/code_golf_score.html", context)


class CodeTaskListView(LoginRequiredMixin, ListView):
class CodeTaskListView(ListView):
model = CodeTask

def get_context_data(self, **kwargs):
Expand Down

0 comments on commit 80e2552

Please sign in to comment.