diff options
author | luxagraf <sng@luxagraf.net> | 2023-11-16 10:35:58 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2023-11-16 10:35:58 -0500 |
commit | 28dcc949f8617c1e4b1ef0b02de91b5738661f10 (patch) | |
tree | 2e96dfcec3923d1d13dec908b0379850f789e6d8 /app/gtd | |
parent | 2722e2093d31481c4ad85cf7a1b1b22be11efccd (diff) |
gtd: revamped naming and added outcome CRUD views
Diffstat (limited to 'app/gtd')
-rw-r--r-- | app/gtd/migrations/0009_alter_gtdoutcome_date_ended_and_more.py | 28 | ||||
-rw-r--r-- | app/gtd/migrations/0010_alter_gtdproject_project_type.py | 18 | ||||
-rw-r--r-- | app/gtd/models.py | 20 | ||||
-rw-r--r-- | app/gtd/templates/gtd/outcome_form.html | 35 | ||||
-rw-r--r-- | app/gtd/templates/gtd/outcome_list.html | 21 | ||||
-rw-r--r-- | app/gtd/templates/gtd/project_list.html | 6 | ||||
-rw-r--r-- | app/gtd/templates/gtd/wiredpost_list.html (renamed from app/gtd/templates/gtd/post_list.html) | 0 | ||||
-rw-r--r-- | app/gtd/templates/gtd/wiredpost_table.html (renamed from app/gtd/templates/gtd/post_table.html) | 8 | ||||
-rw-r--r-- | app/gtd/urls.py | 60 | ||||
-rw-r--r-- | app/gtd/views.py | 59 |
10 files changed, 214 insertions, 41 deletions
diff --git a/app/gtd/migrations/0009_alter_gtdoutcome_date_ended_and_more.py b/app/gtd/migrations/0009_alter_gtdoutcome_date_ended_and_more.py new file mode 100644 index 0000000..7ebee2d --- /dev/null +++ b/app/gtd/migrations/0009_alter_gtdoutcome_date_ended_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.7 on 2023-11-16 14:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gtd', '0008_alter_wiredpost_date_last_pub'), + ] + + operations = [ + migrations.AlterField( + model_name='gtdoutcome', + name='date_ended', + field=models.DateField(blank=True, null=True), + ), + migrations.AlterField( + model_name='gtdoutcome', + name='date_goal', + field=models.DateField(blank=True, null=True), + ), + migrations.AlterField( + model_name='wiredpost', + name='date_last_pub', + field=models.DateField(), + ), + ] diff --git a/app/gtd/migrations/0010_alter_gtdproject_project_type.py b/app/gtd/migrations/0010_alter_gtdproject_project_type.py new file mode 100644 index 0000000..a7de764 --- /dev/null +++ b/app/gtd/migrations/0010_alter_gtdproject_project_type.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2023-11-16 14:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gtd', '0009_alter_gtdoutcome_date_ended_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='gtdproject', + name='project_type', + field=models.IntegerField(choices=[(0, 'Wired'), (1, 'LBH'), (2, 'Personal')], default=2), + ), + ] diff --git a/app/gtd/models.py b/app/gtd/models.py index f234c62..f99c41c 100644 --- a/app/gtd/models.py +++ b/app/gtd/models.py @@ -22,8 +22,8 @@ class GTDOutcome(models.Model): title = models.CharField(max_length=300) body_markdown = models.TextField() body_html = models.TextField(blank=True) - date_goal = models.DateField() - date_ended = models.DateField() + date_goal = models.DateField(blank=True, null=True) + date_ended = models.DateField(blank=True, null=True) def __str__(self): return self.title @@ -32,30 +32,30 @@ class GTDOutcome(models.Model): ordering = ('-date_goal',) def get_absolute_url(self): - return reverse('gtd:outcome', kwargs={"slug": self.slug}) + return reverse('gtd:outcome-detail', kwargs={"pk": self.pk}) def save(self, *args, **kwargs): created = self.pk is None if not created: md = render_images(self.body_markdown) self.body_html = markdown_to_html(md) - super(Outcome, self).save(*args, **kwargs) + super(GTDOutcome, self).save(*args, **kwargs) -class ProjectType(models.IntegerChoices): - WIRED = 0, ('Wired') - LBH = 1, ('LBH') - PERSONAL = 2, ('Personal') - class GTDProject(models.Model): + PROJECT_TYPE = ( + (0, 'Wired'), + (1, 'Lbh'), + (2, 'Personal') + ) title = models.CharField(max_length=200) short_title = models.CharField(max_length=200, blank=True, null=True) body_markdown = models.TextField(null=True, blank=True) body_html = models.TextField(blank=True) date_goal = models.DateField(blank=True, null=True) date_ended = models.DateField(blank=True, null=True) - project_type = models.IntegerField(choices=ProjectType.choices, default=ProjectType.WIRED) + project_type = models.IntegerField(choices=PROJECT_TYPE, default=2) outcome = models.ForeignKey(GTDOutcome, on_delete=models.SET_NULL, null=True, blank=True) class Meta: diff --git a/app/gtd/templates/gtd/outcome_form.html b/app/gtd/templates/gtd/outcome_form.html new file mode 100644 index 0000000..13591e8 --- /dev/null +++ b/app/gtd/templates/gtd/outcome_form.html @@ -0,0 +1,35 @@ +{% extends 'base_gtd.html' %} + +{% block extrahead %} +<style> +form .selector label { + position: inherit; +} +</style> +{% endblock %} +{% block primary %} +<main role="main" class="archive-wrapper"> + <div class="post-body"> + <form action="" method="post" class="comment-form">{% csrf_token %} + {% for field in form %} + <fieldset> + {%if field.name == "project" or field.name == "status" or field.name == 'note_type'%}<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> + </div> +</main> +{% endblock %} + {% block js %} + {% if is_update %}{%else%} +<script type="text/javascript"> +let params = new URL(document.location).searchParams; +document.getElementById('id_title').value = params.get("title"); +document.getElementById('id_body_markdown').value = params.get("description"); +</script> +{% endif %} + {% endblock%} diff --git a/app/gtd/templates/gtd/outcome_list.html b/app/gtd/templates/gtd/outcome_list.html new file mode 100644 index 0000000..025cc8f --- /dev/null +++ b/app/gtd/templates/gtd/outcome_list.html @@ -0,0 +1,21 @@ +{% extends 'base_gtd.html' %} +{% block primary %} +<main class="post-detail"> + <div class="post-header"><ul class="flex header-list"> + <li class="right"><a href="{% url 'gtd:outcome-create' %}" class="btn">New</a></li> + </ul> + </div> + <div class="note-list">{% for object in object_list %}<article> + <h2>{{object.title}}<span class="note-edit"><a href="{% url 'gtd:outcome-edit' object.pk %}">edit</a></span></h2> + <p>{{object.body_markdown}}</p> + <p class="small">Date Goal: {{object.date_goal}}</p> + <p class="small">Type: {{object.get_project_type_display}}</p> + <p class="small"><a href="{% url 'gtd:outcome-delete' object.pk %}">delete</a></p> + </article> +{% endfor%}</div> +</main> + + +{% endblock %} +{% block js %} +{% endblock%} diff --git a/app/gtd/templates/gtd/project_list.html b/app/gtd/templates/gtd/project_list.html index cba8944..24651de 100644 --- a/app/gtd/templates/gtd/project_list.html +++ b/app/gtd/templates/gtd/project_list.html @@ -2,10 +2,10 @@ {% block primary %} <main class="post-detail"> <div class="post-header"><ul class="flex header-list"> - {% for status in note_statuses %} - <li><a class="btn" href="{% url 'gtd:note-list-status' status.1|lower%}">{{status.1}}</a></li> + {% for object in project_types %} + <li><a class="btn" href="{% url 'gtd:project-list-type' object.1|lower%}">{%if object.1 == 'Lbh'%}{{object.1|upper}}{%else%}{{object.1}}{%endif%}</a></li> {% endfor %} - <li class="right"><a href="{% url 'gtd:note-create' %}" class="btn">New Note</a></li> + <li class="right"><a href="{% url 'gtd:project-create' %}" class="btn">New</a></li> </ul> </div> <div class="note-list">{% for object in object_list %}<article> diff --git a/app/gtd/templates/gtd/post_list.html b/app/gtd/templates/gtd/wiredpost_list.html index 1b56106..1b56106 100644 --- a/app/gtd/templates/gtd/post_list.html +++ b/app/gtd/templates/gtd/wiredpost_list.html diff --git a/app/gtd/templates/gtd/post_table.html b/app/gtd/templates/gtd/wiredpost_table.html index c9eb717..92eac7e 100644 --- a/app/gtd/templates/gtd/post_table.html +++ b/app/gtd/templates/gtd/wiredpost_table.html @@ -40,7 +40,7 @@ Date last pub <tbody>{% for object in object_list %} <tr> <td class="field-title"> - <a href="{% url 'gtd:post-detail' object.id %}">{{object.title}}</a> + <a href="{% url 'gtd:wiredpost-detail' object.id %}">{{object.title}}</a> </td> <td class="field-admin_url"> <a target="_blank" href="{{object.url}}"> @@ -50,7 +50,7 @@ Date last pub <td class="field-admin_url">{% if object.edit_url %} <a target="_blank" href="{{object.edit_url}}"> edit - </a>{%else%}<a href="{% url 'gtd:post-edit' object.pk %}">add</a>{%endif%} + </a>{%else%}<a href="{% url 'gtd:wiredpost-edit' object.pk %}">add</a>{%endif%} </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> @@ -60,13 +60,13 @@ Date last pub <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> - <td class="field-days_overdue"><a href="{% url 'gtd:post-edit' object.pk %}">edit</a></td></tr> + <td class="field-days_overdue"><a href="{% url 'gtd:wiredpost-edit' object.pk %}">edit</a></td></tr> </tr> {% endfor %} {% if reviews %}{% for object in reviews %} <tr> <td class="field-title"> - <a href="/post/{{object.id}}/notes">{{object.title}}</a> + <a href="{% url 'gtd:wiredpost_detail' object.id">{{object.title}}</a> </td> <td class="field-admin_url"> <a target="_blank" href="{{object.url}}"> diff --git a/app/gtd/urls.py b/app/gtd/urls.py index 95d7acf..ec4c474 100644 --- a/app/gtd/urls.py +++ b/app/gtd/urls.py @@ -8,7 +8,7 @@ urlpatterns = [ path( r'todo', views.GTDNoteTODOView.as_view(), - name="note-list" + name="note-todo" ), path( r'notes', @@ -17,7 +17,7 @@ urlpatterns = [ name="note-list" ), path( - r'notes/create', + r'note/create', views.GTDNoteCreateView.as_view(), name="note-create" ), @@ -39,30 +39,36 @@ urlpatterns = [ path( r'projects', views.GTDProjectListView.as_view(), + {'project_type':None}, name="project-list" ), path( - r'projects/create', + r'project/create', views.GTDProjectCreateView.as_view(), name="project-create" ), path( - r'projects/<pk>', + r'project/<str:project_type>', + views.GTDProjectListView.as_view(), + name="project-list-type" + ), + path( + r'project/<pk>', views.GTDProjectDetailView.as_view(), name="project-detail" ), path( - r'projects/<pk>/edit', + r'project/<pk>/edit', views.GTDProjectUpdateView.as_view(), name="project-edit" ), path( - r'projects/<pk>/delete', + r'project/<pk>/delete', views.GTDProjectDeleteView.as_view(), name="project-delete" ), path( - r'wirednote', + r'wirednotes', views.WiredNoteListView.as_view(), {'status':None}, name="wirednote-list" @@ -88,28 +94,48 @@ urlpatterns = [ name="wirednote-delete" ), path( - r'post', + r'wiredposts', views.WiredPostListView.as_view(), - name="post-list" + name="wiredpost-list" ), path( - r'post/new', + r'wiredpost/create', views.WiredPostNewView.as_view(), - name="post-create" + name="wiredpost-create" ), path( - r'post/<pk>/edit', + r'wiredpost/<pk>/edit', views.WiredPostUpdateView.as_view(), - name="post-edit" + name="wiredpost-edit" ), path( - r'post/todo', + r'wiredpost/todo', views.WiredPostTodoView.as_view(), - name="post-todo" + name="wiredpost-todo" ), path( - r'<pk>/notes', + r'wiredpost/<pk>/notes', views.WiredPostNotesView.as_view(), - name="post-detail" + name="wiredpost-detail" + ), + path( + r'outcomes', + views.GTDOutcomeListView.as_view(), + name="outcome-list" + ), + path( + r'outcome/create', + views.GTDOutcomeCreateView.as_view(), + name="outcome-create" + ), + path( + r'outcome/<pk>/edit', + views.GTDOutcomeUpdateView.as_view(), + name="outcome-edit" + ), + path( + r'outcome/<pk>/delete', + views.GTDOutcomeDeleteView.as_view(), + name="outcome-delete" ), ] diff --git a/app/gtd/views.py b/app/gtd/views.py index 2fb419e..8aa2c30 100644 --- a/app/gtd/views.py +++ b/app/gtd/views.py @@ -1,10 +1,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.urls import reverse +from django.urls import reverse, reverse_lazy from django.db.models import Q -from .models import GTDNote, GTDProject, WiredNote, WiredPost +from .models import GTDNote, GTDProject, GTDOutcome, WiredNote, WiredPost from .forms import GTDNoteCreateForm, GTDNoteEditForm, GTDProjectCreateForm, GTDProjectUpdateForm, WiredNoteCreateForm, WiredNoteEditForm, WiredPostUpdateForm class GTDNoteCreateView(CreateView): @@ -97,10 +97,20 @@ class GTDProjectListView(ListView): model = GTDProject template_name = "gtd/project_list.html" - def get_context_data(self, **kwargs): + def get_queryset(self): + print("hello world") + print(self.kwargs['project_type']) + if self.kwargs['project_type']: + project_type_reverse = dict((v, k) for k, v in GTDProject.PROJECT_TYPE) + project_type = project_type_reverse[self.kwargs['project_type'].title()] + return GTDProject.objects.filter(project_type=project_type) context = super(GTDProjectListView, self).get_context_data(**kwargs) return context + def get_context_data(self, **kwargs): + context = super(GTDProjectListView, self).get_context_data(**kwargs) + context['project_types'] = GTDProject.PROJECT_TYPE + return context class GTDProjectDeleteView(DeleteView): # specify the model you want to use @@ -120,6 +130,7 @@ class GTDNoteTODOView(ListView): class WiredNoteCreateView(CreateView): model = WiredNote form_class = WiredNoteCreateForm + template_name = "gtd/wirednote_form.html" def get_form_kwargs(self): kwargs = super(WiredNoteCreateView, self).get_form_kwargs() @@ -139,6 +150,7 @@ class WiredNoteCreateView(CreateView): class WiredNoteUpdateView(UpdateView): model = WiredNote form_class = WiredNoteEditForm + template_name = "gtd/wirednote_form.html" def get_form_kwargs(self): kwargs = super(WiredNoteUpdateView, self).get_form_kwargs() @@ -150,11 +162,12 @@ class WiredNoteUpdateView(UpdateView): return context def get_success_url(self): - return reverse('gtd:post-detail', kwargs={"pk": self.object.post.pk}) + return reverse('gtd:wiredpost-detail', kwargs={"pk": self.object.post.pk}) class WiredNoteListView(ListView): model = WiredNote + template_name = "gtd/wirednote_list.html" def get_queryset(self): if self.kwargs['status']: @@ -178,14 +191,14 @@ class WiredNoteDeleteView(DeleteView): class WiredPostListView(ListView): model = WiredPost - template_name = 'gtd/post_table.html' + template_name = 'gtd/wiredpost_table.html' def get_queryset(self): return WiredPost.objects.all().order_by("-needs_update") class WiredPostNewView(ListView): - template_name = 'gtd/post_list.html' + template_name = 'gtd/wiredpost_list.html' def get_queryset(self): return WiredPost.objects.filter(is_live=0) @@ -197,7 +210,7 @@ class WiredPostNewView(ListView): class WiredPostTodoView(ListView): - template_name = 'gtd/post_table.html' + template_name = 'gtd/wiredpost_table.html' def get_queryset(self): qs = WiredPost.objects.filter(Q(needs_update=True) | Q(is_live=0)).exclude(post_status=1) @@ -212,6 +225,7 @@ class WiredPostTodoView(ListView): class WiredPostNotesView(DetailView): model = WiredPost + template_name = "gtd/wiredpost_detail.html" def get_context_data(self, **kwargs): context = super(WiredPostNotesView, self).get_context_data(**kwargs) @@ -222,6 +236,7 @@ class WiredPostNotesView(DetailView): class WiredPostUpdateView(UpdateView): model = WiredPost form_class = WiredPostUpdateForm + template_name = "gtd/wiredpost_form.html" def get_form_kwargs(self): kwargs = super(WiredPostUpdateView, self).get_form_kwargs() @@ -239,3 +254,33 @@ class GTDNoteDeleteView(DeleteView): model = GTDNote success_url ="/gtd/notes" template_name = "gtd/confirm_delete.html" + + +class GTDOutcomeCreateView(CreateView): + model = GTDOutcome + template_name = "gtd/outcome_form.html" + fields = ['title', 'body_markdown', 'date_goal', 'date_ended'] + success_url = reverse_lazy("gtd:outcome-list") + + +class GTDOutcomeUpdateView(UpdateView): + model = GTDOutcome + template_name = "gtd/outcome_form.html" + fields = ['title', 'body_markdown', 'date_goal', 'date_ended'] + success_url = reverse_lazy("gtd:outcome-list") + + def get_context_data(self, **kwargs): + context = super(GTDOutcomeUpdateView, self).get_context_data(**kwargs) + context['is_update'] = True + return context + +class GTDOutcomeListView(ListView): + model = GTDOutcome + template_name = "gtd/outcome_list.html" + + +class GTDOutcomeDeleteView(DeleteView): + # specify the model you want to use + model = GTDOutcome + success_url ="/gtd/outcomes" + template_name = "gtd/confirm_delete.html" |