|
| 1 | +from django.core.management.base import BaseCommand |
| 2 | +from wagtail.models import Page, Site |
| 3 | + |
| 4 | +from core.factories import SponsorshipLevelFactory, MeetupFactory, HomePageFactory, SimplePageFactory |
| 5 | +from core.models import HomePage, SimplePage |
| 6 | + |
| 7 | + |
| 8 | +class Command(BaseCommand): |
| 9 | + help = "Generate sample data for development" |
| 10 | + |
| 11 | + def handle(self, *args, **options): |
| 12 | + self.stdout.write("Generating sample data...") |
| 13 | + |
| 14 | + self._create_sponsorship_levels() |
| 15 | + self._create_meetups() |
| 16 | + home = self._create_home_page() |
| 17 | + self._create_navigation_pages(home) |
| 18 | + |
| 19 | + self.stdout.write(self.style.SUCCESS("\nSample data generated successfully!")) |
| 20 | + |
| 21 | + def _create_sponsorship_levels(self): |
| 22 | + levels = [("Bronze", 100), ("Silver", 200), ("Gold", 300), ("Platinum", 400)] |
| 23 | + for name, level in levels: |
| 24 | + SponsorshipLevelFactory(name=name, level=level) |
| 25 | + self.stdout.write(self.style.SUCCESS("Created sponsorship levels")) |
| 26 | + |
| 27 | + def _create_meetups(self): |
| 28 | + names = ["Python Ireland Monthly Meetup", "Django Dublin", "PyData Ireland"] |
| 29 | + for i, name in enumerate(names): |
| 30 | + MeetupFactory(id=f"meetup-{i}", name=name) |
| 31 | + self.stdout.write(self.style.SUCCESS("Created meetups")) |
| 32 | + |
| 33 | + def _create_home_page(self): |
| 34 | + home = HomePage.objects.first() |
| 35 | + if home: |
| 36 | + self.stdout.write("Home page already exists") |
| 37 | + return home |
| 38 | + |
| 39 | + wagtail_root = Page.objects.get(depth=1) |
| 40 | + default_home_exists = Page.objects.filter(slug="home", depth=2).exists() |
| 41 | + slug = "python-ireland" if default_home_exists else "home" |
| 42 | + |
| 43 | + home = HomePageFactory.build( |
| 44 | + slug=slug, |
| 45 | + show_in_menus=True, |
| 46 | + body=self._get_home_content(), |
| 47 | + ) |
| 48 | + wagtail_root.add_child(instance=home) |
| 49 | + self.stdout.write(self.style.SUCCESS("Created home page")) |
| 50 | + |
| 51 | + site = Site.objects.filter(is_default_site=True).first() |
| 52 | + if site: |
| 53 | + site.root_page = home |
| 54 | + site.save() |
| 55 | + self.stdout.write(self.style.SUCCESS("Updated site root page")) |
| 56 | + |
| 57 | + return home |
| 58 | + |
| 59 | + def _create_navigation_pages(self, home): |
| 60 | + pycon = self._create_page(home, "PyCon 2025", "pycon-2025") |
| 61 | + self._create_page(pycon, "Schedule", "schedule") |
| 62 | + self._create_page(pycon, "Speakers", "pycon-speakers") |
| 63 | + self._create_page(pycon, "Sponsors", "pycon-sponsors") |
| 64 | + self._create_page(pycon, "Venue", "venue") |
| 65 | + self._create_page(pycon, "Tickets", "tickets") |
| 66 | + |
| 67 | + self._create_page(home, "Meetups", "meetups", self._get_meetups_content()) |
| 68 | + self._create_page(home, "Learning Resources", "learning-resources") |
| 69 | + |
| 70 | + previous = self._create_page(home, "Previous PyCons", "previous-pycons") |
| 71 | + for year in [2024, 2023, 2022, 2019]: |
| 72 | + self._create_page(previous, f"PyCon {year}", f"pycon-{year}") |
| 73 | + |
| 74 | + self._create_page(home, "Coaching program", "coaching-program") |
| 75 | + self._create_page(home, "About", "about") |
| 76 | + |
| 77 | + policies = self._create_page(home, "Policies", "policies") |
| 78 | + self._create_page(policies, "Code of Conduct", "code-of-conduct") |
| 79 | + self._create_page(policies, "Privacy Policy", "privacy-policy") |
| 80 | + self._create_page(policies, "Cookie Policy", "cookie-policy") |
| 81 | + |
| 82 | + def _create_page(self, parent, title, slug, body=None): |
| 83 | + if SimplePage.objects.filter(slug=slug).exists(): |
| 84 | + self.stdout.write(f" {title} already exists") |
| 85 | + return SimplePage.objects.get(slug=slug) |
| 86 | + |
| 87 | + page = SimplePageFactory.build(title=title, slug=slug, body=body or [], show_in_menus=True) |
| 88 | + parent.add_child(instance=page) |
| 89 | + self.stdout.write(self.style.SUCCESS(f"Created {title}")) |
| 90 | + return page |
| 91 | + |
| 92 | + def _get_home_content(self): |
| 93 | + return [ |
| 94 | + {"type": "heading", "value": "Introduction"}, |
| 95 | + {"type": "paragraph", "value": ( |
| 96 | + "<p>Python Ireland is the Irish organisation representing the various chapters of Python users. " |
| 97 | + "We organise meet ups and events for software developers, students, academics and anyone who wants " |
| 98 | + "to learn the language. One of our aims is to help grow and diversify the Python community in Ireland. " |
| 99 | + "We also develop and foster links with other Python based communities overseas.</p>" |
| 100 | + )}, |
| 101 | + {"type": "heading", "value": "PyCon Ireland 2025"}, |
| 102 | + {"type": "paragraph", "value": ( |
| 103 | + "<p>We are thrilled to announce PyCon Ireland 2025, taking place in Dublin " |
| 104 | + "on November 15th and 16th! Join us at the UCD O'Reilly Hall for this exciting event.</p>" |
| 105 | + )}, |
| 106 | + {"type": "paragraph", "value": ( |
| 107 | + "<p>PyCon Ireland 2025 will feature two talk tracks and two workshop tracks on both days. " |
| 108 | + "Your ticket includes breakfast and lunch. Join us Saturday evening for networking!</p>" |
| 109 | + )}, |
| 110 | + {"type": "paragraph", "value": ( |
| 111 | + "<p>Please adhere to our <a href='/policies/code-of-conduct/'>Code of Conduct</a>. " |
| 112 | + "Check <a href='/pycon-2025/'>Terms and conditions</a> for details.</p>" |
| 113 | + )}, |
| 114 | + {"type": "paragraph", "value": "<p>See you at PyCon Ireland 2025!</p>"}, |
| 115 | + ] |
| 116 | + |
| 117 | + def _get_meetups_content(self): |
| 118 | + return [ |
| 119 | + {"type": "heading", "value": "Python Ireland Meetups"}, |
| 120 | + {"type": "paragraph", "value": ( |
| 121 | + "<p>Join us at our regular meetups! We hold events every month.</p>" |
| 122 | + "<ul>" |
| 123 | + "<li><a href='https://www.meetup.com/pythonireland/events/'>Upcoming Events</a></li>" |
| 124 | + "<li><a href='https://www.meetup.com/pythonireland/photos/'>Photos</a></li>" |
| 125 | + "<li><a href='https://www.meetup.com/pythonireland/'>Python Ireland on Meetup.com</a></li>" |
| 126 | + "</ul>" |
| 127 | + )}, |
| 128 | + ] |
0 commit comments