<commit_before># Create your views here.
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, Http404
from django.shortcuts import get_object_or_404

from components.quests.models import Quest, QuestMember

@login_required
def accept(request, quest_id):
  if request.method == "POST":
    referer = request.META["HTTP_REFERER"]
    quest = get_object_or_404(Quest, pk=quest_id)
    if quest.can_add_quest(request.user):
      member = QuestMember(user=request.user, quest=quest)
      member.save()

    return HttpResponseRedirect(referer)
  
  raise Http404
  
@login_required
def opt_out(request, quest_id):
  if request.method == "POST":
    referer = request.META["HTTP_REFERER"]
    quest = get_object_or_404(Quest, pk=quest_id)
    if quest.can_add_quest(request.user):
      member = QuestMember(user=request.user, quest=quest, opt_out=True)<commit_msg>Adding in get_or_create to quests to make sure only one is created.<commit_after># Create your views here.
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, Http404
from django.shortcuts import get_object_or_404

from components.quests.models import Quest, QuestMember

@login_required
def accept(request, quest_id):
  if request.method == "POST":
    referer = request.META["HTTP_REFERER"]
    quest = get_object_or_404(Quest, pk=quest_id)
    if quest.can_add_quest(request.user):
      member, created = QuestMember.objects.get_or_create(user=request.user, quest=quest)
      member.save()

    return HttpResponseRedirect(referer)
  
  raise Http404
  
@login_required
def opt_out(request, quest_id):
  if request.method == "POST":
    referer = request.META["HTTP_REFERER"]
    quest = get_object_or_404(Quest, pk=quest_id)
    if quest.can_add_quest(request.user):
      member, created = QuestMember.objects.get_or_create(user=request.user, quest=quest)
      member.opt_out = True
{'fraction_non_alphanumeric': 0.09467758444216991, 'fraction_numerical': 0.015353121801432957, 'mean_word_length': 4.960365853658536, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4645409', 'n_tokens_mistral': 645, 'n_tokens_neox': 624, 'n_words': 139}