# Path: tango_user/filters.py
# class ProfileFilter(django_filters.FilterSet):
#     display_name = django_filters.CharFilter(lookup_expr='icontains')
# 
#     class Meta:
#         model = get_user_model()
#         fields = ['display_name']
# 
# Path: tango_user/forms.py
# class PublicProfileForm(forms.ModelForm):
#     """
#     Allows for profile and settings updates.
#     Note that template checks for "Open board links" label.
#     Anything below that will be in a 'settings' fieldset.
#     """
#     class Meta:
#         model = Profile
#         fields = (
#             'display_name',
#             'street_address',
#             'city',
#             'state',
#             'country',
#             'zipcode',
#             'occupation',
#             'interests',
#             'birthday',
#             'homepage',
#             'bio',
#             'avatar',
#             'signature',
#         )
# 
# class ProfileSettingsForm(forms.ModelForm):
#     """
#     Allows for modifying profile settings
#     """
#     class Meta:
#         model = Profile
#         fields = (
#             'display_on_map',
#             'show_signatures',
#             'theme'
#         )


import datetime
import json
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.views.generic import ListView
from django.views.generic.edit import UpdateView
from .filters import ProfileFilter
from .forms import PublicProfileForm, ProfileSettingsForm





UserModel = get_user_model()
past_year = datetime.datetime.now() - datetime.timedelta(days=365)


class MemberList(ListView):
    """
    Renders either default user list (paginated) or search results.
    To-do: split search to separate view, make pagination work better.
    """
    queryset = UserModel.objects.filter(is_active=1, last_login__gte=past_year).order_by('display_name').values()
    template_name = "users/user_list.html"
    paginate_by = 100

    def get_context_data(self, **kwargs):
        context = super(MemberList, self).get_context_data(**kwargs)
        if 'display_name' in self.request.GET or 'state' in self.request.GET:
            filter = ProfileFilter(self.request.GET, queryset=self.queryset)
        else:

# Path: tango_user/filters.py
# class ProfileFilter(django_filters.FilterSet):
#     display_name = django_filters.CharFilter(lookup_expr='icontains')
# 
#     class Meta:
#         model = get_user_model()
#         fields = ['display_name']
# 
# Path: tango_user/forms.py
# class PublicProfileForm(forms.ModelForm):
#     """
#     Allows for profile and settings updates.
#     Note that template checks for "Open board links" label.
#     Anything below that will be in a 'settings' fieldset.
#     """
#     class Meta:
#         model = Profile
#         fields = (
#             'display_name',
#             'street_address',
#             'city',
#             'state',
#             'country',
#             'zipcode',
#             'occupation',
#             'interests',
#             'birthday',
#             'homepage',
#             'bio',
#             'avatar',
#             'signature',
#         )
# 
# class ProfileSettingsForm(forms.ModelForm):
#     """
#     Allows for modifying profile settings
#     """
#     class Meta:
#         model = Profile
#         fields = (
#             'display_on_map',
#             'show_signatures',
#             'theme'
#         )


# Path: tango_user/views.py
import datetime
import json
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.views.generic import ListView
from django.views.generic.edit import UpdateView
from .filters import ProfileFilter
from .forms import PublicProfileForm, ProfileSettingsForm





UserModel = get_user_model()
past_year = datetime.datetime.now() - datetime.timedelta(days=365)


class MemberList(ListView):
    """
    Renders either default user list (paginated) or search results.
    To-do: split search to separate view, make pagination work better.
    """
    queryset = UserModel.objects.filter(is_active=1, last_login__gte=past_year).order_by('display_name').values()
    template_name = "users/user_list.html"
    paginate_by = 100

    def get_context_data(self, **kwargs):
        context = super(MemberList, self).get_context_data(**kwargs)
        if 'display_name' in self.request.GET or 'state' in self.request.GET:
            filter = ProfileFilter(self.request.GET, queryset=self.queryset)
        else:

            filter = ProfileFilter()
