only allow /m/
This commit is contained in:
parent
7f660c3db9
commit
250fa43c19
1 changed files with 9 additions and 2 deletions
|
|
@ -7,6 +7,7 @@ import lxml.html
|
|||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.db.models.functions import ExtractWeek, ExtractYear
|
||||
from django.urls import reverse
|
||||
|
|
@ -48,6 +49,10 @@ class Item(models.Model):
|
|||
self.get_hue()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
if '/m/' not in self.url:
|
||||
raise ValidationError("You can only use mobile urls(/m/)")
|
||||
|
||||
def __str__(self):
|
||||
return '%s (%s)' % (self.title, self.url)
|
||||
|
||||
|
|
@ -101,12 +106,14 @@ class Item(models.Model):
|
|||
return week, archive
|
||||
|
||||
def get_week(self):
|
||||
return int(self.published.strftime('%W'))
|
||||
return int(self.published.strftime('%W')) if self.published else None
|
||||
|
||||
def get_year(self):
|
||||
return int(self.published.strftime('%Y'))
|
||||
return int(self.published.strftime('%Y')) if self.published else None
|
||||
|
||||
def get_monday(self):
|
||||
if not self.published:
|
||||
return None
|
||||
d = '%s-W%s' % (self.get_year(), self.get_week())
|
||||
return datetime.strptime(d + '-1', "%Y-W%W-%w").strftime('%Y-%m-%d')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue