Skip to content

Commit

Permalink
Merge pull request #27 from xurble/django-5
Browse files Browse the repository at this point in the history
Django 5 Fixes
  • Loading branch information
xurble authored Jan 15, 2024
2 parents b725d3f + dfdd326 commit d385c98
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 320 deletions.
8 changes: 6 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

### 1.0.8
- Increases the size of GUIDs
- Adds support for Django 5

### 1.0.7
- Fixes a bug that could result in the wrong body being set on items with a <content:encoded> element
- Separates the handling of 403 and 410 result codes
- Separates the handling of 403 and 410 result codes

### 1.0.6
- Fixes a bug preventing existing enclosures being updated when re-reading a feed
Expand Down Expand Up @@ -29,4 +33,4 @@
- Admin improvements from Chris Spencer, does break reverse FK links so be careful.

### 0.1.2
- First really usable version
- First really usable version
73 changes: 36 additions & 37 deletions feeds/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models
from django.utils.timezone import utc

import time
import datetime
Expand Down Expand Up @@ -29,14 +28,14 @@ class Source(models.Model):
site_url = models.CharField(max_length=255, blank=True, null=True)
feed_url = models.CharField(max_length=512)
image_url = models.CharField(max_length=512, blank=True, null=True)

description = models.TextField(null=True, blank=True)

last_polled = models.DateTimeField(blank=True, null=True)
due_poll = models.DateTimeField(default=datetime.datetime(1900, 1, 1)) # default to distant past to put new sources to front of queue
etag = models.CharField(max_length=255, blank=True, null=True)
last_modified = models.CharField(max_length=255, blank=True, null=True) # just pass this back and forward between server and me , no need to parse

last_result = models.CharField(max_length=255,blank=True,null=True)
interval = models.PositiveIntegerField(default=400)
last_success = models.DateTimeField(blank=True, null=True)
Expand All @@ -45,17 +44,17 @@ class Source(models.Model):
status_code = models.PositiveIntegerField(default=0)
last_302_url = models.CharField(max_length=512, null=True, blank=True)
last_302_start = models.DateTimeField(null=True, blank=True)

max_index = models.IntegerField(default=0)

num_subs = models.IntegerField(default=1)

is_cloudflare = models.BooleanField(default=False)


def __str__(self):
return self.display_name

@property
def best_link(self):
#the html link else hte feed link
Expand All @@ -70,58 +69,58 @@ def display_name(self):
return self.best_link
else:
return self.name

@property
def garden_style(self):

if not self.live:
css = "background-color:#ccc;"
elif self.last_change is None or self.last_success is None:
css = "background-color:#D00;color:white"
else:
dd = datetime.datetime.utcnow().replace(tzinfo=utc) - self.last_change
dd = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc) - self.last_change

days = int (dd.days / 2)

col = 255 - days
if col < 0: col = 0

css = "background-color:#ff%02x%02x" % (col,col)

if col < 128:
css += ";color:white"

return css

@property
def health_box(self):

if not self.live:
css="#ccc;"
elif self.last_change == None or self.last_success == None:
css="#F00;"
else:
dd = datetime.datetime.utcnow().replace(tzinfo=utc) - self.last_change
dd = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc) - self.last_change

days = int (dd.days/2)

red = days
if red > 255:
red = 255

green = 255-days;
if green < 0:
green = 0

css = "#%02x%02x00" % (red,green)

return css


class Post(models.Model):
GUID_MAX_LENGTH = 1024
# an entry in a feed

source = models.ForeignKey(Source, on_delete=models.CASCADE, related_name='posts')
title = models.TextField(blank=True)
body = models.TextField()
Expand All @@ -141,26 +140,26 @@ def title_url_encoded(self):
if len(ret) > 2: ret = ret[2:]
except:
logging.info("Failed to url encode title of post {}".format(self.id))
ret = ""
ret = ""

def __str__(self):
return "%s: post %d, %s" % (self.source.display_name, self.index, self.title)

@property
def recast_link(self):

# TODO: This needs to come out, it's just for recast

#if "?" in self.link:
# return self.link + ("&recast_id=%d" % self.id)
#else:
# return self.link + ("?recast_id=%d" % self.id)current_subscription

return "/post/%d/" % self.id

class Meta:
ordering = ["index"]

class Enclosure(models.Model):

post = models.ForeignKey(Post, on_delete=models.CASCADE, related_name='enclosures')
Expand All @@ -169,10 +168,10 @@ class Enclosure(models.Model):
type = models.CharField(max_length=256)
medium = models.CharField(max_length=25, null=True, blank=True)
description = models.CharField(max_length=512, null= True, blank=True)

@property
def recast_link(self):

# TODO: This needs to come out, it's just for recast

#if "?" in self.href:
Expand All @@ -181,14 +180,14 @@ def recast_link(self):
# return self.href + ("?recast_id=%d" % self.id)

return "/enclosure/%d/" % self.id


class WebProxy(models.Model):
# this class if for Cloudflare avoidance and contains a list of potential
# web proxies that we can try, scraped from the internet
address = models.CharField(max_length=255)

def __str__(self):
return "Proxy:{}".format(self.address)


Loading

0 comments on commit d385c98

Please sign in to comment.