summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2023-07-19 15:50:29 -0500
committerluxagraf <sng@luxagraf.net>2023-07-19 15:50:29 -0500
commita22d349573d60564e582b9a314c9463385d03dac (patch)
treea8bb9d9d6e3edbb75e454539cd7cd7caab7e0744 /app
parent46ecd030e8d2b68f155c6f8d2d4ad653500391c6 (diff)
posts: made create and update forms for notes
Diffstat (limited to 'app')
-rw-r--r--app/posts/forms.py9
-rw-r--r--app/posts/migrations/0011_alter_note_url.py18
-rw-r--r--app/posts/models.py5
-rw-r--r--app/posts/note_urls.py23
-rw-r--r--app/posts/templates/posts/note_form.html18
-rw-r--r--app/posts/templates/posts/post_detail.html6
-rw-r--r--app/posts/views.py26
7 files changed, 96 insertions, 9 deletions
diff --git a/app/posts/forms.py b/app/posts/forms.py
index 89d350a..8f98980 100644
--- a/app/posts/forms.py
+++ b/app/posts/forms.py
@@ -1,11 +1,14 @@
from django.forms import ModelForm
-class CreateForm(forms.ModelForm):
+from .models import Note, Post
+
+class NoteCreateForm(ModelForm):
def __init__(self,*args,**kwargs):
user = kwargs.pop('user')
- super(CreateForm,self).__init__(*args,**kwargs)
- self.fields['post'].queryset = Post.objects.filter(user=user)
+ super(NoteCreateForm,self).__init__(*args,**kwargs)
+ self.fields['post'].queryset = Post.objects.filter(user=user).order_by("title")
class Meta:
model = Note
+ fields = ['title', 'url', 'body_markdown', 'post']
diff --git a/app/posts/migrations/0011_alter_note_url.py b/app/posts/migrations/0011_alter_note_url.py
new file mode 100644
index 0000000..de97e8a
--- /dev/null
+++ b/app/posts/migrations/0011_alter_note_url.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.2 on 2023-07-19 19:46
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('posts', '0010_post_is_live_post_user'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='note',
+ name='url',
+ field=models.CharField(blank=True, max_length=400, null=True),
+ ),
+ ]
diff --git a/app/posts/models.py b/app/posts/models.py
index 91420e1..8781bc1 100644
--- a/app/posts/models.py
+++ b/app/posts/models.py
@@ -1,4 +1,5 @@
from django.db import models
+from django.urls import reverse
from django.utils.html import format_html, format_html_join
from django.utils import timezone
import settings
@@ -93,7 +94,7 @@ class Post(models.Model):
class Note(models.Model):
title = models.CharField(max_length=400)
- url = models.CharField(max_length=400)
+ url = models.CharField(max_length=400, blank=True, null=True)
body_markdown = models.TextField(blank=True, null=True)
date_created = models.DateTimeField(default=timezone.now)
post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True)
@@ -104,6 +105,8 @@ class Note(models.Model):
def __str__(self):
return self.title
+ def get_absolute_url(self):
+ return reverse('notes:edit', kwargs={"pk": self.pk})
#URL,This Article,Type,Lead,Previous Leads,Other Testers,Notes/Docs,Last Pub Date,Update Next,Months Since Update,Update Frequency (Months),Updates per year,Prev. Updates,"18 Mo Traffic Trend
'''
diff --git a/app/posts/note_urls.py b/app/posts/note_urls.py
new file mode 100644
index 0000000..4bf6914
--- /dev/null
+++ b/app/posts/note_urls.py
@@ -0,0 +1,23 @@
+from django.urls import path, re_path
+
+from . import views
+
+app_name = "notes"
+
+urlpatterns = [
+ path(
+ r'',
+ views.NoteCreateView.as_view(),
+ name="create"
+ ),
+ path(
+ r'<pk>/edit',
+ views.NoteUpdateView.as_view(),
+ name="edit"
+ ),
+ path(
+ r'<pk>/notes',
+ views.PostNotesView.as_view(),
+ name="detail"
+ ),
+]
diff --git a/app/posts/templates/posts/note_form.html b/app/posts/templates/posts/note_form.html
new file mode 100644
index 0000000..c3de7be
--- /dev/null
+++ b/app/posts/templates/posts/note_form.html
@@ -0,0 +1,18 @@
+{% 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 == "post"%}<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 type="submit" name="save" class="btn" value="Save" />
+ </form>
+</main>
+{% endblock %}
+ {% block js %}
+ {% endblock%}
diff --git a/app/posts/templates/posts/post_detail.html b/app/posts/templates/posts/post_detail.html
index 32d5ec4..8117fe6 100644
--- a/app/posts/templates/posts/post_detail.html
+++ b/app/posts/templates/posts/post_detail.html
@@ -6,9 +6,9 @@
<p>Last Updated: {{object.date_last_pub}}</p>
<p>Needs Update: {% if object.needs_update %} Yes {% if object.days_overdue %}{{object.days_overdue}} days overdue{%endif %}{%endif%}</p>
</div>
-<div class="note-list">{% for object in object.note_set.all%}
- <h2><a href="{{object.url}}">{{object.title}}</a></h2>
- <p>{{object.body_markdown}}</p>
+ <div class="note-list">{% for object in object.note_set.all%}<article>
+ <h2>{%if object.url%}<a href="{{object.url}}">{{object.title}}</a>{%else%}{{object.title}}{%endif%}<span class="note-edit"><a href="{{object.get_absolute_url}}">edit</a></span></h2>
+ <p>{{object.body_markdown}}</p></article>
{% endfor%}</div>
</main>
{% endblock %}
diff --git a/app/posts/views.py b/app/posts/views.py
index 41475d8..a26e53a 100644
--- a/app/posts/views.py
+++ b/app/posts/views.py
@@ -1,8 +1,11 @@
-from django.views.generic import UpdateView, DetailView, ListView
+from django.views.generic import UpdateView, DetailView, ListView
+from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
+from django.urls import reverse
-from .models import Post
+from .models import Post, Note
+from .forms import NoteCreateForm
class PostListView(ListView):
@@ -20,6 +23,25 @@ class PostNotesView(DetailView):
model = Post
+class NoteCreateView(CreateView):
+ model = Note
+ form_class = NoteCreateForm
+
+ def get_form_kwargs(self):
+ kwargs = super(NoteCreateView, self).get_form_kwargs()
+ kwargs.update({'user': self.request.user})
+ return kwargs
+
+ def get_success_url(self):
+ return reverse('posts:detail', kwargs={"pk": self.object.post.pk})
+
+
+class NoteUpdateView(UpdateView):
+ model = Note
+ fields = ['title', 'url', 'body_markdown', 'post']
+
+ def get_success_url(self):
+ return reverse('posts:detail', kwargs={"pk": self.object.post.pk})
'''
class UpdateViewWithUser(UpdateView):