# Path: src/user/models.py
# class UserProfile(models.Model):
# 
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
# 
# class QuestEntry(models.Model):
# 
#     user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
#     quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
#     discovery_date = models.DateTimeField(auto_now_add=True)
#     completion_date = models.DateTimeField(null=True)
# 
#     def completed(self):
#         return self.completion_date != None


from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.core.exceptions import SuspiciousOperation
from django.shortcuts import render
from django.urls import reverse_lazy
from django.utils import timezone
from django.views.generic.base import RedirectView
from django.views.generic.detail import DetailView
from .models import UserProfile, QuestEntry
from quests.models import Quest
        except KeyError:
            user = User.objects.get(username=self.kwargs['slug'])
        return user.id

    def get_quest_types(self):
        return Quest.QUEST_TYPES

    def get_undiscovered_quests(self):
        try:
            user = User.objects.get(pk=self.kwargs['pk'])
        except KeyError:
            user = User.objects.get(username=self.kwargs['slug'])
        quests = [entry.quest.id for entry in QuestEntry.objects.filter(user__user=user)]
        return Quest.objects.exclude(id__in=quests)

class UserProfileUpdate(LoginRequiredMixin, RedirectView):

    login_url = reverse_lazy('login')
    pattern_name = 'app-views-user'

    def get_redirect_url(self, *args, **kwargs):
        user = User.objects.get(pk=kwargs['pk'])
        action = self.request.POST.get('action')
        id = self.request.POST.get('id')
        if action == 'complete':
            entry_obj = self.verify_entry(user, id)
            entry_obj.completion_date = timezone.now()
            entry_obj.save(update_fields=['completion_date'])
        elif action == 'discover':
            quest = Quest.objects.get(pk=id)

# Path: src/user/models.py
# class UserProfile(models.Model):
# 
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
# 
# class QuestEntry(models.Model):
# 
#     user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
#     quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
#     discovery_date = models.DateTimeField(auto_now_add=True)
#     completion_date = models.DateTimeField(null=True)
# 
#     def completed(self):
#         return self.completion_date != None


# Path: src/user/views.py
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.core.exceptions import SuspiciousOperation
from django.shortcuts import render
from django.urls import reverse_lazy
from django.utils import timezone
from django.views.generic.base import RedirectView
from django.views.generic.detail import DetailView
from .models import UserProfile, QuestEntry
from quests.models import Quest

        except KeyError:
            user = User.objects.get(username=self.kwargs['slug'])
        return user.id

    def get_quest_types(self):
        return Quest.QUEST_TYPES

    def get_undiscovered_quests(self):
        try:
            user = User.objects.get(pk=self.kwargs['pk'])
        except KeyError:
            user = User.objects.get(username=self.kwargs['slug'])
        quests = [entry.quest.id for entry in QuestEntry.objects.filter(user__user=user)]
        return Quest.objects.exclude(id__in=quests)

class UserProfileUpdate(LoginRequiredMixin, RedirectView):

    login_url = reverse_lazy('login')
    pattern_name = 'app-views-user'

    def get_redirect_url(self, *args, **kwargs):
        user = User.objects.get(pk=kwargs['pk'])
        action = self.request.POST.get('action')
        id = self.request.POST.get('id')
        if action == 'complete':
            entry_obj = self.verify_entry(user, id)
            entry_obj.completion_date = timezone.now()
            entry_obj.save(update_fields=['completion_date'])
        elif action == 'discover':
            quest = Quest.objects.get(pk=id)

            profile = UserProfile.objects.get(user=user)