2024-04-24 09:50:42 -04:00
|
|
|
import datetime
|
|
|
|
|
2010-04-30 18:44:24 -04:00
|
|
|
from django.contrib.auth.models import User
|
2024-04-24 09:50:42 -04:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
2010-08-21 20:42:38 -04:00
|
|
|
from apps.reader.models import UserSubscription
|
2010-04-30 18:44:24 -04:00
|
|
|
|
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
class Command(BaseCommand):
|
2020-06-08 07:55:17 -04:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument("-d", "--days", dest="days", nargs=1, default=1, help="Days of unread")
|
|
|
|
parser.add_argument("-u", "--username", dest="username", nargs=1, help="Specify user id or username")
|
|
|
|
parser.add_argument("-U", "--userid", dest="userid", nargs=1, help="Specify user id or username")
|
2024-04-24 09:43:56 -04:00
|
|
|
|
2010-04-30 18:44:24 -04:00
|
|
|
def handle(self, *args, **options):
|
2024-04-24 09:43:56 -04:00
|
|
|
if options["userid"]:
|
|
|
|
user = User.objects.filter(pk=options["userid"])[0]
|
|
|
|
elif options["username"]:
|
|
|
|
user = User.objects.get(username__icontains=options["username"])
|
2010-04-30 18:44:24 -04:00
|
|
|
else:
|
2020-06-15 02:54:37 -04:00
|
|
|
raise Exception("Need username or user id.")
|
2024-04-24 09:43:56 -04:00
|
|
|
|
2011-03-31 18:51:23 -04:00
|
|
|
user.profile.last_seen_on = datetime.datetime.utcnow()
|
|
|
|
user.profile.save()
|
2010-04-30 18:44:24 -04:00
|
|
|
feeds = UserSubscription.objects.filter(user=user)
|
|
|
|
for sub in feeds:
|
2024-04-24 09:43:56 -04:00
|
|
|
if options["days"] == 0:
|
2010-04-30 18:44:24 -04:00
|
|
|
sub.mark_feed_read()
|
|
|
|
else:
|
2024-04-24 09:43:56 -04:00
|
|
|
sub.mark_read_date = datetime.datetime.utcnow() - datetime.timedelta(
|
|
|
|
days=int(options["days"])
|
|
|
|
)
|
2011-05-19 19:04:10 -04:00
|
|
|
sub.needs_unread_recalc = True
|
2024-04-24 09:43:56 -04:00
|
|
|
sub.save()
|