from django.conf import settings
from django.views.generic import TemplateView
from django.contrib.auth.mixins import LoginRequiredMixin


class UserIndexView(LoginRequiredMixin, TemplateView):

    def get_template_names(self):
        theme = settings.THEME_NAME
        return [
            f"themes/{theme}/templates/users/center/index.html",
            "themes/cursor/templates/users/center/index.html",
            "themes/default/templates/users/center/index.html"
        ]

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        user = self.request.user
        try:
            context['profile'] = user.profile  # 通过related_name获取profile
        except:
            pass
        context['user'] = user
        return context
