# Path: lazysignup/models.py
# class LazyUser(models.Model):
#     user = models.OneToOneField(constants.LAZYSIGNUP_USER_MODEL, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=now, db_index=True)
#     objects = LazyUserManager()
# 
#     @classmethod
#     def get_user_class(cls):
#         related_user_field = cls._meta.get_field('user')
#         # Django < 1.9 has rel.to
#         if hasattr(related_user_field, 'rel'):
#             rel_to = related_user_field.rel.to if related_user_field.rel else None
#         elif hasattr(related_user_field, 'remote_field'):
#             rel_to = related_user_field.remote_field.model if related_user_field.remote_field else None
#         return rel_to
# 
#     def __str__(self):
#         return '{0}:{1}'.format(self.user, self.created)


import datetime
from django.conf import settings
from django.core.management.base import BaseCommand
from lazysignup.models import LazyUser




class Command(BaseCommand):
    help = u"""Remove all users whose sessions have expired and who haven't
               set a password. This assumes you are using database sessions"""

    def handle(self, **options):
        # Delete each of these users. We don't use the queryset delete()
        # because we want cascades to work (including, of course, the LazyUser
        # object itself)
        for lazy_user in self.to_delete():
            lazy_user.user.delete()

    def to_delete(self):
        delete_before = datetime.datetime.now() - datetime.timedelta(
            seconds=settings.SESSION_COOKIE_AGE)

# Path: lazysignup/models.py
# class LazyUser(models.Model):
#     user = models.OneToOneField(constants.LAZYSIGNUP_USER_MODEL, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=now, db_index=True)
#     objects = LazyUserManager()
# 
#     @classmethod
#     def get_user_class(cls):
#         related_user_field = cls._meta.get_field('user')
#         # Django < 1.9 has rel.to
#         if hasattr(related_user_field, 'rel'):
#             rel_to = related_user_field.rel.to if related_user_field.rel else None
#         elif hasattr(related_user_field, 'remote_field'):
#             rel_to = related_user_field.remote_field.model if related_user_field.remote_field else None
#         return rel_to
# 
#     def __str__(self):
#         return '{0}:{1}'.format(self.user, self.created)


# Path: lazysignup/management/commands/remove_expired_users.py
import datetime
from django.conf import settings
from django.core.management.base import BaseCommand
from lazysignup.models import LazyUser





class Command(BaseCommand):
    help = u"""Remove all users whose sessions have expired and who haven't
               set a password. This assumes you are using database sessions"""

    def handle(self, **options):
        # Delete each of these users. We don't use the queryset delete()
        # because we want cascades to work (including, of course, the LazyUser
        # object itself)
        for lazy_user in self.to_delete():
            lazy_user.user.delete()

    def to_delete(self):
        delete_before = datetime.datetime.now() - datetime.timedelta(
            seconds=settings.SESSION_COOKIE_AGE)

        return LazyUser.objects.filter(