From 1f49a9fa1b3e0523825d966243fdd29082d68ffc Mon Sep 17 00:00:00 2001 From: Bae KwonHan Date: Sun, 9 Mar 2025 15:48:26 +0900 Subject: [PATCH] fix template --- .../pythonkr/migrations/0001_initial.py | 63 ++++++++++++ pythonkr_backend/pythonkr/models.py | 96 ++++++++++++++++++- .../{pao => pythonkr}/pao_communites.html | 0 .../{pao => pythonkr}/pao_event.html | 0 .../{pao => pythonkr}/pao_events.html | 0 .../{pao => pythonkr}/pao_home copy.html | 0 .../{pao => pythonkr}/pao_people.html | 0 .../{pao => pythonkr}/pao_person.html | 0 .../{pao => pythonkr}/pao_sponsor.html | 0 .../{pao => pythonkr}/pao_sponsors.html | 0 .../pao_base.html => pythonkr/pk_base.html} | 0 .../pao_home.html => pythonkr/pk_home.html} | 0 .../pk_markdown_doc.html} | 0 .../pao_page.html => pythonkr/pk_page.html} | 0 14 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 pythonkr_backend/pythonkr/migrations/0001_initial.py rename pythonkr_backend/pythonkr/templates/{pao => pythonkr}/pao_communites.html (100%) rename pythonkr_backend/pythonkr/templates/{pao => pythonkr}/pao_event.html (100%) rename pythonkr_backend/pythonkr/templates/{pao => pythonkr}/pao_events.html (100%) rename pythonkr_backend/pythonkr/templates/{pao => pythonkr}/pao_home copy.html (100%) rename pythonkr_backend/pythonkr/templates/{pao => pythonkr}/pao_people.html (100%) rename pythonkr_backend/pythonkr/templates/{pao => pythonkr}/pao_person.html (100%) rename pythonkr_backend/pythonkr/templates/{pao => pythonkr}/pao_sponsor.html (100%) rename pythonkr_backend/pythonkr/templates/{pao => pythonkr}/pao_sponsors.html (100%) rename pythonkr_backend/pythonkr/templates/{pao/pao_base.html => pythonkr/pk_base.html} (100%) rename pythonkr_backend/pythonkr/templates/{pao/pao_home.html => pythonkr/pk_home.html} (100%) rename pythonkr_backend/pythonkr/templates/{pao/pao_markdown_doc.html => pythonkr/pk_markdown_doc.html} (100%) rename pythonkr_backend/pythonkr/templates/{pao/pao_page.html => pythonkr/pk_page.html} (100%) diff --git a/pythonkr_backend/pythonkr/migrations/0001_initial.py b/pythonkr_backend/pythonkr/migrations/0001_initial.py new file mode 100644 index 0000000..a6a9b81 --- /dev/null +++ b/pythonkr_backend/pythonkr/migrations/0001_initial.py @@ -0,0 +1,63 @@ +# Generated by Django 5.1.7 on 2025-03-09 06:47 + +import django.db.models.deletion +import wagtail.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('wagtailcore', '0094_alter_page_locale'), + ] + + operations = [ + migrations.CreateModel( + name='PKDocPage', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), + ('content', wagtail.fields.RichTextField(blank=True)), + ('markdown_url', models.URLField(blank=True, null=True)), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='PKHomePage', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), + ('body', wagtail.fields.RichTextField(blank=True)), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='PKPage', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), + ('content', wagtail.fields.RichTextField(blank=True)), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='PKSponsors', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), + ('content', wagtail.fields.RichTextField()), + ('is_looking_for_sponsors', models.BooleanField(default=False)), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + ] diff --git a/pythonkr_backend/pythonkr/models.py b/pythonkr_backend/pythonkr/models.py index 71a8362..040ac46 100644 --- a/pythonkr_backend/pythonkr/models.py +++ b/pythonkr_backend/pythonkr/models.py @@ -1,3 +1,97 @@ +from wagtail.models import Page +from wagtail.fields import RichTextField +from wagtail.admin.panels import FieldPanel +from django.core.exceptions import ObjectDoesNotExist from django.db import models +from django.apps import apps +import httpx +import markdown -# Create your models here. + +class PKBasePage(Page): + class Meta: + abstract = True + + def get_context(self, request, *args, **kwargs): + "common context for PK" + context = super().get_context(request, *args, **kwargs) + + SponsorPageModel = apps.get_model("pythonkr", "PKSponsors") + try: + sponsor_page = SponsorPageModel.objects.get() + except ObjectDoesNotExist: + return context + + context["looking_for_sponsors"] = sponsor_page.is_looking_for_sponsors + context["current_sponsors"] = [] + + return context + +class PKSponsors(PKBasePage): + content = RichTextField() + is_looking_for_sponsors = models.BooleanField(default=False) + + parent_page_types = ["pythonkr.PKHomePage"] + + content_panels = Page.content_panels + [ + FieldPanel("content"), + FieldPanel("is_looking_for_sponsors"), + ] + +class PKPage(PKBasePage): + template = "pythonkr/pk_page.html" + content = RichTextField(blank=True) + + parent_page_types = ["pythonkr.PKHomePage"] + + content_panels = Page.content_panels + [ + FieldPanel("content"), + ] + + +class PKDocPage(PKBasePage): + template = "pythonkr/pk_markdown_doc.html" + + content = RichTextField(blank=True) + markdown_url = models.URLField(blank=True, null=True) + parent_page_types = ["pythonkr.PKHomePage"] + + content_panels = Page.content_panels + [ + FieldPanel("content"), + FieldPanel("markdown_url"), + ] + + def _render_markdown(self, markdown_text): + return markdown.markdown(markdown_text) + + def get_rendered_content(self): + if self.markdown_url: + response = httpx.get(self.markdown_url) + if response.status_code == 200: + return self._render_markdown(response.text) + return self.content + + def save(self, *args, **kwargs): + if self.markdown_url: + response = httpx.get(self.markdown_url) + if response.status_code == 200: + self.content = self._render_markdown(response.text) + super().save(*args, **kwargs) + + +class PKHomePage(PKBasePage): + template = "pythonkr/pk_home.html" + body = RichTextField(blank=True) + + subpage_types = [ + PKPage, + PKDocPage, + ] + + content_panels = Page.content_panels + [ + FieldPanel("body"), + ] + + def get_context(self, request, *args, **kwargs): + context = super().get_context(request, *args, **kwargs) + return context \ No newline at end of file diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_communites.html b/pythonkr_backend/pythonkr/templates/pythonkr/pao_communites.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_communites.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pao_communites.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_event.html b/pythonkr_backend/pythonkr/templates/pythonkr/pao_event.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_event.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pao_event.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_events.html b/pythonkr_backend/pythonkr/templates/pythonkr/pao_events.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_events.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pao_events.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_home copy.html b/pythonkr_backend/pythonkr/templates/pythonkr/pao_home copy.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_home copy.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pao_home copy.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_people.html b/pythonkr_backend/pythonkr/templates/pythonkr/pao_people.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_people.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pao_people.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_person.html b/pythonkr_backend/pythonkr/templates/pythonkr/pao_person.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_person.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pao_person.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_sponsor.html b/pythonkr_backend/pythonkr/templates/pythonkr/pao_sponsor.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_sponsor.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pao_sponsor.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_sponsors.html b/pythonkr_backend/pythonkr/templates/pythonkr/pao_sponsors.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_sponsors.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pao_sponsors.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_base.html b/pythonkr_backend/pythonkr/templates/pythonkr/pk_base.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_base.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pk_base.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_home.html b/pythonkr_backend/pythonkr/templates/pythonkr/pk_home.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_home.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pk_home.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_markdown_doc.html b/pythonkr_backend/pythonkr/templates/pythonkr/pk_markdown_doc.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_markdown_doc.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pk_markdown_doc.html diff --git a/pythonkr_backend/pythonkr/templates/pao/pao_page.html b/pythonkr_backend/pythonkr/templates/pythonkr/pk_page.html similarity index 100% rename from pythonkr_backend/pythonkr/templates/pao/pao_page.html rename to pythonkr_backend/pythonkr/templates/pythonkr/pk_page.html