# Path: app/account/models.py
# class Profile(abstracts.ModelAbstract):
#     user = models.OneToOneField(User)
#     website = models.URLField(null=True, blank=True)
#     avatar = models.ImageField(max_length=1024, null=True, blank=True, upload_to=get_account_file_name)
#     is_verified = models.BooleanField(default=False)
# 
# 
#     def __str__(self):
#         return u"{}".format(self.user.username)
# 
#     def __unicode__(self):
#         return self.__str__()
# 
# class Request(abstracts.ModelAbstract):
#     user = models.ForeignKey(User)
#     type = models.SmallIntegerField(choices=REQUEST_TYPE_CHOICES)
#     is_approved = models.BooleanField(default=False)
#     activation_key = models.CharField(max_length=64, blank=True)
#     key_expires_at = models.DateTimeField(auto_now_add=True)
#     str_field_1 = models.CharField(max_length=64, null=True, blank=True)
#     str_field_2 = models.CharField(max_length=64, null=True, blank=True)
#     dec_field_1 = models.DecimalField(max_digits=9, decimal_places=2, null=True, blank=True)
#     dec_field_2 = models.DecimalField(max_digits=9, decimal_places=2, null=True, blank=True)
#     bool_field_1 = models.BooleanField(default=False, blank=True)
#     bool_field_2 = models.BooleanField(default=False, blank=True)
# 
#     def __str__(self):
#         return u"{}".format(self.user.username)
# 
#     def __unicode__(self):
#         return self.__str__()
# 
# REQUEST_TYPE_ACCOUNT = 1
# 
# REQUEST_TYPE_EMAIL = 2
# 
# REQUEST_TYPE_PASSWORD = 3


from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from core import abstracts
from .models import Profile, Request, REQUEST_TYPE_ACCOUNT, REQUEST_TYPE_EMAIL, REQUEST_TYPE_PASSWORD
        elif (queryset.filter(type=REQUEST_TYPE_EMAIL)):
            for q in queryset:
                q.user.email = q.str_field_2
                q.user.save()
                q.user.profile.is_verified = False
                q.user.profile.save()
            queryset.update(is_approved=False)
        elif (queryset.filter(type=REQUEST_TYPE_PASSWORD)):
            for q in queryset:
                q.user.set_password("12345")
                q.user.save()
            queryset.update(is_approved=False)

            # rows_updated = queryset.update(is_approved=False)
            # if rows_updated == 1:
            # message_bit = "1 request was"
            # else:
            # message_bit = "%s requests were" % rows_updated
            # model_admin.message_user(request, "%s successfully marked as refused." % message_bit)


class RequestAdmin(abstracts.ModelAdminAbstract):
    list_display = ['user', 'type', 'is_approved', 'activation_key', 'str_field_1', 'str_field_2', 'dec_field_1',
                    'dec_field_2', 'bool_field_1', 'bool_field_2', 'key_expires_at', ]
    list_filter = ['user', 'type', 'is_approved', ]
    actions = [RequestActions.approve_selected_requests, RequestActions.refuse_selected_requests]


admin.site.unregister(User)
admin.site.register(User, UserNewAdmin)

# Path: app/account/models.py
# class Profile(abstracts.ModelAbstract):
#     user = models.OneToOneField(User)
#     website = models.URLField(null=True, blank=True)
#     avatar = models.ImageField(max_length=1024, null=True, blank=True, upload_to=get_account_file_name)
#     is_verified = models.BooleanField(default=False)
# 
# 
#     def __str__(self):
#         return u"{}".format(self.user.username)
# 
#     def __unicode__(self):
#         return self.__str__()
# 
# class Request(abstracts.ModelAbstract):
#     user = models.ForeignKey(User)
#     type = models.SmallIntegerField(choices=REQUEST_TYPE_CHOICES)
#     is_approved = models.BooleanField(default=False)
#     activation_key = models.CharField(max_length=64, blank=True)
#     key_expires_at = models.DateTimeField(auto_now_add=True)
#     str_field_1 = models.CharField(max_length=64, null=True, blank=True)
#     str_field_2 = models.CharField(max_length=64, null=True, blank=True)
#     dec_field_1 = models.DecimalField(max_digits=9, decimal_places=2, null=True, blank=True)
#     dec_field_2 = models.DecimalField(max_digits=9, decimal_places=2, null=True, blank=True)
#     bool_field_1 = models.BooleanField(default=False, blank=True)
#     bool_field_2 = models.BooleanField(default=False, blank=True)
# 
#     def __str__(self):
#         return u"{}".format(self.user.username)
# 
#     def __unicode__(self):
#         return self.__str__()
# 
# REQUEST_TYPE_ACCOUNT = 1
# 
# REQUEST_TYPE_EMAIL = 2
# 
# REQUEST_TYPE_PASSWORD = 3


# Path: app/account/admin.py
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from core import abstracts
from .models import Profile, Request, REQUEST_TYPE_ACCOUNT, REQUEST_TYPE_EMAIL, REQUEST_TYPE_PASSWORD

        elif (queryset.filter(type=REQUEST_TYPE_EMAIL)):
            for q in queryset:
                q.user.email = q.str_field_2
                q.user.save()
                q.user.profile.is_verified = False
                q.user.profile.save()
            queryset.update(is_approved=False)
        elif (queryset.filter(type=REQUEST_TYPE_PASSWORD)):
            for q in queryset:
                q.user.set_password("12345")
                q.user.save()
            queryset.update(is_approved=False)

            # rows_updated = queryset.update(is_approved=False)
            # if rows_updated == 1:
            # message_bit = "1 request was"
            # else:
            # message_bit = "%s requests were" % rows_updated
            # model_admin.message_user(request, "%s successfully marked as refused." % message_bit)


class RequestAdmin(abstracts.ModelAdminAbstract):
    list_display = ['user', 'type', 'is_approved', 'activation_key', 'str_field_1', 'str_field_2', 'dec_field_1',
                    'dec_field_2', 'bool_field_1', 'bool_field_2', 'key_expires_at', ]
    list_filter = ['user', 'type', 'is_approved', ]
    actions = [RequestActions.approve_selected_requests, RequestActions.refuse_selected_requests]


admin.site.unregister(User)
admin.site.register(User, UserNewAdmin)

admin.site.register(Profile, ProfileAdminAbstract)