summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/gtd/management/__init__.py0
-rw-r--r--app/gtd/management/commands/__init__.py0
-rw-r--r--app/gtd/management/commands/rss_updater.py67
-rw-r--r--app/gtd/migrations/0013_gtdnote_url.py18
-rw-r--r--app/gtd/migrations/0014_gtdnote_plan_gtdnote_work_status.py23
-rw-r--r--app/gtd/migrations/0015_rename_plan_gtdnote_work_plan.py18
-rw-r--r--app/gtd/migrations/0016_alter_gtdnote_work_plan.py18
-rw-r--r--app/gtd/migrations/0017_alter_gtdnote_note_type_alter_gtdnote_status_and_more.py28
-rw-r--r--app/gtd/models.py61
9 files changed, 218 insertions, 15 deletions
diff --git a/app/gtd/management/__init__.py b/app/gtd/management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/gtd/management/__init__.py
diff --git a/app/gtd/management/commands/__init__.py b/app/gtd/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/gtd/management/commands/__init__.py
diff --git a/app/gtd/management/commands/rss_updater.py b/app/gtd/management/commands/rss_updater.py
new file mode 100644
index 0000000..41ffa99
--- /dev/null
+++ b/app/gtd/management/commands/rss_updater.py
@@ -0,0 +1,67 @@
+from django.core.management.base import BaseCommand, CommandError
+
+import datetime
+import feedparser
+from urllib.parse import urlparse
+
+from django.contrib.auth import get_user_model
+
+from posts.models import PostStatus, Post
+User = get_user_model()
+"""
+run from a cronscript that looks line this:
+
+*/1 * * * * cd /home/lxf/sites/wired.luxagraf.net && source /home/lxf/sites/wired.luxagraf.net/venv/bin/activate && /home/lxf/sites/wired.luxagraf.net/venv/bin/python /home/lxf/sites/wired.luxagraf.net/manage.py rss_updater --settings=config.settings
+"""
+
+class Command(BaseCommand):
+ help = "Update all published posts"
+
+ def is_deal(self, tags):
+ for tag in tags:
+ if tag['term'] == "Deals":
+ return True
+ return False
+
+ def handle(self, *args, **options):
+ feed = feedparser.parse("https://www.wired.com/feed/tag/commerce/latest/rss")
+ for item in feed.entries:
+ url = urlparse(item.link)
+ story_type = url.path.split('/')[1]
+ if story_type == "story" or "gallery":
+ if not self.is_deal(item.tags):
+ try:
+ post = Post.objects.get(url=item.link)
+ post.date_last_pub = datetime.datetime.strptime(item.published, '%a, %d %b %Y %H:%M:%S %z').date()
+ post.post_status = PostStatus.PUBLISHED
+ post.save()
+ self.stdout.write(
+ self.style.SUCCESS('Successfully updated post "%s"' % post.title)
+ )
+ except:
+ continue
+ if story_type == "review":
+ """
+ TODO: add first and last names so I have everyone in the DB
+ Then parse and add reviews, but change views so we don't see them
+ in views where we just want a list of guides to update
+ """
+ user = User.objects.get(firstname=item.author.split(" ")[0],lastname=item.author.split(" ")[1])
+ dt = datetime.datetime.strptime(item.published, '%a, %d %b %Y %H:%M:%S %z').date()
+
+ post = Post.objects.get(url=item.link)
+
+ user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL)
+ title = models.CharField(max_length=512, blank=True, null=True)
+ body = models.TextField(blank=True, null=True)
+ url = models.CharField(max_length=512, blank=True, null=True)
+ date_last_pub = models.DateField()
+ guid = models.CharField(max_length=512, blank=True, null=True, db_index=True)
+ author = models.CharField(max_length=255, blank=True, null=True)
+ post_type = models.IntegerField(choices=PostType.choices, default=PostType.GUIDE)
+ template_type = models.IntegerField(choices=TemplateType.choices, default=TemplateType.STORY)
+ update_frequency = models.BigIntegerField(help_text="In days")
+ products = models.ManyToManyField(ProductLink, blank=True, null=True)
+ needs_update = models.BooleanField(default=False)
+ is_live = models.BooleanField(default=True)
+ post_status = models.IntegerField(choices=PostStatus.choices, default=PostStatus.PUBLISHED)
diff --git a/app/gtd/migrations/0013_gtdnote_url.py b/app/gtd/migrations/0013_gtdnote_url.py
new file mode 100644
index 0000000..911fa75
--- /dev/null
+++ b/app/gtd/migrations/0013_gtdnote_url.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.7 on 2023-11-17 08:58
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('gtd', '0012_alter_gtdnote_body_markdown_and_more'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='gtdnote',
+ name='url',
+ field=models.CharField(blank=True, max_length=400, null=True),
+ ),
+ ]
diff --git a/app/gtd/migrations/0014_gtdnote_plan_gtdnote_work_status.py b/app/gtd/migrations/0014_gtdnote_plan_gtdnote_work_status.py
new file mode 100644
index 0000000..760bae4
--- /dev/null
+++ b/app/gtd/migrations/0014_gtdnote_plan_gtdnote_work_status.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.7 on 2023-11-17 09:15
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('gtd', '0013_gtdnote_url'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='gtdnote',
+ name='plan',
+ field=models.IntegerField(choices=[(0, 'For Guide'), (1, 'Review'), (2, 'Rave/Rant'), (3, 'No Plan')], default=0),
+ ),
+ migrations.AddField(
+ model_name='gtdnote',
+ name='work_status',
+ field=models.IntegerField(choices=[(0, 'Call In'), (1, 'Asked For'), (2, 'Coming'), (3, 'Testing'), (4, 'Done'), (5, 'Live')], default=0),
+ ),
+ ]
diff --git a/app/gtd/migrations/0015_rename_plan_gtdnote_work_plan.py b/app/gtd/migrations/0015_rename_plan_gtdnote_work_plan.py
new file mode 100644
index 0000000..b378848
--- /dev/null
+++ b/app/gtd/migrations/0015_rename_plan_gtdnote_work_plan.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.7 on 2023-11-17 09:15
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('gtd', '0014_gtdnote_plan_gtdnote_work_status'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='gtdnote',
+ old_name='plan',
+ new_name='work_plan',
+ ),
+ ]
diff --git a/app/gtd/migrations/0016_alter_gtdnote_work_plan.py b/app/gtd/migrations/0016_alter_gtdnote_work_plan.py
new file mode 100644
index 0000000..ee7a400
--- /dev/null
+++ b/app/gtd/migrations/0016_alter_gtdnote_work_plan.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.7 on 2023-11-17 09:24
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('gtd', '0015_rename_plan_gtdnote_work_plan'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='gtdnote',
+ name='work_plan',
+ field=models.IntegerField(choices=[(1, 'For Guide'), (2, 'Review'), (3, 'Rave/Rant'), (0, 'No Plan')], default=1),
+ ),
+ ]
diff --git a/app/gtd/migrations/0017_alter_gtdnote_note_type_alter_gtdnote_status_and_more.py b/app/gtd/migrations/0017_alter_gtdnote_note_type_alter_gtdnote_status_and_more.py
new file mode 100644
index 0000000..c99a2e4
--- /dev/null
+++ b/app/gtd/migrations/0017_alter_gtdnote_note_type_alter_gtdnote_status_and_more.py
@@ -0,0 +1,28 @@
+# Generated by Django 4.2.7 on 2023-11-17 09:31
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('gtd', '0016_alter_gtdnote_work_plan'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='gtdnote',
+ name='note_type',
+ field=models.SmallIntegerField(choices=[(0, 'Action'), (1, 'Reminder'), (2, 'Reference')], default=0),
+ ),
+ migrations.AlterField(
+ model_name='gtdnote',
+ name='status',
+ field=models.SmallIntegerField(choices=[(0, 'None'), (1, 'Open'), (2, 'Completed')], default=1),
+ ),
+ migrations.AlterField(
+ model_name='gtdnote',
+ name='work_status',
+ field=models.SmallIntegerField(choices=[(0, 'Call In'), (1, 'Asked For'), (2, 'Coming'), (3, 'Testing'), (4, 'Done'), (5, 'Live')], default=0),
+ ),
+ ]
diff --git a/app/gtd/models.py b/app/gtd/models.py
index e74c33a..f54ac3a 100644
--- a/app/gtd/models.py
+++ b/app/gtd/models.py
@@ -89,27 +89,59 @@ class GTDProject(models.Model):
super(GTDProject, self).save(*args, **kwargs)
-class NoteType(models.IntegerChoices):
- ACTION = 0, ('action')
- REMINDER = 1, ('reminder')
- REFERENCE = 2, ('reference')
-
-
class GTDNote(models.Model):
title = models.CharField(max_length=200)
+ url = models.CharField(max_length=400, blank=True, null=True)
body_markdown = models.TextField(null=True, blank=True)
body_html = models.TextField(blank=True)
date_completed = models.DateField(null=True, blank=True)
date_created = models.DateTimeField(auto_now=True)
- note_type = models.IntegerField(choices=NoteType.choices, default=NoteType.ACTION)
+ ACTION = 0
+ REMINDER = 1
+ REFERENCE = 2
+ NOTE_TYPE = [
+ (ACTION, 'Action'),
+ (REMINDER, 'Reminder'),
+ (REFERENCE, 'Reference'),
+ ]
+ note_type = models.SmallIntegerField(choices=NOTE_TYPE, default=ACTION)
reminder = models.BigIntegerField(help_text="In days", null=True, blank=True)
project = models.ForeignKey(GTDProject, on_delete=models.SET_NULL, null=True, blank=True)
- STATUS = (
- (0, 'None'),
- (1, 'Open'),
- (2, 'Completed'),
+ NONE = 0
+ OPEN = 1
+ COMPLETED = 2
+ STATUS= [
+ (NONE, 'None'),
+ (OPEN, 'Open'),
+ (COMPLETED, 'Completed'),
+ ]
+ status = models.SmallIntegerField(choices=STATUS, default=OPEN)
+ CALLIN = 0
+ ASKEDFOR = 1
+ COMING = 2
+ TESTING = 3
+ DONE = 4
+ LIVE = 5
+ WORK_STATUS = (
+ (CALLIN, 'Call In'),
+ (ASKEDFOR, 'Asked For'),
+ (COMING, 'Coming'),
+ (TESTING, 'Testing'),
+ (DONE, 'Done'),
+ (LIVE, 'Live'),
)
- status = models.IntegerField(choices=STATUS, default=0)
+ work_status = models.SmallIntegerField(choices=WORK_STATUS, default=CALLIN)
+ NONE = 0
+ GUIDE = 1
+ REVIEW = 2
+ RAVE = 3
+ WORK_PLAN = (
+ (GUIDE, 'For Guide'),
+ (REVIEW, 'Review'),
+ (RAVE, 'Rave/Rant'),
+ (NONE, 'No Plan'),
+ )
+ work_plan = models.IntegerField(choices=WORK_PLAN, default=1)
class Meta:
ordering = ('-date_created',)
@@ -118,13 +150,12 @@ class GTDNote(models.Model):
def __str__(self):
return self.title
- def get_absolute_url(self, *args, **kwargs):
- return reverse('gtd:note-edit', kwargs={"pk": self.pk})
-
def save(self, *args, **kwargs):
self.body_html = markdown_to_html(self.body_markdown)
super(GTDNote, self).save(*args, **kwargs)
+ def get_absolute_url(self, *args, **kwargs):
+ return reverse('gtd:note-edit', kwargs={"pk": self.pk})
class PostType(models.IntegerChoices):
REVIEW = 0, ('review')