Skip to content

Commit

Permalink
feat!: Upgrade from Django 2.2 to 3.2 (#1316)
Browse files Browse the repository at this point in the history
* wip: upgrade to Django 3.2

* add foundation scss

* Merge branch 'master' into upgrade-django

* update libsass

* patch ci to use upgrade-django branches

* fix migrations tests

* update selenium_test_case

* remove django-foundation-statics
  • Loading branch information
razvan-pro authored Mar 15, 2022
1 parent 8b58260 commit e09c1eb
Show file tree
Hide file tree
Showing 53 changed files with 10,357 additions and 697 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
pip install pipenv
pip install pytest-cov
pipenv install --dev --system
pip install -U "git+https://github.com/ocadotechnology/codeforlife-portal@upgrade-django#egg=cfl-common&subdirectory=cfl_common" # TODO remove after Django upgrade
pip install -U "git+https://github.com/ocadotechnology/codeforlife-portal@upgrade-django#egg=codeforlife-portal" # TODO remove after Django upgrade
pip install -U "git+https://github.com/ocadotechnology/aimmo@upgrade-django#egg=aimmo" # TODO remove after Django upgrade
- name: Collect static
run: python example_project/manage.py collectstatic --noinput
- name: Run tests
Expand Down
11 changes: 6 additions & 5 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ verify_ssl = true
name = "pypi"

[packages]
django-autoconfig = { git = 'https://github.com/ocadotechnology/django-autoconfig.git', ref = 'master' }
django-autoconfig = { git = 'https://github.com/ocadotechnology/django-autoconfig.git', ref = 'upgrade-django' }
rapid-router = {editable = true, path = "."}

[dev-packages]
django-selenium-clean = "==0.3.2"
django-test-migrations = "==1.0.0"
django-selenium-clean = "==0.3.3"
django-test-migrations = "==1.2.0"
selenium = "==3.141.0"
pytest-django = "==4.1.0"
pytest-django = "==4.5.2"
pytest = "==6.*"
codeforlife-portal = "*"
# TODO uncomment after Django upgrade
# codeforlife-portal = "*"

[requires]
python_version = "3.7"
702 changes: 61 additions & 641 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions game/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"game-scss": {
"source_filenames": ("game/sass/game.scss",),
"output_filename": "game.css",
}
},
},
"CSS_COMPRESSOR": None,
},
Expand All @@ -34,7 +34,6 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"django_js_reverse",
"foundation_scss",
"rest_framework",
],
"LANGUAGES": [("lol-us", "Localisation")],
Expand All @@ -54,6 +53,7 @@
}
],
"USE_TZ": True,
"DEFAULT_AUTO_FIELD": "django.db.models.AutoField",
}

SETTINGS.update(CSP_CONFIG)
6 changes: 6 additions & 0 deletions game/end_to_end_tests/base_game_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from common.tests.utils.organisation import create_organisation_directly
from common.tests.utils.student import create_school_student_directly
from common.tests.utils.teacher import signup_teacher_directly
from django.core.management import call_command
from django.urls import reverse
from portal.tests.pageObjects.portal.home_page import HomePage

Expand Down Expand Up @@ -217,6 +218,11 @@ def login_once(self):

return BaseGameTest.user_profile

@classmethod
def setUpClass(cls):
super().setUpClass()
call_command("collectstatic", "--noinput")

@classmethod
def tearDownClass(cls):
super(BaseGameTest, cls).tearDownClass()
Expand Down
40 changes: 3 additions & 37 deletions game/end_to_end_tests/selenium_test_case.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,12 @@
"""
This SeleniumTestCase is copied over from django-selenium-clean==0.3.2
Patch SeleniumTestCase from django-selenium-clean package.
Instead of inheriting from StaticLiveServerTestCase, we inherit from LiveServerTestCase.
This solves a bug introduced when upgrading to Django 1.11,
see more information here: https://github.com/jazzband/django-pipeline/issues/593
"""

from django.conf import settings
from django.contrib.staticfiles.testing import LiveServerTestCase
from django_selenium_clean import SeleniumWrapper, PageElement
from django.core.management import call_command
from django_selenium_clean import SeleniumTestCase


class SeleniumTestCase(LiveServerTestCase):
@classmethod
def setUpClass(cls):
# this line is not part of django-selenium-clean
call_command("collectstatic", "--noinput")

super(SeleniumTestCase, cls).setUpClass()
cls.selenium = SeleniumWrapper()
PageElement.selenium = cls.selenium

# Normally we would just do something like
# selenium.live_server_url = self.live_server_url
# However, there is no "self" at this time, so we
# essentially duplicate the code from the definition of
# the LiveServerTestCase.live_server_url property.
cls.selenium.live_server_url = "http://%s:%s" % (
cls.server_thread.host,
cls.server_thread.port,
)

