diff options
author | luxagraf <sng@luxagraf.net> | 2023-09-22 10:04:37 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2023-09-22 10:04:37 -0400 |
commit | acf110f7379a2776ee917441f24fb9f6f07f0ac1 (patch) | |
tree | fcf524b91f3286776a04537658cfcaf794fb2ef7 | |
parent | 015bdab536631d522d7abd1c03c608c81de30924 (diff) |
notes/guides: cleaned up some code and made it easier to see what I need
to do.
-rw-r--r-- | app/notes/forms.py | 18 | ||||
-rw-r--r-- | app/notes/models.py | 4 | ||||
-rw-r--r-- | app/notes/templates/notes/note_form.html | 2 | ||||
-rw-r--r-- | app/notes/views.py | 10 | ||||
-rw-r--r-- | app/posts/management/commands/rss_updater.py | 27 | ||||
-rw-r--r-- | app/posts/templates/posts/post_table.html | 5 | ||||
-rw-r--r-- | app/posts/views.py | 2 |
7 files changed, 58 insertions, 10 deletions
diff --git a/app/notes/forms.py b/app/notes/forms.py index f4ca7b9..93cb0be 100644 --- a/app/notes/forms.py +++ b/app/notes/forms.py @@ -20,3 +20,21 @@ class NoteCreateForm(ModelForm): class Meta: model = Note fields = ['title', 'url', 'body_markdown', 'post'] + + + +class NoteEditForm(ModelForm): + + def __init__(self,*args,**kwargs): + user = kwargs.pop('user') + self.user = user + super(NoteEditForm,self).__init__(*args,**kwargs) + self.fields['post'].queryset = Post.objects.all().order_by("title") + + def save(self, commit=True): + self.instance.user = self.user + return super().save(commit=commit) + + class Meta: + model = Note + fields = ['title', 'url', 'body_markdown', 'post', 'status', 'plan'] diff --git a/app/notes/models.py b/app/notes/models.py index 7f8dab0..7687283 100644 --- a/app/notes/models.py +++ b/app/notes/models.py @@ -25,8 +25,8 @@ class Note(models.Model): PLAN = ( (0, 'For Guide'), (1, 'Review'), - (2, 'Rave'), - (3, 'Rant'), + (2, 'Rave/Rant'), + (3, 'No Plan'), ) plan = models.IntegerField(choices=PLAN, default=0) diff --git a/app/notes/templates/notes/note_form.html b/app/notes/templates/notes/note_form.html index e360345..482d76e 100644 --- a/app/notes/templates/notes/note_form.html +++ b/app/notes/templates/notes/note_form.html @@ -4,7 +4,7 @@ <form action="" method="post" class="comment-form">{% csrf_token %} {% for field in form %} <fieldset> - {%if field.name == "post" or field.name == "status" %}<span class="selector">{{field.label_tag}}</span>{%else%}{{field.label_tag}}{%endif%} + {%if field.name == "post" or field.name == "status" or field.name == 'plan'%}<span class="selector">{{field.label_tag}}</span>{%else%}{{field.label_tag}}{%endif%} {%if field.name == "body_markdown"%}<div class="textarea-rounded">{{ field }}</div>{%else%}{{field}}{%endif%} </fieldset> <small class="alert">{% if field.errors %}{{field.errors}}{% endif %}</small> diff --git a/app/notes/views.py b/app/notes/views.py index 209d896..1b8ec1d 100644 --- a/app/notes/views.py +++ b/app/notes/views.py @@ -4,7 +4,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.urls import reverse from .models import Note -from .forms import NoteCreateForm +from .forms import NoteCreateForm, NoteEditForm class NoteCreateView(LoginRequiredMixin, CreateView): @@ -26,11 +26,15 @@ class NoteCreateView(LoginRequiredMixin, CreateView): return reverse('notes:create') - class NoteUpdateView(LoginRequiredMixin, UpdateView): model = Note - fields = ['title', 'url', 'body_markdown', 'post', 'status', 'plan'] + form_class = NoteEditForm + def get_form_kwargs(self): + kwargs = super(NoteUpdateView, self).get_form_kwargs() + kwargs.update({'user': self.request.user}) + return kwargs + def get_context_data(self, **kwargs): context = super(NoteUpdateView, self).get_context_data(**kwargs) context['is_update'] = True diff --git a/app/posts/management/commands/rss_updater.py b/app/posts/management/commands/rss_updater.py index ad8551b..41ffa99 100644 --- a/app/posts/management/commands/rss_updater.py +++ b/app/posts/management/commands/rss_updater.py @@ -4,8 +4,10 @@ import datetime import feedparser from urllib.parse import urlparse -from posts.models import PostStatus, Post +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: @@ -38,5 +40,28 @@ class Command(BaseCommand): ) 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/posts/templates/posts/post_table.html b/app/posts/templates/posts/post_table.html index 4779149..d9040e3 100644 --- a/app/posts/templates/posts/post_table.html +++ b/app/posts/templates/posts/post_table.html @@ -66,13 +66,14 @@ Date last pub </a> </td> <td class="field-date_last_pub nowrap">{{object.date_last_pub}}</td> - <td class="field-post_type"><span class="hide">{{object.post_type}}</span>{{object.get_post_type_display}}</td> + <td class="field-post_type"><span class="hide">{{object.post_type}}</span>{{object.get_plan_display}}</td> <td class="field-update_frequency">{{object.update_frequency}}</td> <td class="field-needs_update">{% if object.needs_update %} <span class="hide">1</span><img src="/static/admin/img/icon-yes.svg" alt="True">{%else%} <span class="hide">0</span><img src="/static/admin/img/icon-no.svg" alt="False">{%endif%} </td> - <td class="field-days_overdue">{{object.days_overdue}}</td></tr> + <td class="field-days_overdue">{{object.days_overdue}}</td> + <td class="field-days_overdue"><a href="{% url 'notes:edit' object.pk %}">edit</a></td></tr> </tr>{% endfor %}{% endif %} </tbody> </table> diff --git a/app/posts/views.py b/app/posts/views.py index 29796c4..40368df 100644 --- a/app/posts/views.py +++ b/app/posts/views.py @@ -47,7 +47,7 @@ class PostTodoView(LoginRequiredMixin, ListView): def get_context_data(self, **kwargs): context = super(PostTodoView, self).get_context_data(**kwargs) - context['reviews'] = Note.objects.filter(plan=1) + context['reviews'] = Note.objects.filter(plan__in=[1,2,3]).exclude(status=4) return context |