aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-09-10 17:37:25 +0100
committerMatthew Lemon <y@yulqen.org>2024-09-10 17:37:25 +0100
commitb17cb510c32e22c59e0140c2f2d90cf6ccbed361 (patch)
treed69e688432e6063f7390fcf25e95d0919bac1792
parent7550f31f604fa45f9030a32b9b8fbc2d0739bed7 (diff)
All tests pass and sign-up page is editable
-rw-r--r--pyblackbird_cc/resources/forms.py81
-rw-r--r--pyblackbird_cc/resources/tests/test_file_processing.py10
-rw-r--r--pyblackbird_cc/resources/tests/test_views.py18
-rw-r--r--pyblackbird_cc/templates/account/signup.html37
4 files changed, 100 insertions, 46 deletions
diff --git a/pyblackbird_cc/resources/forms.py b/pyblackbird_cc/resources/forms.py
index 00869be..5327def 100644
--- a/pyblackbird_cc/resources/forms.py
+++ b/pyblackbird_cc/resources/forms.py
@@ -1,15 +1,19 @@
import logging
-from typing import List, Tuple
import magic
from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
-from crispy_forms.layout import Submit, Field, Layout, Button
+from crispy_forms.layout import Button
+from crispy_forms.layout import Field
+from crispy_forms.layout import Layout
+from crispy_forms.layout import Submit
from django import forms
-from pyblackbird_cc.resources.models import Resource, ResourceSubcategory
+from pyblackbird_cc.resources.models import Resource
from pyblackbird_cc.resources.models import ResourceCategory
+from pyblackbird_cc.resources.models import ResourceSubcategory
from pyblackbird_cc.resources.models import ResourceType
+
from .models import AGE_RANGE_CHOICES
from .models import CURRICULUM_CHOICES
@@ -19,10 +23,9 @@ ALLOWED_THUMBNAILS = 5
ALLOWED_PDFS = 20
-def _create_choices_tuple() -> List[Tuple[str, str]]:
+def _create_choices_tuple() -> list[tuple[str, str]]:
"""Returns a list of tuples containing resource subcategory names."""
- return sorted(list(ResourceSubcategory.objects.values_list('name', flat=True)), key=str)
-
+ return sorted(list(ResourceSubcategory.objects.values_list("name", flat=True)), key=str)
class ResourceCreateForm(forms.Form):
@@ -30,7 +33,7 @@ class ResourceCreateForm(forms.Form):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.add_input(Submit("submit", "Submit"))
- self.fields['subcategories'].choices = _create_choices_tuple()
+ self.fields["subcategories"].choices = _create_choices_tuple()
error_css_class = "error"
required_css_class = "required"
@@ -38,40 +41,42 @@ class ResourceCreateForm(forms.Form):
name = forms.CharField(
max_length=255,
help_text="Concisely describe what the resource is, aiming for"
- " in 35-45 characters. "
- "eg: 'Fractions KS2 Worksheet and Answers.'",
+ " in 35-45 characters. "
+ "eg: 'Fractions KS2 Worksheet and Answers.'",
)
description = forms.CharField(
max_length=5000,
widget=forms.Textarea,
help_text=" You can (and should) use <strong>Markdown</strong> here. "
- "This is your opportunity to clearly explain what your resource "
- "is all "
- "about! It’s worth remembering that you are using the space to "
- "communicate to two "
- "different audiences. Firstly, think about what fellow teachers "
- "would like "
- "to know, such as exactly what the resource contains and how it "
- "could be used in the classroom. Secondly, the words you include "
- "on this page are also talking to internal and external search "
- "engines."
- " External search engines, like Google, show the first 155 characters "
- "of the resource description, so make sure you take advantage "
- "of these "
- "characters by using lots of relevant keywords as part of an "
- "enticing pitch.",
+ "This is your opportunity to clearly explain what your resource "
+ "is all "
+ "about! It’s worth remembering that you are using the space to "
+ "communicate to two "
+ "different audiences. Firstly, think about what fellow teachers "
+ "would like "
+ "to know, such as exactly what the resource contains and how it "
+ "could be used in the classroom. Secondly, the words you include "
+ "on this page are also talking to internal and external search "
+ "engines."
+ " External search engines, like Google, show the first 155 characters "
+ "of the resource description, so make sure you take advantage "
+ "of these "
+ "characters by using lots of relevant keywords as part of an "
+ "enticing pitch.",
)
card_description = forms.CharField(
max_length=1000,
widget=forms.Textarea,
- help_text=("If you enter text here, it will be used in the 'card' description "
- "box on the home page. Max 1000 characters."),
+ help_text=(
+ "If you enter text here, it will be used in the 'card' description "
+ "box on the home page. Max 1000 characters."
+ ),
)
resource_type = forms.ModelChoiceField(queryset=ResourceType.objects.all())
age_range = forms.ChoiceField(
choices=AGE_RANGE_CHOICES,
help_text="Try to be accurate in your choice of age range so that your resource "
- "shows up in the correct searches. (Although we don't have searches yet!)",
+ "shows up in the correct searches. (Although we don't have searches yet!)",
)
curriculum = forms.ChoiceField(
choices=CURRICULUM_CHOICES,
@@ -80,8 +85,8 @@ class ResourceCreateForm(forms.Form):
main_resource_category = forms.ModelChoiceField(
queryset=ResourceCategory.objects.all(),
help_text="Categorise your resource by subject so it shows up in the correct "
- "searches. It's a good idea to limit the number of subjects you select "
- "to one or two to make your resource easier to find.",
+ "searches. It's a good idea to limit the number of subjects you select "
+ "to one or two to make your resource easier to find.",
)
subcategories = forms.MultipleChoiceField(
required=False,
@@ -110,10 +115,10 @@ class ResourceCreateForm(forms.Form):
required=False,
label="Cover images",
help_text="Your cover image will be displayed in the search results and as "
- "the first image on your resource page in the preview function. "
- "It is important to add an eye catching cover image that gives "
- "other teachers an idea about what your resource contains. "
- "You can multi-select up to 5 .png or .jpg files here.",
+ "the first image on your resource page in the preview function. "
+ "It is important to add an eye catching cover image that gives "
+ "other teachers an idea about what your resource contains. "
+ "You can multi-select up to 5 .png or .jpg files here.",
)
pdf_files.widget.attrs.update({"class": "file_upload", "accept": ".pdf"})
thumbnail_files.widget.attrs.update({"class": "file_upload", "accept": ".png,.jpg"})
@@ -121,8 +126,10 @@ class ResourceCreateForm(forms.Form):
min_value=1,
max_value=3,
required=False,
- help_text=("Please enter either 1, 2 or 3 here. This will dictate where on the page "
- "this resource will feature on the main list page."),
+ help_text=(
+ "Please enter either 1, 2 or 3 here. This will dictate where on the page "
+ "this resource will feature on the main list page."
+ ),
)
def clean_thumbnail_files(self):
@@ -159,7 +166,7 @@ class ResourceUpdateMetadataForm(forms.ModelForm):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.add_input(Submit("submit", "Submit"))
- self.fields['subcategories'].queryset = ResourceSubcategory.objects.all().order_by('name')
+ self.fields["subcategories"].queryset = ResourceSubcategory.objects.all().order_by("name")
error_css_class = "error"
required_css_class = "required"
@@ -245,7 +252,7 @@ class ResourceUpdateThumbnailsForm(forms.Form):
),
required=False,
label="Thumbnail files",
- help_text="You can upload 5 files."
+ help_text="You can upload 5 files.",
)
thumbnail_files.widget.attrs.update({"class": "file_upload", "accept": ".png,.jpg"})
diff --git a/pyblackbird_cc/resources/tests/test_file_processing.py b/pyblackbird_cc/resources/tests/test_file_processing.py
index e4ac781..7b95a9d 100644
--- a/pyblackbird_cc/resources/tests/test_file_processing.py
+++ b/pyblackbird_cc/resources/tests/test_file_processing.py
@@ -1,3 +1,6 @@
+from pathlib import Path
+
+from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.core.files.uploadedfile import SimpleUploadedFile
@@ -5,9 +8,8 @@ from django.core.files.uploadedfile import TemporaryUploadedFile
from django.test import TestCase
from django.urls import reverse
-from ..utils import _get_pdf_collection_type
-
from .. import services
+from ..utils import _get_pdf_collection_type
def test_detect_snapshotted_pdf_collection():
@@ -25,7 +27,9 @@ def test_detect_snapshotted_pdf_collection():
class PDFFileUploadTestCase(TestCase):
def setUp(self):
self.url = reverse("resources:create_resource")
- self.test_file_path = "resources/tests/testdata/test_small_file.pdf"
+ self.test_file_path = Path(
+ settings.BASE_DIR / "pyblackbird_cc" / "resources/tests/testdata/test_small_file.pdf"
+ )
# Create a test user
self.email = "testuser@example.com"
diff --git a/pyblackbird_cc/resources/tests/test_views.py b/pyblackbird_cc/resources/tests/test_views.py
index e5025a5..e85dd9f 100644
--- a/pyblackbird_cc/resources/tests/test_views.py
+++ b/pyblackbird_cc/resources/tests/test_views.py
@@ -1,6 +1,8 @@
import unittest
+from pathlib import Path
import pytest
+from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from django.core.files.uploadedfile import SimpleUploadedFile
@@ -32,21 +34,25 @@ def test_create_resource_view(client):
@pytest.mark.django_db
def test_create_resource_has_form(client):
User = get_user_model()
- user = User.objects.create_user(email='testuser@example.com', password='12345')
- client.login(email='testuser@example.com', password='12345')
+ user = User.objects.create_user(email="testuser@example.com", password="12345")
+ client.login(email="testuser@example.com", password="12345")
url = reverse("resources:create_resource")
response = client.get(url)
assert response.status_code == 200
- assert 'form' in response.context
- assert isinstance(response.context['form'], ResourceCreateForm)
+ assert "form" in response.context
+ assert isinstance(response.context["form"], ResourceCreateForm)
class PDFFileUploadTestCase(TestCase):
def setUp(self):
self.url = reverse("resources:create_resource")
- self.two_page_pdf = "resources/tests/testdata/two_page.pdf"
- self.seven_page_pdf = "resources/tests/testdata/seven_page.pdf"
+ self.two_page_pdf = Path(
+ settings.BASE_DIR / "pyblackbird_cc" / "resources/tests/testdata/two_page.pdf"
+ )
+ self.seven_page_pdf = Path(
+ settings.BASE_DIR / "pyblackbird_cc" / "resources/tests/testdata/seven_page.pdf"
+ )
# Create a test user
self.email = "testuser@example.com"
diff --git a/pyblackbird_cc/templates/account/signup.html b/pyblackbird_cc/templates/account/signup.html
new file mode 100644
index 0000000..9dd81fd
--- /dev/null
+++ b/pyblackbird_cc/templates/account/signup.html
@@ -0,0 +1,37 @@
+ {% extends "account/base_entrance.html" %}
+ {% load allauth i18n %}
+ {% block head_title %}
+ {% trans "Signup" %}
+ {% endblock head_title %}
+ {% block content %}
+ {% element h1 %}
+ {% trans "Sign Up" %}
+ <p>There are lots of benefits to signing up!</p>
+ {% endelement %}
+ {% setvar link %}
+ <a href="{{ login_url }}">
+ {% endsetvar %}
+ {% setvar end_link %}
+ </a>
+ {% endsetvar %}
+ <p>{% blocktranslate %}Already have an account? Then please {{ link }}sign in{{ end_link }}.{% endblocktranslate %}</p>
+ {% if not SOCIALACCOUNT_ONLY %}
+ {% url 'account_signup' as action_url %}
+ {% element form form=form method="post" action=action_url tags="entrance,signup" %}
+ {% slot body %}
+ {% csrf_token %}
+ {% element fields form=form unlabeled=True %}
+ {% endelement %}
+ {{ redirect_field }}
+ {% endslot %}
+ {% slot actions %}
+ {% element button tags="prominent,signup" type="submit" %}
+ {% trans "Sign Up" %}
+ {% endelement %}
+ {% endslot %}
+ {% endelement %}
+ {% endif %}
+ {% if SOCIALACCOUNT_ENABLED %}
+ {% include "socialaccount/snippets/login.html" with page_layout="entrance" %}
+ {% endif %}
+ {% endblock content %}