diff options
author | luxagraf <sng@luxagraf.net> | 2023-08-02 16:17:09 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2023-08-02 16:17:09 -0500 |
commit | 15f3969829705ee78ba20fb0fd5201e84112b7e9 (patch) | |
tree | 87d141bf2f49e3eeb5ce353cace451b009bc17c6 /app/posts | |
parent | 5be880ce1fabeb5eb4f1254f74c0212d1b71892b (diff) |
posts: added edit function to manual update that I've turned something
in so it disappears from my todo.
Diffstat (limited to 'app/posts')
-rw-r--r-- | app/posts/forms.py | 19 | ||||
-rw-r--r-- | app/posts/migrations/0016_post_post_status.py | 18 | ||||
-rw-r--r-- | app/posts/models.py | 9 | ||||
-rw-r--r-- | app/posts/templates/posts/post_form.html | 16 | ||||
-rw-r--r-- | app/posts/templates/posts/post_table.html | 6 | ||||
-rw-r--r-- | app/posts/urls.py | 5 | ||||
-rw-r--r-- | app/posts/views.py | 22 |
7 files changed, 92 insertions, 3 deletions
diff --git a/app/posts/forms.py b/app/posts/forms.py new file mode 100644 index 0000000..f1b9960 --- /dev/null +++ b/app/posts/forms.py @@ -0,0 +1,19 @@ +from django.forms import ModelForm +from django.forms import ChoiceField + +from .models import Post + +class PostUpdateForm(ModelForm): + + def __init__(self,*args,**kwargs): + user = kwargs.pop('user') + self.user = user + super(PostUpdateForm,self).__init__(*args,**kwargs) + + def save(self, commit=True): + self.instance.user = self.user + return super().save(commit=commit) + + class Meta: + model = Post + fields = ['title', 'post_status'] diff --git a/app/posts/migrations/0016_post_post_status.py b/app/posts/migrations/0016_post_post_status.py new file mode 100644 index 0000000..ff50609 --- /dev/null +++ b/app/posts/migrations/0016_post_post_status.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.2 on 2023-08-02 20:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('posts', '0015_delete_note'), + ] + + operations = [ + migrations.AddField( + model_name='post', + name='post_status', + field=models.IntegerField(choices=[(0, 'Assigned'), (1, 'turned in'), (2, 'published')], default=2), + ), + ] diff --git a/app/posts/models.py b/app/posts/models.py index 674dd5f..f42956e 100644 --- a/app/posts/models.py +++ b/app/posts/models.py @@ -40,6 +40,12 @@ class TemplateType(models.IntegerChoices): GALLERY = 1, ('gallery') +class PostStatus(models.IntegerChoices): + ASSIGNED = 0, ('Assigned') + TURNEDIN = 1, ('turned in') + PUBLISHED = 2, ('published') + + class Post(models.Model): # an entry in a feed user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL) @@ -55,6 +61,7 @@ class Post(models.Model): 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) class Meta: @@ -85,7 +92,7 @@ class Post(models.Model): def save(self, *args, **kwargs): td = timezone.localdate() - self.date_last_pub - if td.days > self.update_frequency: + if td.days > self.update_frequency and self.post_status != 1: self.needs_update = True else: self.needs_update = False diff --git a/app/posts/templates/posts/post_form.html b/app/posts/templates/posts/post_form.html new file mode 100644 index 0000000..23289fe --- /dev/null +++ b/app/posts/templates/posts/post_form.html @@ -0,0 +1,16 @@ +{% extends 'base.html' %} +{% block primary %} +<main role="main" class="archive-wrapper"> + <form action="" method="post" class="comment-form">{% csrf_token %} + {% for field in form %} + <fieldset> + {%if field.name == "guide_type" or field.name == "post_status" %}<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> + {%endfor%} + <input class="btn" type="submit" name="add_new" value="Save and add another" /> + <input type="submit" name="save" class="btn" value="Save" /> + </form> +</main> +{% endblock %} diff --git a/app/posts/templates/posts/post_table.html b/app/posts/templates/posts/post_table.html index 2fa18a0..4779149 100644 --- a/app/posts/templates/posts/post_table.html +++ b/app/posts/templates/posts/post_table.html @@ -29,6 +29,9 @@ Date last pub <th scope="col" class="column-days_overdue"> <div class="text"><span>Days overdue</span></div> </th> +<th scope="col" class="column-days_overdue"> + <div class="text"><span>Edit</span></div> +</th> </tr> </thead> <tbody>{% for object in object_list %} @@ -48,7 +51,8 @@ Date last pub <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 'posts:edit' object.pk %}">edit</a></td></tr> </tr> {% endfor %} {% if reviews %}{% for object in reviews %} diff --git a/app/posts/urls.py b/app/posts/urls.py index 8c91a4c..19dc257 100644 --- a/app/posts/urls.py +++ b/app/posts/urls.py @@ -16,6 +16,11 @@ urlpatterns = [ name="new" ), path( + r'<pk>/edit', + views.PostUpdateView.as_view(), + name="edit" + ), + path( r'todo', views.PostTodoView.as_view(), name="new" diff --git a/app/posts/views.py b/app/posts/views.py index 3e0ac23..25a8074 100644 --- a/app/posts/views.py +++ b/app/posts/views.py @@ -2,8 +2,10 @@ from django.views.generic import UpdateView, DetailView, ListView from django.views.generic.edit import CreateView, DeleteView, UpdateView from django.contrib.auth.mixins import LoginRequiredMixin from django.db.models import Q +from django.urls import reverse from .models import Post +from .forms import PostUpdateForm from notes.models import Note class PostListView(LoginRequiredMixin, ListView): @@ -22,7 +24,7 @@ class PostNewView(LoginRequiredMixin, ListView): def get_context_data(self, **kwargs): context = super(PostNewView, self).get_context_data(**kwargs) - context['reviews'] = Note.objects.filter(plan__in=[1,2]) + context['reviews'] = Note.objects.filter(plan__in=[1,2], status__in=[0,1,2,3]) return context @@ -43,3 +45,21 @@ class PostTodoView(LoginRequiredMixin, ListView): class PostNotesView(LoginRequiredMixin, DetailView): model = Post + + +class PostUpdateView(LoginRequiredMixin, UpdateView): + model = Post + form_class = PostUpdateForm + + def get_form_kwargs(self): + kwargs = super(PostUpdateView, self).get_form_kwargs() + kwargs.update({'user': self.request.user}) + return kwargs + + def get_success_url(self): + if 'add_new' in self.request.POST: + return reverse('posts:create') + else: + return reverse('posts:detail', kwargs={"pk": self.object.pk}) + + |