summaryrefslogtreecommitdiff
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
parent46ecd030e8d2b68f155c6f8d2d4ad653500391c6 (diff)
posts: made create and update forms for notes
-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
-rw-r--r--config/base_urls.py14
-rw-r--r--templates/base.html9
9 files changed, 101 insertions, 27 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):
diff --git a/config/base_urls.py b/config/base_urls.py
index ba981f6..7825bb4 100644
--- a/config/base_urls.py
+++ b/config/base_urls.py
@@ -4,6 +4,7 @@ from django.conf import settings
from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.views.generic.base import RedirectView
+import debug_toolbar
admin.autodiscover()
admin.site.enable_nav_sidebar = False
@@ -16,15 +17,6 @@ urlpatterns = [
path(r'post/', include('posts.urls')),
re_path(r'^post/$', RedirectView.as_view(url='/posts/')),
path(r'posts/', include('posts.urls', namespace='posts')),
+ path(r'notes/', include('posts.note_urls')),
+ path('__debug__/', include(debug_toolbar.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
-
-
-if settings.DEBUG:
- import debug_toolbar
- urlpatterns = [
- path('__debug__/', include(debug_toolbar.urls)),
-
- # For django versions before 2.0:
- # url(r'^__debug__/', include(debug_toolbar.urls)),
-
- ] + urlpatterns
diff --git a/templates/base.html b/templates/base.html
index 80afbff..cca6bf3 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -28,16 +28,11 @@
{% block extrabody %}{% endblock %}
<footer class="page-footer">
<nav>
- <a class="nav-item" href="/about" title="About Corrinne">About</a>
- <a class="nav-item" href="/private-tutoring" title="Work with me">Work With Me</a>
- <a class="nav-item" href="/faq" title="Frequently asked questions">FAQ</a>
- {%comment %}<a class="nav-item" href="/what-is-structured-word-inquiry" title="How structured word inquiry helps children learn to read">What Is SWI?</a>
- <a class="nav-item" href="/resources/" title="Resources for parents and teachers">Resources</a>{% endcomment%}
- <a class="nav-item" href="/contact/" title="Contact Corrinne">Contact</a>
+ <a class="nav-item" href="/posts" title="View Guides">Guides</a>
</nav>
<p id="license">
&copy; 2020-{% now "Y" %}
- <span class="h-card"><a class="p-name u-url" href="https://tk.net/">Corrinne Gilbertson</a><data class="p-locality" value="Everywhere"></data><data class="p-country-name" value="United States"></data></span>.
+ <span class="h-card"><a class="p-name u-url" href="https://luxagraf.net/">luxagraf</a><data class="p-locality" value="Everywhere"></data><data class="p-country-name" value="United States"></data></span>.
</p>
</footer>
{% block js %}{% endblock%}