signal backend, app cleanup
This commit is contained in:
parent
4b157ed1d1
commit
6f18890739
43 changed files with 695 additions and 124 deletions
|
|
@ -13,6 +13,7 @@ from django.urls import reverse
|
|||
User = get_user_model()
|
||||
|
||||
|
||||
|
||||
class Settings(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
|
@ -37,6 +38,7 @@ class Item(models.Model):
|
|||
if self.url and not self.data:
|
||||
self.update_data()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return '%s (%s)' % (self.title, self.url)
|
||||
|
||||
|
|
@ -60,14 +62,15 @@ class Item(models.Model):
|
|||
cal = now.date().isocalendar()
|
||||
monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1)
|
||||
monday = timezone.datetime(monday.year, monday.month, monday.day, tzinfo=now.tzinfo)
|
||||
print(now.tzinfo)
|
||||
first_post = qs.filter(published__gt=monday).first()
|
||||
print('!!', first_post.published, now, first_post.published > now)
|
||||
if first_post.published < now:
|
||||
print('only this week')
|
||||
if first_post and first_post.published < now:
|
||||
week = qs.filter(published__gt=monday)
|
||||
elif not first_post:
|
||||
while qs.exists() and not first_post:
|
||||
monday = monday - timedelta(days=7)
|
||||
first_post = qs.filter(published__gt=monday).first()
|
||||
week = qs.filter(published__gt=monday)
|
||||
else:
|
||||
print('only last week')
|
||||
last_monday = monday - timedelta(days=7)
|
||||
week = qs.filter(published__gt=last_monday)
|
||||
archive = qs.exclude(id__in=week)
|
||||
|
|
@ -102,6 +105,7 @@ class Comment(models.Model):
|
|||
|
||||
item = models.ForeignKey(Item, related_name='comments', on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, null=True, related_name='comments', on_delete=models.CASCADE, blank=True)
|
||||
session_key = models.CharField(max_length=60, null=True, default=None, blank=True)
|
||||
|
||||
name = models.CharField(max_length=1024)
|
||||
email = models.CharField(max_length=1024)
|
||||
|
|
@ -109,6 +113,11 @@ class Comment(models.Model):
|
|||
data = models.JSONField(default=dict, editable=False)
|
||||
published = models.DateTimeField(null=True, default=None)
|
||||
|
||||
class Meta:
|
||||
permissions = [
|
||||
("can_post_comment", "Can post comments without moderation")
|
||||
]
|
||||
|
||||
@property
|
||||
def is_published(self):
|
||||
return bool(self.published)
|
||||
|
|
@ -128,7 +137,11 @@ class Comment(models.Model):
|
|||
|
||||
def json(self):
|
||||
data = {}
|
||||
data['name'] = self.name
|
||||
if not self.user:
|
||||
data['name'] = '%s (guest)' % self.name
|
||||
else:
|
||||
data['name'] = self.name
|
||||
data['date'] = self.date
|
||||
data['text'] = self.text
|
||||
return data
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue