from datetime import date, timedelta
from django.core.management import BaseCommand

from users.models import User


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument("username")

    def handle(self, *args, **options):
        username = options["username"]
        try:
            user = User.objects.get(username=username)
            today = date.today()
            delta = timedelta(180)
            user.license_expiry_date = today + delta
            user.save()
            self.stdout.write(
                f"new date set for user{user.username}: {user.license_expiry_date}"
            )

        except Exception as e:
            self.stdout.write(e)
