Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ gunicorn = "*"
dj-database-url = "*"
slack-sdk = "*"
sentry-sdk = "*"
wagtail = "*"
wagtail-factories = "*"

[dev-packages]
pytest = "*"
Expand Down
498 changes: 362 additions & 136 deletions Pipfile.lock

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@
from django.test import Client
import pytest
from pytest_factoryboy import register
from wagtail.models import Locale, Site

from authentication.tests.factories.student_user_factory import StudentUserFactory
from authentication.tests.factories.user_factory import UserFactory
from payment.tests.factories.referral_coupon_factory import ReferralCouponFactory
from payment.tests.factories.coupon_effect_factory import CouponEffectFactory
from staff.tests.factories.batch_factory import BatchFactory
from staff.tests.factories.batch_page_factory import BatchPageFactory
from staff.tests.factories.batch_schedule_factory import BatchScheduleFactory
from staff.tests.factories.course_factory import CourseFactory
from staff.tests.factories.course_page_factory import CoursePageFactory
from staff.tests.factories.day_page_factory import DayPageFactory
from staff.tests.factories.section_factory import SectionFactory
from student.tests.factories.certificate_factory import CertificateFactory
from student.tests.factories.enrolment_factory import EnrolmentFactory
from student.tests.factories.registration_factory import RegistrationFactory

register(BatchFactory)
register(BatchPageFactory)
register(BatchScheduleFactory)
register(CertificateFactory)
register(CouponEffectFactory)
register(CourseFactory)
register(CoursePageFactory)
register(DayPageFactory)
register(EnrolmentFactory)
register(ReferralCouponFactory)
register(RegistrationFactory)
Expand Down Expand Up @@ -147,3 +154,14 @@ def swe_fundamentals_registration_early_bird(swe_fundamentals_batch, registratio
)

yield swe_fundamentals_registration_early_bird

###########
# WAGTAIL #
###########

@pytest.fixture()
def wagtail_site():
Locale.objects.create(language_code='en')
wagtail_site = Site(is_default_site=True)

yield wagtail_site
19 changes: 19 additions & 0 deletions learn/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@
'student',
'payment',
'emails',
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail',
'modelcluster',
'taggit'
]

# AUTHENTICATION
Expand Down Expand Up @@ -120,6 +133,7 @@
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down Expand Up @@ -282,3 +296,8 @@
COUPON_CODE_NOTIFICATION_TEMPLATE_ID = env('COUPON_CODE_NOTIFICATION_TEMPLATE_ID')
SWE_FUNDAMENTALS_GRADUATION_NOTIFICATION_TEMPLATE_ID = env('SWE_FUNDAMENTALS_GRADUATION_NOTIFICATION_TEMPLATE_ID')
SWE_FUNDAMENTALS_REGISTRATION_CONFIRMATION_TEMPLATE_ID = env('SWE_FUNDAMENTALS_REGISTRATION_CONFIRMATION_TEMPLATE_ID')

# WAGTAIL #
WAGTAIL_SITE_NAME = ROCKET_ACADEMY
WAGTAILADMIN_RECENT_EDITS_LIMIT = 5
WAGTAILEMBEDS_RESPONSIVE_HTML = True
40 changes: 40 additions & 0 deletions staff/migrations/0016_coursepage_batchpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 4.1.3 on 2022-12-06 13:42

from django.db import migrations, models
import django.db.models.deletion
import wagtail.fields


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0078_referenceindex'),
('staff', '0015_alter_course_name'),
]

operations = [
migrations.CreateModel(
name='CoursePage',
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')),
('intro', wagtail.fields.RichTextField(blank=True)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='staff.course')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
migrations.CreateModel(
name='BatchPage',
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')),
('intro', wagtail.fields.RichTextField(blank=True)),
('batch', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='staff.batch')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]
28 changes: 28 additions & 0 deletions staff/migrations/0017_daypage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.1.4 on 2023-01-03 08:17

from django.db import migrations, models
import django.db.models.deletion
import wagtail.fields


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0078_referenceindex'),
('staff', '0016_coursepage_batchpage'),
]

operations = [
migrations.CreateModel(
name='DayPage',
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)),
('batch_page', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='staff.batchpage')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]
3 changes: 3 additions & 0 deletions staff/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from .batch import Batch
from .batch_page import BatchPage
from .batch_schedule import BatchSchedule
from .certificate import Certificate
from .course import Course
from .course_page import CoursePage
from .day_page import DayPage
from .section import Section
2 changes: 1 addition & 1 deletion staff/models/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def save(self, *args, **kwargs):
return super().save(*args, **kwargs)

def __str__(self):
return f"Batch {self.number}"
return f"{self.course.get_name_display()} Batch {self.number}"

@classmethod
def next_number(self, course_id, type):
Expand Down
30 changes: 30 additions & 0 deletions staff/models/batch_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django import forms
from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page
from wagtail.search import index

from staff.models import Batch


class BatchPage(Page):
intro = RichTextField(blank=True)
batch = models.ForeignKey(Batch, on_delete=models.PROTECT)

