# 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

botw-tracker is an open source software project released under the MIT License.
See the accompanying LICENSE file for terms.

"""

def index(request):
    user_list = UserProfile.objects.order_by('user__username')
    return render(request, 'user/index.html', {'user_list': user_list})

class UserProfileView(DetailView):

    model = UserProfile
    slug_field = "user__username"

    def get_user_id(self):
        try:
            user = User.objects.get(pk=self.kwargs['pk'])
        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'])

# 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


botw-tracker is an open source software project released under the MIT License.
See the accompanying LICENSE file for terms.

"""

def index(request):
    user_list = UserProfile.objects.order_by('user__username')
    return render(request, 'user/index.html', {'user_list': user_list})

class UserProfileView(DetailView):

    model = UserProfile
    slug_field = "user__username"

    def get_user_id(self):
        try:
            user = User.objects.get(pk=self.kwargs['pk'])
        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)]