@classmethod
def tearDownClass(cls):

cls.selenium.quit()
PageElement.selenium = None
super(SeleniumTestCase, cls).tearDownClass()

def __call__(self, result=None):
if hasattr(self, "selenium"):
for width in getattr(settings, "SELENIUM_WIDTHS", [1624]):
self.selenium.set_window_size(width, 1024)
return super(SeleniumTestCase, self).__call__(result)
SeleniumTestCase.__bases__ = (LiveServerTestCase,)
45 changes: 45 additions & 0 deletions game/static/game/sass/foundation.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@charset "UTF-8";
// Foundation by ZURB
// foundation.zurb.com
// Licensed under MIT Open Source

// Make sure the charset is set appropriately

// Behold, here are all the Foundation components.
@import "foundation/components/grid";
@import "foundation/components/accordion";
@import "foundation/components/alert-boxes";
@import "foundation/components/block-grid";
@import "foundation/components/breadcrumbs";
@import "foundation/components/button-groups";
@import "foundation/components/buttons";
@import "foundation/components/clearing";
@import "foundation/components/dropdown";
@import "foundation/components/dropdown-buttons";
@import "foundation/components/flex-video";
@import "foundation/components/forms";
@import "foundation/components/icon-bar";
@import "foundation/components/inline-lists";
@import "foundation/components/joyride";
@import "foundation/components/keystrokes";
@import "foundation/components/labels";
@import "foundation/components/magellan";
@import "foundation/components/orbit";
@import "foundation/components/pagination";
@import "foundation/components/panels";
@import "foundation/components/pricing-tables";
@import "foundation/components/progress-bars";
@import "foundation/components/range-slider";
@import "foundation/components/reveal";
@import "foundation/components/side-nav";
@import "foundation/components/split-buttons";
@import "foundation/components/sub-nav";
@import "foundation/components/switches";
@import "foundation/components/tables";
@import "foundation/components/tabs";
@import "foundation/components/thumbs";
@import "foundation/components/tooltips";
@import "foundation/components/top-bar";
@import "foundation/components/type";
@import "foundation/components/offcanvas";
@import "foundation/components/visibility";
102 changes: 102 additions & 0 deletions game/static/game/sass/foundation/_functions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Foundation by ZURB
// foundation.zurb.com
// Licensed under MIT Open Source

// This is the default html and body font-size for the base rem value.
$rem-base: 16px !default;

// IMPORT ONCE
// We use this to prevent styles from being loaded multiple times for compenents that rely on other components.
$modules: () !default;
@mixin exports($name) {
$module_index: index($modules, $name);
@if (($module_index == null) or ($module_index == false)) {
$modules: append($modules, $name);
@content;
}
}

//
// @functions
//


// RANGES
// We use these functions to define ranges for various things, like media queries.
@function lower-bound($range){
@if length($range) <= 0 {
@return 0;
}
@return nth($range,1);
}

@function upper-bound($range) {
@if length($range) < 2 {
@return 999999999999;
}
@return nth($range, 2);
}

// STRIP UNIT
// It strips the unit of measure and returns it
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}

// CONVERT TO REM
@function convert-to-rem($value, $base-value: $rem-base) {
$value: strip-unit($value) / strip-unit($base-value) * 1rem;
@if ($value == 0rem) { $value: 0; } // Turn 0rem into 0
@return $value;
}

@function data($attr) {
@if $namespace {
@return '[data-' + $namespace + '-' + $attr + ']';
}

@return '[data-' + $attr + ']';
}

// REM CALC

// New Syntax, allows to optionally calculate on a different base value to counter compounding effect of rem's.
// Call with 1, 2, 3 or 4 parameters, 'px' is not required but supported:
//
// rem-calc(10 20 30px 40);
//
// Space delimited, if you want to delimit using comma's, wrap it in another pair of brackets
//
// rem-calc((10, 20, 30, 40px));
//
// Optionally call with a different base (eg: 8px) to calculate rem.
//
// rem-calc(16px 32px 48px, 8px);
//
// If you require to comma separate your list
//
// rem-calc((16px, 32px, 48), 8px);

@function rem-calc($values, $base-value: $rem-base) {
$max: length($values);

@if $max == 1 { @return convert-to-rem(nth($values, 1), $base-value); }

$remValues: ();
@for $i from 1 through $max {
$remValues: append($remValues, convert-to-rem(nth($values, $i), $base-value));
}
@return $remValues;
}

// OLD EM CALC
// Deprecated: We'll drop support for this in 5.1.0, use rem-calc()
@function emCalc($values){
@return rem-calc($values);
}

// OLD EM CALC
// Deprecated: We'll drop support for this in 5.1.0, use rem-calc()
@function em-calc($values){
@return rem-calc($values);
}
Loading

0 comments on commit e09c1eb

Please sign in to comment.