search_fields = Page.search_fields + [
index.FilterField('intro'),
index.SearchField('intro'),
]

content_panels = Page.content_panels + [
FieldPanel('batch', widget=forms.Select),
FieldPanel('intro')
]

def save(self, *args, **kwargs):
# slug does not appear above as an attribute
# because it is an attribute on Wagtail's Page model
self.slug = self.batch.number

return super().save(*args, **kwargs)
3 changes: 3 additions & 0 deletions staff/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ class Course(SafeDeleteModel):
name = models.CharField(max_length=255, choices=NAME_CHOICES)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

def __str__(self):
return self.get_name_display()
23 changes: 23 additions & 0 deletions staff/models/course_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django import forms
from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page
from wagtail.search import index

from staff.models import Course


class CoursePage(Page):
intro = RichTextField(blank=True)
course = models.ForeignKey(Course, on_delete=models.PROTECT)

search_fields = Page.search_fields + [
index.FilterField('intro'),
index.SearchField('intro'),
]

content_panels = Page.content_panels + [
FieldPanel('course', widget=forms.Select),
FieldPanel('intro')
]
23 changes: 23 additions & 0 deletions staff/models/day_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django import forms
from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page
from wagtail.search import index

from staff.models import BatchPage


class DayPage(Page):
batch_page = models.ForeignKey(BatchPage, on_delete=models.PROTECT)
body = RichTextField(blank=True)

search_fields = Page.search_fields + [
index.FilterField('body'),
index.SearchField('body'),
]

content_panels = Page.content_panels + [
FieldPanel('batch_page', widget=forms.Select),
FieldPanel('body')
]
20 changes: 20 additions & 0 deletions staff/templates/staff/batch_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "staff_base.html" %}

{% load wagtailcore_tags %}

{% block body_class %}template-blogindexpage{% endblock %}

{% block content %}
<div class="row">
<div class="col-6">
<h1>{{ page.title }}</h1>

<div class="intro my-5">{{ page.intro|richtext }}</div>

{% for post in page.get_children %}
<h2><a href="{% pageurl post %}">{{ post.title }}</a></h2>
{% endfor %}
</div>
</div>

{% endblock %}
20 changes: 20 additions & 0 deletions staff/templates/staff/course_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "staff_base.html" %}

{% load wagtailcore_tags %}

{% block body_class %}template-blogindexpage{% endblock %}

{% block content %}
<div class="row">
<div class="col-6">
<h1>{{ page.title }}</h1>

<div class="intro my-5">{{ page.intro|richtext }}</div>

{% for post in page.get_children %}
<h4><a href="{% pageurl post %}">{{ post.title }}</a></h4>
{% endfor %}
</div>
</div>

{% endblock %}
20 changes: 20 additions & 0 deletions staff/templates/staff/day_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "staff_base.html" %}

{% load wagtailcore_tags %}

{% block body_class %}template-blogindexpage{% endblock %}

{% block content %}
<div class="row">
<div class="col-6">
<h1>{{ page.title }}</h1>

<div class="intro my-5">{{ page.body|richtext }}</div>

{% for post in page.get_children %}
<h2><a href="{% pageurl post %}">{{ post.title }}</a></h2>
{% endfor %}
</div>
</div>

{% endblock %}
25 changes: 25 additions & 0 deletions staff/tests/factories/batch_page_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.utils.text import slugify
from factory import LazyAttribute, SubFactory, Trait
from factory.fuzzy import FuzzyText
from wagtail_factories import PageFactory

from staff.models import BatchPage
from staff.tests.factories.batch_factory import BatchFactory

class BatchPageFactory(PageFactory):
class Meta:
model = BatchPage

title = FuzzyText(length=15)
slug = LazyAttribute(lambda object: slugify(object.batch.number))
intro = FuzzyText(length=20)
batch = SubFactory(BatchFactory, swe_fundamentals=True)

class Params:
swe_fundamentals = Trait(
batch=SubFactory(BatchFactory, swe_fundamentals=True)
)

coding_bootcamp = Trait(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be safer to name coding_bootcamp swe_bootcamp instead, to anticipate future bootcamp courses like Data Science bootcamp.

batch=SubFactory(BatchFactory, coding_bootcamp=True)
)
25 changes: 25 additions & 0 deletions staff/tests/factories/course_page_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.utils.text import slugify
from factory import LazyAttribute, SubFactory, Trait
from factory.fuzzy import FuzzyText
from wagtail_factories import PageFactory

from staff.models import CoursePage
from staff.tests.factories.course_factory import CourseFactory

class CoursePageFactory(PageFactory):
class Meta:
model = CoursePage

title = FuzzyText(length=15)
slug = LazyAttribute(lambda object: slugify(object.course.name.replace('_', '-')))
intro = FuzzyText(length=20)
course = SubFactory(CourseFactory, swe_fundamentals=True)

class Params:
swe_fundamentals = Trait(
course=SubFactory(CourseFactory, swe_fundamentals=True)
)

coding_bootcamp = Trait(
course=SubFactory(CourseFactory, coding_bootcamp=True)
)
Loading