author
int64 658
755k
| date
stringlengths 19
19
| timezone
int64 -46,800
43.2k
| hash
stringlengths 40
40
| message
stringlengths 5
490
| mods
list | language
stringclasses 20
values | license
stringclasses 3
values | repo
stringlengths 5
68
| original_message
stringlengths 12
491
|
---|---|---|---|---|---|---|---|---|---|
701,855 |
07.11.2017 14:04:11
| -46,800 |
b31add9b02656cf0d01b596802be6c72257754db
|
Refactoring - functional decomposition of TextBoxDrawer
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/utils/TextBoxDrawer.py",
"new_path": "csunplugged/utils/TextBoxDrawer.py",
"diff": "@@ -9,6 +9,10 @@ from bidi.algorithm import get_display\nfrom uniseg.linebreak import line_break_units\nimport arabic_reshaper\nimport math\n+from utils.errors.TextBoxDrawerErrors import (\n+ MissingSVGFile,\n+ TextBoxNotFoundInSVG\n+)\nDEFAULT_FONT = \"static/fonts/NotoSans-Regular.ttf\"\nDEFAULT_FONT_OVERRIDES = {\n@@ -70,7 +74,10 @@ class TextBoxDrawer(object):\ndef load_svg(self, svg_path):\n\"\"\"Load SVG element tree.\"\"\"\n+ try:\nreturn ET.parse(svg_path).getroot()\n+ except OSError:\n+ raise MissingSVGFile(svg_path)\ndef get_dimension_ratios(self):\n\"\"\"Get ratios between SVG and image coordinate spaces.\n@@ -94,12 +101,18 @@ class TextBoxDrawer(object):\nTextBox object\n\"\"\"\ntext_layer = self.svg.find('{http://www.w3.org/2000/svg}g[@id=\"TEXT\"]')\n+\n+ try:\ntext_elem = text_layer.find('{{http://www.w3.org/2000/svg}}text[@id=\"{}\"]'.format(box_id))\n- if text_elem is not None:\nbox_elem = text_elem.getprevious()\n- else:\n+ assert box_elem is not None\n+ except:\n+ try:\nbox_elem = text_layer.find('{{http://www.w3.org/2000/svg}}rect[@id=\"{}\"]'.format(box_id))\ntext_elem = box_elem.getnext()\n+ assert text_elem is not None\n+ except:\n+ raise TextBoxNotFoundInSVG(box_id)\ntspan_element = text_elem.find('{http://www.w3.org/2000/svg}tspan')\nif tspan_element is not None:\n@@ -196,30 +209,7 @@ class TextBoxDrawer(object):\nreturn DEFAULT_FONT_OVERRIDES[language]\nreturn DEFAULT_FONT\n- def write_text_box_object(self, text_box, text, font_path=None,\n- font_size=None, horiz_just='left', vert_just='top',\n- line_spacing=4, color=None):\n- \"\"\"Write text into text_box by modifying line breaks and font size as required.\n-\n- Args:\n- text_box: TextBox object\n- text: (str) text to write\n- font_path: (str) path to font .ttf file. This parameter is checked\n- first, followed by an attempt to match the font from the SVG,\n- and then a fallback language\n- font_size: (int) target font size, may be reduced to fit if required.\n- This parameter is checked first, falling back to the original\n- font size from the SVG\n- horiz_just: (str) left, center, right or justify\n- vert_just: (str) top, center, bottom\n- line_spacing: (int) number of pixels between text lines\n- color: (RGB 3-tuple or HEX string) text color. This parameter is\n- checked first, falling back to the original color from the SVG\n- \"\"\"\n- if get_language() == 'ar':\n- text = arabic_reshaper.reshape(text)\n-\n- font_path = font_path or text_box.font_path\n+ def fallback_font_if_required(self, font_path, text):\nif font_path:\nfont_name = os.path.splitext(os.path.basename(font_path))[0]\nmax_ord_allowed = FONT_MAX_ORD[font_name]\n@@ -229,10 +219,13 @@ class TextBoxDrawer(object):\nfont_path = self.get_default_font()\nelse:\nfont_path = self.get_default_font()\n+ return font_path\n- font_size = font_size or text_box.font_size or DEFAULT_FONT_SIZE\n- color = color or text_box.color or DEFAULT_COLOR\n+ def get_font_y_offset(self, font):\n+ (_, _), (_, offset_y) = font.font.getsize(\"A\")\n+ return offset_y\n+ def fit_text(self, text, box_width, box_height, font_path, font_size, line_spacing):\nfont_size_is_ok = False\nwhile not font_size_is_ok:\nfont = self.get_font(font_path, font_size)\n@@ -242,7 +235,7 @@ class TextBoxDrawer(object):\nfor unit in breakable_units:\npotential_line = line + unit\nsize = self.get_text_width(font, potential_line)\n- if size >= text_box.width:\n+ if size >= box_width:\nlines.append(line)\nline = unit\nelse:\n@@ -256,16 +249,56 @@ class TextBoxDrawer(object):\nspacing=line_spacing)\n# Reduce text_height by offset at top\n- (_, _), (_, offset_y) = font.font.getsize(text)\n- text_height -= offset_y\n+ text_height -= self.get_font_y_offset(font)\n- if text_height <= text_box.height:\n+ if text_height <= box_height:\nfont_size_is_ok = True\nelse:\n# Decrease font size exponentially, and try again\nfont_size = max(int(0.9 * font_size), 1)\n+ return font_size, lines, text_width, text_height\n+\n+\n+ def write_text_box_object(self, text_box, text, font_path=None,\n+ font_size=None, horiz_just='left', vert_just='top',\n+ line_spacing=4, color=None):\n+ \"\"\"Write text into text_box by modifying line breaks and font size as required.\n+\n+ Args:\n+ text_box: TextBox object\n+ text: (str) text to write\n+ font_path: (str) path to font .ttf file. This parameter is checked\n+ first, followed by an attempt to match the font from the SVG,\n+ and then a fallback language\n+ font_size: (int) target font size, may be reduced to fit if required.\n+ This parameter is checked first, falling back to the original\n+ font size from the SVG\n+ horiz_just: (str) left, center, right or justify\n+ vert_just: (str) top, center, bottom\n+ line_spacing: (int) number of pixels between text lines\n+ color: (RGB 3-tuple or HEX string) text color. This parameter is\n+ checked first, falling back to the original color from the SVG\n+ \"\"\"\n+ if get_language() == 'ar':\n+ text = arabic_reshaper.reshape(text)\n+\n+ font_path = font_path or text_box.font_path\n+ font_path = self.fallback_font_if_required(font_path, text)\n+ font_size = font_size or text_box.font_size or DEFAULT_FONT_SIZE\n+ font_size, lines, text_width, text_height = self.fit_text(\n+ text,\n+ text_box.width,\n+ text_box.height,\n+ font_path,\n+ font_size,\n+ line_spacing\n+ )\n+\n+ font = self.get_font(font_path, font_size)\ntext = '\\n'.join(lines)\n+ color = color or text_box.color or DEFAULT_COLOR\n+\nif get_language_bidi():\n# Get RTL text\ntext = get_display(text)\n@@ -290,7 +323,7 @@ class TextBoxDrawer(object):\nx = (text_box.width - text_width)\n# Remove offset from top line, to mimic AI textbox behavior\n- y -= offset_y\n+ y -= self.get_font_y_offset(font)\nif text_box.angle != 0:\ntext_img = Image.new(\"RGBA\", (int(text_box.width), int(text_box.height)))\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Refactoring - functional decomposition of TextBoxDrawer
|
701,855 |
07.11.2017 14:05:25
| -46,800 |
8e8c1b326c71ad1e2810bc806d443bf3e9e0a8ed
|
Add custom exceptions for TextBoxDrawer
This is a skeleton for now, with docstrings etc. to follow
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/utils/errors/TextBoxDrawerErrors.py",
"diff": "+class TextBoxDrawerError(Exception):\n+ pass\n+\n+class MissingSVGFile(TextBoxDrawerError):\n+ pass\n+\n+class TextBoxNotFoundInSVG(TextBoxDrawerError):\n+ pass\n+\n+class MissingSVGViewBox(TextBoxDrawerError):\n+ pass\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add custom exceptions for TextBoxDrawer
This is a skeleton for now, with docstrings etc. to follow
|
701,855 |
07.11.2017 14:06:55
| -46,800 |
3f3e815ad238cf669cf6f4cf42277101e1916483
|
Add initial unit tests for TextBoxDrawer
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/text_box_drawer/__init__.py",
"diff": "+\"\"\"Module for tests of TextBoxDrawer.\"\"\"\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/text_box_drawer/test_text_box_drawer.py",
"diff": "+\"\"\"Test class for TextBoxDrawer.\"\"\"\n+\n+from django.test import SimpleTestCase\n+from utils.TextBoxDrawer import TextBoxDrawer, TextBox, DEFAULT_FONT\n+from PIL import ImageFont, Image, ImageDraw\n+from lxml import etree as ET\n+import os\n+import math\n+from utils.errors.TextBoxDrawerErrors import (\n+ MissingSVGFile,\n+ TextBoxNotFoundInSVG\n+)\n+\n+BASE_PATH = \"tests/utils/text_box_drawer\"\n+\n+class TextBoxDrawerTest(SimpleTestCase):\n+\n+ def test_initialisation_basic_svg(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ image = Image.new(\"RGB\", (2000, 4000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ self.assertIsInstance(tbd.svg, ET._Element)\n+ self.assertAlmostEqual(tbd.width_ratio, 2)\n+ self.assertAlmostEqual(tbd.height_ratio, 4)\n+\n+ def test_initialisation_missing_svg(self):\n+ svg = os.path.join(BASE_PATH, \"missing.svg\")\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ with self.assertRaises(MissingSVGFile):\n+ tbd = TextBoxDrawer(image, None, svg)\n+\n+ def test_get_box_core(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ # In PNG Space, x is *2, and y is *4 from SVG Space\n+ image = Image.new(\"RGB\", (2000, 4000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ box = tbd.get_box(\"box1\")\n+\n+ self.assertIsInstance(box, TextBox)\n+ self.assertIsInstance(box.vertices, list)\n+ self.assertEqual(4, len(box.vertices))\n+ x, y = box.vertices[0]\n+ # SVG x=100, *2 to convert into PNG space\n+ self.assertAlmostEqual(2 * 100, x)\n+ # SVG y=200, *4 to convert into PNG space\n+ self.assertAlmostEqual(4 * 200, y)\n+ # SVG width=50, *2 to convert into PNG space\n+ self.assertAlmostEqual(2 * 50.0, box.width)\n+ # SVG height=75, *4 to convert into PNG space\n+ self.assertAlmostEqual(4 * 75.0, box.height)\n+ self.assertEqual(\"#006838\", box.color)\n+ self.assertEqual(\"static/fonts/PatrickHand-Regular.ttf\", box.font_path)\n+ # SVG font size is 48px, converted into PNG space\n+ self.assertEqual(4 * 48, box.font_size)\n+ self.assertIsInstance(box.font_size, int)\n+ self.assertEqual(0, box.angle)\n+\n+ def test_get_box_id_on_rect_element(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ image = Image.new(\"RGB\", (2000, 4000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ box = tbd.get_box(\"onrectangle\")\n+\n+ def test_get_box_invalid_id(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ image = Image.new(\"RGB\", (2000, 4000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ with self.assertRaises(TextBoxNotFoundInSVG):\n+ box = tbd.get_box(\"invalid\")\n+\n+ def text_get_box_with_tspan(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ box = tbd.get_box(\"withtspan\")\n+ self.assertEqual(\"#414042\", box.color)\n+ self.assertEqual(\"static/fonts/PatrickHand-Regular.ttf\", box.font_path)\n+ self.assertEqual(48, box.font_size)\n+ self.assertIsInstance(box.font_size, int)\n+\n+ def text_get_box_without_style(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ box = tbd.get_box(\"withoutstyle\")\n+ self.assertEqual(None, box.color)\n+ self.assertEqual(None, box.font_path)\n+ self.assertEqual(None, box.font_size)\n+\n+ def test_get_box_rotated(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ box = tbd.get_box(\"rotated\")\n+ self.assertAlmostEqual(math.radians(45.0), box.angle, places=3)\n+\n+ # Check location of bottom left corner\n+ bottomleft_x, bottomleft_y = box.vertices[3]\n+ self.assertAlmostEqual(bottomleft_x, 1/math.sqrt(2) * box.width, places=1)\n+ self.assertAlmostEqual(bottomleft_y, 1/math.sqrt(2) * box.height, places=1)\n+\n+ def test_fallback_font_if_required_valid_font(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ font_path = \"static/fonts/PatrickHand-Regular.ttf\"\n+ font = tbd.fallback_font_if_required(font_path, \"abc\")\n+ self.assertEqual(font_path, font)\n+\n+ def test_fallback_font_if_required_ordinal_too_high(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ font_path = \"static/fonts/PatrickHand-Regular.ttf\"\n+ new_font_path = tbd.fallback_font_if_required(font_path, chr(300))\n+ self.assertNotEqual(font_path, new_font_path)\n+ self.assertEqual(DEFAULT_FONT, new_font_path)\n+\n+ def test_fallback_font_none_given(self):\n+ svg = os.path.join(BASE_PATH, \"basic.svg\")\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ tbd = TextBoxDrawer(image, None, svg)\n+ font_path = tbd.fallback_font_if_required(None, \"abc\")\n+ self.assertEqual(DEFAULT_FONT, font_path)\n+\n+ # def test_fit_text_one_line(self):\n+ #\n+ # def test_fit_text_multiline(self):\n+ #\n+ # def test_fit_text_decrease_fontsize(self):\n+ #\n+ # def test_write_text_box_object_basic(self):\n+ #\n+ # def test_write_text_box_object_rotated(self):\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add initial unit tests for TextBoxDrawer
|
701,855 |
07.11.2017 16:02:18
| -46,800 |
3a05bca8903bd763b7fe5af8d5ce0f8709ba52a6
|
Style fixes and general tidyups of TextBoxDrawer
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/utils/TextBoxDrawer.py",
"new_path": "csunplugged/utils/TextBoxDrawer.py",
"diff": "@@ -31,7 +31,7 @@ FONT_MAX_ORD = {\nclass TextBox(object):\n\"\"\"Class to store position/dimensions of a text box.\"\"\"\n- def __init__(self, vertices, width, height, color, font_path, font_size, angle):\n+ def __init__(self, vertices, width, height, color=None, font_path=None, font_size=None, angle=0):\n\"\"\"Initialise TextBox.\nArgs:\n@@ -42,7 +42,7 @@ class TextBox(object):\ncolor: (RGB 3-tuple or HEX string) text color, if given in SVG\nfont_path: (str) path to font, if given in SVG\nfont_size: (int) font size, if given in SVG\n- angle: (float) rotation angle of textbox, anti-clockwise\n+ angle: (float) rotation angle of textbox, anti-clockwise, in radians\n\"\"\"\nself.vertices = vertices\nself.width = width\n@@ -59,21 +59,35 @@ class TextBoxDrawer(object):\nText_box layout is defined by elements in an exported SVG.\n\"\"\"\n- def __init__(self, image, draw, svg_path):\n+ def __init__(self, image, draw, svg_path=None):\n\"\"\"Initialise TextBoxDrawer.\nArgs:\nimage: PIL Image object\ndraw: PIL ImageDraw object\n- svg_path: (str) path to SVG file for text box layout\n+ svg_path: (str) path to SVG file for text box layout. If None,\n+ an instantiated TextBox objects will have to be provided for\n+ each call to write_text_box\n\"\"\"\nself.image = image\nself.draw = draw\n+ if svg_path:\nself.svg = self.load_svg(svg_path)\nself.width_ratio, self.height_ratio = self.get_dimension_ratios()\n- def load_svg(self, svg_path):\n- \"\"\"Load SVG element tree.\"\"\"\n+ @staticmethod\n+ def load_svg(svg_path):\n+ \"\"\"Load SVG element tree.\n+\n+ Args:\n+ svg_path: (str) path to svg file\n+\n+ Returns:\n+ (ElementTree) root node of SVG\n+\n+ Raises:\n+ MissingSVGFile: SVG file could not be found at given path\n+ \"\"\"\ntry:\nreturn ET.parse(svg_path).getroot()\nexcept OSError:\n@@ -99,6 +113,9 @@ class TextBoxDrawer(object):\nof a rectangle element in the SVG\nReturns:\nTextBox object\n+\n+ Raises:\n+ TextBoxNotFoundInSVG: No textbox could be found with the given id\n\"\"\"\ntext_layer = self.svg.find('{http://www.w3.org/2000/svg}g[@id=\"TEXT\"]')\n@@ -106,12 +123,12 @@ class TextBoxDrawer(object):\ntext_elem = text_layer.find('{{http://www.w3.org/2000/svg}}text[@id=\"{}\"]'.format(box_id))\nbox_elem = text_elem.getprevious()\nassert box_elem is not None\n- except:\n+ except Exception:\ntry:\nbox_elem = text_layer.find('{{http://www.w3.org/2000/svg}}rect[@id=\"{}\"]'.format(box_id))\ntext_elem = box_elem.getnext()\nassert text_elem is not None\n- except:\n+ except Exception:\nraise TextBoxNotFoundInSVG(box_id)\ntspan_element = text_elem.find('{http://www.w3.org/2000/svg}tspan')\n@@ -169,18 +186,23 @@ class TextBoxDrawer(object):\nangle=angle,\n)\n- def write_text_box(self, box_id, string, **kwargs):\n+ def write_text_box(self, box, string, **kwargs):\n\"\"\"Write text onto image in the space defined by the given textbox.\nArgs:\n- box_id: (str) identifier of the textbox, matching the 'id' attribute\n- of a rectangle element in the SVG\n+ box: (str or TextBox) either the id of a text element in the SVG,\n+ or an instantiated TextBox object defining the area to fill\n+ with text. If an svg path was not given to __init__, this must\n+ be a TextBox object.\nstring: (str) text to write\n\"\"\"\n- box = self.get_box(box_id)\n- self.write_text_box_object(box, string, **kwargs)\n+ if isinstance(box, str):\n+ # We've been given a box id- retrieve from SVG\n+ box = self.get_box(box)\n+ self.write_text_box_object(self.image, self.draw, box, string, **kwargs)\n- def get_text_width(self, font, text):\n+ @staticmethod\n+ def get_text_width(font, text):\n\"\"\"Get width of given text in given font.\nArgs:\n@@ -189,7 +211,8 @@ class TextBoxDrawer(object):\n\"\"\"\nreturn font.getsize(text)[0]\n- def get_font_height(self, font):\n+ @staticmethod\n+ def get_font_height(font):\n\"\"\"Get height of given font.\nArgs:\n@@ -198,43 +221,80 @@ class TextBoxDrawer(object):\nascent, descent = font.getmetrics()\nreturn ascent + descent\n- def get_font(self, font_path, font_size):\n+ @staticmethod\n+ def get_font(font_path, font_size):\n\"\"\"Get ImageFont instance for given font path/size.\"\"\"\nreturn ImageFont.truetype(font_path, font_size)\n- def get_default_font(self):\n+ @staticmethod\n+ def get_default_font():\n\"\"\"Get default font for the current language.\"\"\"\nlanguage = get_language()\nif language in DEFAULT_FONT_OVERRIDES:\nreturn DEFAULT_FONT_OVERRIDES[language]\nreturn DEFAULT_FONT\n- def fallback_font_if_required(self, font_path, text):\n+ @classmethod\n+ def fallback_font_if_required(cls, font_path, text):\n+ \"\"\"Check if the given text can be rendered in the requested font.\n+\n+ Returns:\n+ (str) <font_path> if all chars can be rendered, otherwise a default.\n+ \"\"\"\nif font_path:\nfont_name = os.path.splitext(os.path.basename(font_path))[0]\nmax_ord_allowed = FONT_MAX_ORD[font_name]\nmax_ord = ord(max(text, key=ord))\nif max_ord > max_ord_allowed:\n# Text contains codepoints without a glyph in requested font\n- font_path = self.get_default_font()\n+ font_path = cls.get_default_font()\nelse:\n- font_path = self.get_default_font()\n+ font_path = cls.get_default_font()\nreturn font_path\n- def get_font_y_offset(self, font):\n+ @staticmethod\n+ def get_font_y_offset(font):\n+ \"\"\"Get vertical offset of a given font.\n+\n+ When rendering a line of text in a given font, there is a vertical\n+ offset between the given height, and the top of the character.\n+ See https://stackoverflow.com/questions/43060479/ for details.\n+\n+ Args:\n+ font: (ImageFont)\n+ \"\"\"\n(_, _), (_, offset_y) = font.font.getsize(\"A\")\nreturn offset_y\n- def fit_text(self, text, box_width, box_height, font_path, font_size, line_spacing):\n+ @classmethod\n+ def fit_text(cls, text, box_width, box_height, font_path, font_size, line_spacing):\n+ \"\"\"Fit given text into given dimensons by modifying line breaks and font size.\n+\n+ Args:\n+ text: (str) text to fit\n+ box_width: (int) width of available area\n+ box_height: (int) height of available area\n+ font_path: (str) path to font file\n+ font_size: (int) size of font, in pixels\n+ line_spacing: (int) number of pixels spacing between lines\n+\n+ Returns:\n+ 4-tuple: (\n+ modified font size (int),\n+ lines of text (list of strings),\n+ width of fitted text (int),\n+ height of fitted text (int)\n+ )\n+ \"\"\"\nfont_size_is_ok = False\nwhile not font_size_is_ok:\n- font = self.get_font(font_path, font_size)\n+ font = cls.get_font(font_path, font_size)\nlines = []\nline = \"\"\nbreakable_units = line_break_units(text)\nfor unit in breakable_units:\npotential_line = line + unit\n- size = self.get_text_width(font, potential_line)\n+ size = cls.get_text_width(font, potential_line)\nif size >= box_width:\nlines.append(line)\nline = unit\n@@ -243,13 +303,17 @@ class TextBoxDrawer(object):\nif line:\nlines.append(line)\n- text_width, text_height = self.draw.multiline_textsize(\n+\n+ # Dummy image draw because multiline_textsize isn't a @classmethod\n+ dummy_img = Image.new(\"1\", (1, 1))\n+ dummy_draw = ImageDraw.Draw(dummy_img)\n+ text_width, text_height = dummy_draw.multiline_textsize(\n'\\n'.join(lines),\nfont=font,\nspacing=line_spacing)\n# Reduce text_height by offset at top\n- text_height -= self.get_font_y_offset(font)\n+ text_height -= cls.get_font_y_offset(font)\nif text_height <= box_height:\nfont_size_is_ok = True\n@@ -259,14 +323,16 @@ class TextBoxDrawer(object):\nreturn font_size, lines, text_width, text_height\n-\n- def write_text_box_object(self, text_box, text, font_path=None,\n+ @classmethod\n+ def write_text_box_object(cls, image, draw, text_box, text, font_path=None,\nfont_size=None, horiz_just='left', vert_just='top',\nline_spacing=4, color=None):\n\"\"\"Write text into text_box by modifying line breaks and font size as required.\nArgs:\n- text_box: TextBox object\n+ image: (Image.Image) Base resource image\n+ draw: (ImageDraw.Draw) ImageDraw object for the resource image\n+ text_box: (TextBox) object containing textbox properties\ntext: (str) text to write\nfont_path: (str) path to font .ttf file. This parameter is checked\nfirst, followed by an attempt to match the font from the SVG,\n@@ -284,9 +350,9 @@ class TextBoxDrawer(object):\ntext = arabic_reshaper.reshape(text)\nfont_path = font_path or text_box.font_path\n- font_path = self.fallback_font_if_required(font_path, text)\n+ font_path = cls.fallback_font_if_required(font_path, text)\nfont_size = font_size or text_box.font_size or DEFAULT_FONT_SIZE\n- font_size, lines, text_width, text_height = self.fit_text(\n+ font_size, lines, text_width, text_height = cls.fit_text(\ntext,\ntext_box.width,\ntext_box.height,\n@@ -295,7 +361,7 @@ class TextBoxDrawer(object):\nline_spacing\n)\n- font = self.get_font(font_path, font_size)\n+ font = cls.get_font(font_path, font_size)\ntext = '\\n'.join(lines)\ncolor = color or text_box.color or DEFAULT_COLOR\n@@ -323,7 +389,7 @@ class TextBoxDrawer(object):\nx = (text_box.width - text_width)\n# Remove offset from top line, to mimic AI textbox behavior\n- y -= self.get_font_y_offset(font)\n+ y -= cls.get_font_y_offset(font)\nif text_box.angle != 0:\ntext_img = Image.new(\"RGBA\", (int(text_box.width), int(text_box.height)))\n@@ -340,12 +406,12 @@ class TextBoxDrawer(object):\nvertices_xvals, vertices_yvals = zip(*text_box.vertices)\npx = int(min(vertices_xvals))\npy = int(min(vertices_yvals))\n- self.image.paste(text_img, (px, py), text_img)\n+ image.paste(text_img, (px, py), text_img)\nelse:\ntopleft_x, topleft_y = text_box.vertices[0]\nx += topleft_x\ny += topleft_y\n- self.draw.multiline_text(\n+ draw.multiline_text(\n(x, y),\ntext,\nfill=color,\n@@ -353,9 +419,3 @@ class TextBoxDrawer(object):\nalign=horiz_just,\nspacing=line_spacing\n)\n-\n- def draw_crosshair(self, point):\n- \"\"\"Draw a black crosshair at the specified point.\"\"\"\n- x, y = point\n- self.draw.line([(x - 30, y), (x + 30, y)], fill=(150, 150, 150), width=5)\n- self.draw.line([(x, y - 30), (x, y + 30)], fill=(150, 150, 150), width=5)\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/utils/errors/TextBoxDrawerErrors.py",
"new_path": "csunplugged/utils/errors/TextBoxDrawerErrors.py",
"diff": "+\"\"\"Exceptions relating to the TextBoxDrawer utility class.\"\"\"\n+\n+\nclass TextBoxDrawerError(Exception):\n+ \"\"\"Base exception for TextBoxDrawer errors.\"\"\"\n+\npass\n+\nclass MissingSVGFile(TextBoxDrawerError):\n+ \"\"\"Raised when an SVG file could not be found.\"\"\"\n+\npass\n+\nclass TextBoxNotFoundInSVG(TextBoxDrawerError):\n- pass\n+ \"\"\"Raised when a given textbox id could not be found in the SVG file.\"\"\"\n-class MissingSVGViewBox(TextBoxDrawerError):\npass\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Style fixes and general tidyups of TextBoxDrawer
|
701,855 |
07.11.2017 16:04:59
| -46,800 |
59e32c0ccebb1a03debcdd20e1720dd92b8cde74
|
Add more unit tests to increase coverage of TextBoxDrawer
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/utils/text_box_drawer/test_text_box_drawer.py",
"new_path": "csunplugged/tests/utils/text_box_drawer/test_text_box_drawer.py",
"diff": "@@ -13,6 +13,7 @@ from utils.errors.TextBoxDrawerErrors import (\nBASE_PATH = \"tests/utils/text_box_drawer\"\n+\nclass TextBoxDrawerTest(SimpleTestCase):\ndef test_initialisation_basic_svg(self):\n@@ -27,7 +28,7 @@ class TextBoxDrawerTest(SimpleTestCase):\nsvg = os.path.join(BASE_PATH, \"missing.svg\")\nimage = Image.new(\"RGB\", (1000, 1000))\nwith self.assertRaises(MissingSVGFile):\n- tbd = TextBoxDrawer(image, None, svg)\n+ TextBoxDrawer(image, None, svg)\ndef test_get_box_core(self):\nsvg = os.path.join(BASE_PATH, \"basic.svg\")\n@@ -59,14 +60,14 @@ class TextBoxDrawerTest(SimpleTestCase):\nsvg = os.path.join(BASE_PATH, \"basic.svg\")\nimage = Image.new(\"RGB\", (2000, 4000))\ntbd = TextBoxDrawer(image, None, svg)\n- box = tbd.get_box(\"onrectangle\")\n+ tbd.get_box(\"onrectangle\")\ndef test_get_box_invalid_id(self):\nsvg = os.path.join(BASE_PATH, \"basic.svg\")\nimage = Image.new(\"RGB\", (2000, 4000))\ntbd = TextBoxDrawer(image, None, svg)\nwith self.assertRaises(TextBoxNotFoundInSVG):\n- box = tbd.get_box(\"invalid\")\n+ tbd.get_box(\"invalid\")\ndef text_get_box_with_tspan(self):\nsvg = os.path.join(BASE_PATH, \"basic.svg\")\n@@ -123,12 +124,136 @@ class TextBoxDrawerTest(SimpleTestCase):\nfont_path = tbd.fallback_font_if_required(None, \"abc\")\nself.assertEqual(DEFAULT_FONT, font_path)\n- # def test_fit_text_one_line(self):\n- #\n- # def test_fit_text_multiline(self):\n- #\n- # def test_fit_text_decrease_fontsize(self):\n- #\n- # def test_write_text_box_object_basic(self):\n- #\n- # def test_write_text_box_object_rotated(self):\n+ def test_fit_text_one_line(self):\n+ font_path = \"static/fonts/PatrickHand-Regular.ttf\"\n+ font_size = 50\n+ font = ImageFont.truetype(font_path, font_size)\n+ text = \"This is a string\"\n+ text_width, text_height = font.getsize(text)\n+ new_font_size, lines, new_text_width, new_text_height = TextBoxDrawer.fit_text(\n+ text,\n+ text_width * 2,\n+ text_height * 2,\n+ font_path,\n+ font_size,\n+ 4\n+ )\n+\n+ self.assertEqual(1, len(lines))\n+ self.assertEqual(text, lines[0])\n+ self.assertEqual(font_size, new_font_size)\n+ self.assertIsInstance(new_text_width, int)\n+ self.assertIsInstance(new_text_height, int)\n+\n+ def test_fit_text_multiline(self):\n+ font_path = \"static/fonts/PatrickHand-Regular.ttf\"\n+ font_size = 50\n+ font = ImageFont.truetype(font_path, font_size)\n+ text = \"This is a string\"\n+ text_width, text_height = font.getsize(text)\n+ new_font_size, lines, new_text_width, new_text_height = TextBoxDrawer.fit_text(\n+ text,\n+ text_width * 0.8, # Make box slightly narrower than text, to force 2 lines\n+ text_height * 5,\n+ font_path,\n+ font_size,\n+ 4\n+ )\n+ self.assertEqual(2, len(lines))\n+ self.assertEqual(text, ''.join(lines))\n+ self.assertEqual(font_size, new_font_size)\n+ self.assertIsInstance(new_text_width, int)\n+ self.assertIsInstance(new_text_height, int)\n+\n+ def test_fit_text_decrease_fontsize(self):\n+ font_path = \"static/fonts/PatrickHand-Regular.ttf\"\n+ font_size = 50\n+ font = ImageFont.truetype(font_path, font_size)\n+ text = \"This is a string\"\n+ text_width, text_height = font.getsize(text)\n+ new_font_size, lines, new_text_width, new_text_height = TextBoxDrawer.fit_text(\n+ text,\n+ text_width * 0.8, # Make box slightly narrower than text, to force 2 lines\n+ text_height, # Make box too short to force smaller text\n+ font_path,\n+ font_size,\n+ 4\n+ )\n+ self.assertEqual(text, ''.join(lines))\n+ self.assertTrue(new_font_size < font_size)\n+ self.assertTrue(new_font_size > 1)\n+ self.assertIsInstance(new_text_width, int)\n+ self.assertIsInstance(new_text_height, int)\n+\n+ def test_write_text_box_object_defaults_smoke_test(self):\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ draw = ImageDraw.Draw(image)\n+ vertices = [\n+ (0, 0), (200, 0), (200, 100), (0, 100)\n+ ]\n+ width = 200\n+ height = 100\n+ box = TextBox(vertices, width, height)\n+ TextBoxDrawer.write_text_box_object(\n+ image,\n+ draw,\n+ box,\n+ \"This is a string\",\n+ )\n+\n+ def test_write_text_box_object_justification_smoke_test(self):\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ draw = ImageDraw.Draw(image)\n+ vertices = [\n+ (0, 0), (200, 0), (200, 100), (0, 100)\n+ ]\n+ width = 200\n+ height = 100\n+ box = TextBox(vertices, width, height)\n+ for horiz_just in [\"left\", \"center\", \"right\"]:\n+ for vert_just in [\"top\", \"center\", \"bottom\"]:\n+ TextBoxDrawer.write_text_box_object(\n+ image,\n+ draw,\n+ box,\n+ \"This is a string\",\n+ horiz_just=horiz_just,\n+ vert_just=vert_just,\n+ )\n+\n+ def test_write_text_box_object_params_smoke_test(self):\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ draw = ImageDraw.Draw(image)\n+ vertices = [\n+ (0, 0), (200, 0), (200, 100), (0, 100)\n+ ]\n+ width = 200\n+ height = 100\n+ box = TextBox(vertices, width, height)\n+ TextBoxDrawer.write_text_box_object(\n+ image,\n+ draw,\n+ box,\n+ \"This is a string\",\n+ font_path=\"static/fonts/PatrickHand-Regular\",\n+ font_size=17,\n+ line_spacing=10,\n+ color=\"#013291\"\n+ )\n+\n+ def test_write_text_box_object_rotated_smoke_test(self):\n+ image = Image.new(\"RGB\", (1000, 1000))\n+ draw = ImageDraw.Draw(image)\n+ vertices = [\n+ (0, 200), (0, 0), (100, 0), (100, 200)\n+ ]\n+ width = 200\n+ height = 100\n+ rotation = 90\n+ box = TextBox(vertices, width, height, rotation)\n+ TextBoxDrawer.write_text_box_object(\n+ image,\n+ draw,\n+ box,\n+ \"This is a string\",\n+ )\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add more unit tests to increase coverage of TextBoxDrawer
|
701,855 |
07.11.2017 18:20:45
| -46,800 |
c33be360ee7f5cb92aaa04dd902a99ce8fbedf1b
|
Add designer/developer documentation for dynamic text rendering
|
[
{
"change_type": "MODIFY",
"old_path": "docs/source/developer/resources.rst",
"new_path": "docs/source/developer/resources.rst",
"diff": "@@ -146,3 +146,144 @@ Thumbnail image\n------------------------------------------------------------------------------\nThis image should represent the resource, and be at least 350px high.\n+\n+Dynamic Text Overlay\n+==============================================================================\n+In many cases, resources comprise of a base PNG image with text dynamically overlayed from within the python view, based on a users request.\n+Cases where this is necessary include:\n+\n+- Randomly generated numbers or data\n+- Text, which must be translated into the user's language\n+\n+While the actual text is added dynamically, the layout/colour/font/size of that text on the resource should be determined as part of the design process.\n+To achieve this, we have developed a pipeline to allow designers to define these text fields in Adobe Illustrator, and export them in an SVG format.\n+This information can then be used to dynamically render the required text as closely as possible to the intended design. This process is outlined in more detail below, for both developers and designers.\n+\n+For Designers\n+------------------------------------------------------------------------------\n+The following workflow has been designed for Adobe Illustrator. Currently, other graphics software is not supported.\n+\n+Setting up the document\n+*******************************************************************************\n+ 1. Create a new layer called ``TEXT`` (Anything on this layer will be ignored during the export to PNG)\n+\n+Creating a new dynamic text field\n+*******************************************************************************\n+ 1. Create a new transparent rectangular text box in the ``TEXT`` layer\n+ 2. Add sample text\n+ 3. Set font, font size and colour\n+ 4. Position and rotate text box as required\n+ 5. Expand text box to define the area in which the text will be allowed\n+ 6. Give the text box element a unique identifier\n+\n+ - This is achieved by expanding the ``TEXT`` layer in the layers panel, and double-clicking on the text box element.\n+ - The identifier must contain lowercase letters only.\n+ - The identifier must be unique across all layers.\n+\n+Notes:\n+ - Sample text must be added - do not leave the box empty.\n+ - The colour, font and font size information of the first character in the text will be used.\n+ - While we strive to match the original design as much as possible during rendering, the result is not exact. Ensure there is some padding around all sides of the text box to allow for this.\n+ - Text boxes in shapes other than rectangles are currently not supported.\n+ - During the design process, consider that some languages are written right to left.\n+\n+Export procedure\n+*******************************************************************************\n+Firstly, check that every element in the ``TEXT`` layer has been given a unique, lowercase identifier as outlined above.\n+\n+Next, resize the artboard to fit to artwork bounds\n+\n+ 1. Ensure all layers (including the ``TEXT`` layer) are visible\n+ 2. Click ``Object -> Artboards -> Fit To Artwork Bounds``\n+\n+Now export the base PNG image\n+\n+ 1. Ensure the ``TEXT`` layer is hidden\n+ 2. Export PNG, ensuring that `Use Artboards` is selected\n+\n+Finally, export the SVG file containing the text field information\n+\n+ 1. Ensure all layers (including the ``TEXT`` layer) are visible\n+ 2. Click ``File -> Save As``\n+ 3. Use the same file name (without extension) as was used for the PNG\n+ 4. Choose ``SVG`` as the format, and select ``Use Artboards``\n+ 5. Click ``Save``\n+ 6. In the dropdown for ``CSS Properties``, choose ``Style Attributes``\n+ 7. Click ``OK``\n+\n+\n+For Developers\n+------------------------------------------------------------------------------\n+\n+Rendering text into defined text fields (i.e. defined in an SVG file)\n+*******************************************************************************\n+\n+To dynamically render text onto the resource, use the TextBoxDrawer class\n+\n+.. code-block:: python\n+\n+ from utils.TextBoxDrawer import TextBoxDrawer\n+\n+Load the base PNG image, set it up for editing, and then instantiate a TextBoxDrawer object\n+\n+.. code-block:: python\n+\n+ image = Image.open(\"my_resource.png\")\n+ draw = ImageDraw.Draw(image)\n+ textbox_drawer = TextBoxDrawer(image, draw, svg_path=\"my_resource.svg\")\n+\n+Dynamically populate text fields by calling the ``write_text_box`` function.\n+\n+.. code-block:: python\n+\n+ textbox_drawer.write_text_box(\n+ \"title\",\n+ \"This is some text\",\n+ horiz_just=\"center\",\n+ )\n+\n+Notes:\n+ - Justification information (horizontal and vertical) is not extracted from the original design. The default is top left, but can be overrided using the kwargs ``horiz_just`` and ``vert_just``.\n+ - Colour, font, and font size information is extracted from the original design, but can also be set with kwargs here. If provided, kwargs will take precedence.\n+ - See the docstrings in ``TextBoxDrawer.py`` for more detailed information on the options available.\n+\n+Rendering text without defined text fields (i.e. without an SVG file)\n+*******************************************************************************\n+\n+It is also possible to use this class for dynamically rendering text *without* an SVG file to define the parameters of the text fields.\n+\n+ 1. Initialise TextBoxDrawer without an SVG path\n+ 2. Create an instance of the TextBox class to define the parameters of the text field (this is normally created automatically with the information extracted from the SVG)\n+ 3. Call ``write_text_box`` with the instantiated TextBox object instead of a textbox identifier\n+\n+A simple example:\n+\n+.. code-block:: python\n+\n+ from utils.TextBoxDrawer import TextBoxDrawer, TextBox\n+\n+ image = Image.open(\"my_resource.png\")\n+ draw = ImageDraw.Draw(image)\n+ textbox_drawer = TextBoxDrawer(image, draw)\n+\n+ font_path = \"static/fonts/PatrickHand-Regular.ttf\"\n+ font_size = 40\n+\n+ x, y = 100, 200\n+ width, height = 300, 400\n+\n+ # Vertices clockwise from top left\n+ vertices = [(x, y), (x + width, y), (x + width, y + height), (x, y + height)]\n+\n+ box = TextBox(vertices,\n+ width,\n+ height,\n+ color=\"#ba325b\",\n+ font_path=font_path,\n+ font_size=font_size\n+ )\n+\n+ textbox_drawer.write_text_box(\n+ box,\n+ \"This is some text\"\n+ )\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add designer/developer documentation for dynamic text rendering
|
701,855 |
07.11.2017 18:35:31
| -46,800 |
0c25981e0a8f7f61142574e7cd5c68e74ee47cd9
|
Fix bug in rotated textbox test
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/utils/text_box_drawer/test_text_box_drawer.py",
"new_path": "csunplugged/tests/utils/text_box_drawer/test_text_box_drawer.py",
"diff": "@@ -250,7 +250,7 @@ class TextBoxDrawerTest(SimpleTestCase):\nwidth = 200\nheight = 100\nrotation = 90\n- box = TextBox(vertices, width, height, rotation)\n+ box = TextBox(vertices, width, height, angle=rotation)\nTextBoxDrawer.write_text_box_object(\nimage,\ndraw,\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Fix bug in rotated textbox test
|
701,860 |
08.11.2017 17:31:32
| -46,800 |
7c7e03e1914fa06c36052e02fe43e3015c94cbb7
|
add images to Great Sorted Treasure Hunt Sorted lessons (fixes
|
[
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/marbles.png",
"new_path": "csunplugged/static/img/topics/marbles.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/marbles.png differ\n"
},
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/numbers-middle-bright.png",
"new_path": "csunplugged/static/img/topics/numbers-middle-bright.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/numbers-middle-bright.png differ\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/topics/content/en/searching-algorithms/sequential-and-binary-search-unit-plan/lessons/the-great-treasure-hunt-sorted-ct-links.md",
"new_path": "csunplugged/topics/content/en/searching-algorithms/sequential-and-binary-search-unit-plan/lessons/the-great-treasure-hunt-sorted-ct-links.md",
"diff": "@@ -75,6 +75,8 @@ Which students can explain why the logical decision is to always stick with bina\n#### Examples of what you could look for:\n+{image file-path=\"img/topics/numbers-middle-bright.png\" alt=\"The middle item is the important item.\"}\n+\nWhich students instinctively go for the middle square when searching?\nThey are likely logical thinkers who can deduce that since the numbers are sorted then the middle square will tell them the most useful information.\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
add images to Great Sorted Treasure Hunt Sorted lessons (fixes #672)
|
701,855 |
08.11.2017 18:59:03
| -46,800 |
e9998ce3b367d70a54a5c2f8150048e7be1634ee
|
Add test definitions for TranslatableModelLoader unit tests
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"diff": "+\"\"\"Test class for TranslatableModelLoader.\"\"\"\n+\n+from django.test import SimpleTestCase\n+\n+class TranslatableModelLoaderTest(SimpleTestCase):\n+ \"\"\"Test class for TranslatableModelLoader.\"\"\"\n+\n+ def test_get_yaml_translations_english(self):\n+ pass\n+\n+ def test_get_yaml_translations_english_missing_reqd_field(self):\n+ pass\n+\n+ def test_get_yaml_translations_english_missing_reqd_slug(self):\n+ pass\n+\n+ def test_get_yaml_translations_field_map(self):\n+ pass\n+\n+ def test_get_yaml_translations_translated(self):\n+ pass\n+\n+ def test_get_yaml_translations_translated_missing_reqd_field(self):\n+ pass\n+\n+ def test_get_yaml_translations_translated_missing_reqd_slug(self):\n+ pass\n+\n+ def test_get_yaml_translation_missing_yaml(self):\n+ pass\n+\n+ def test_get_markdown_translations_english(self):\n+ pass\n+\n+ def test_get_markdown_translation_english_missing_file(self):\n+ pass\n+\n+ def test_get_markdown_translations_translated(self):\n+ pass\n+\n+ def test_get_markdown_translation_translated_missing_file(self):\n+ pass\n+\n+ def test_populate_translations(self):\n+ pass\n+\n+ def test_mark_translation_availability_all_required_fields_present(self):\n+ pass\n+\n+ def test_mark_translation_availability_required_field_missing(self):\n+ pass\n+\n+ def test_mark_translation_availability_required_fields_not_given(self):\n+ pass\n+\n+ def test_get_blank_translation_dictionary(self):\n+ pass\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add test definitions for TranslatableModelLoader unit tests
|
701,855 |
08.11.2017 19:29:57
| -46,800 |
2f317cc14738d2e94a1e3b1d7bd2ee669762c08e
|
Add unit tests for TranslatableModelLoader.get_yaml_translations
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/de/translation.yaml",
"diff": "+model1:\n+ field1: de value 1-1\n+ field2: de value 1-2\n+\n+model2:\n+ field1: de value 2-1\n+ field2: de value 2-2\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/de/translationmissingreqdfield.yaml",
"diff": "+model1:\n+ field1: value 1-1\n+ field2: value 1-2\n+\n+model2:\n+ field2: value 2-2\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/de/translationmissingreqdslug.yaml",
"diff": "+model1:\n+ field1: value 1-1\n+ field2: value 1-2\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/en/basic.yaml",
"diff": "+model1:\n+ field1: value 1-1\n+ field2: value 1-2\n+\n+model2:\n+ field1: value 2-1\n+ field2: value 2-2\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/en/missingreqdfield.yaml",
"diff": "+model1:\n+ field1: value 1-1\n+ field2: value 1-2\n+\n+model2:\n+ field2: value 2-2\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/en/missingreqdslug.yaml",
"diff": "+model1:\n+ field1: value 1-1\n+ field2: value 1-2\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/en/translation.yaml",
"diff": "+model1:\n+ field1: en value 1-1\n+ field2: en value 1-2\n+\n+model2:\n+ field1: en value 2-1\n+ field2: en value 2-2\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/en/translationmissingreqdfield.yaml",
"diff": "+model1:\n+ field1: value 1-1\n+ field2: value 1-2\n+\n+model2:\n+ field1: value 2-1\n+ field2: value 2-2\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/en/translationmissingreqdslug.yaml",
"diff": "+model1:\n+ field1: value 1-1\n+ field2: value 1-2\n+\n+model2:\n+ field1: value 2-1\n+ field2: value 2-2\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"new_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"diff": "\"\"\"Test class for TranslatableModelLoader.\"\"\"\nfrom django.test import SimpleTestCase\n+from utils.TranslatableModelLoader import TranslatableModelLoader\n+from utils.errors.MissingRequiredModelsError import MissingRequiredModelsError\n+from utils.errors.MissingRequiredFieldError import MissingRequiredFieldError\n+from utils.errors.CouldNotFindYAMLFileError import CouldNotFindYAMLFileError\n+\nclass TranslatableModelLoaderTest(SimpleTestCase):\n\"\"\"Test class for TranslatableModelLoader.\"\"\"\n+ def __init__(self, *args, **kwargs):\n+ super().__init__(*args, **kwargs)\n+ self.base_path = \"tests/utils/translatable_model_loader/assets\"\n+\ndef test_get_yaml_translations_english(self):\n- pass\n+ yaml_file = \"basic.yaml\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ translations = loader.get_yaml_translations(yaml_file)\n+\n+ self.assertIsInstance(translations, dict)\n+ self.assertSetEqual(set([\"model1\", \"model2\"]), set(translations.keys()))\n+\n+ model1_translations = translations[\"model1\"]\n+ self.assertIsInstance(model1_translations, dict)\n+ self.assertSetEqual(set([\"en\"]), set(model1_translations.keys()))\n+ model1_english = model1_translations[\"en\"]\n+ self.assertIsInstance(model1_english, dict)\n+ self.assertSetEqual(set([\"field1\", \"field2\"]), set(model1_english.keys()))\n+ self.assertEqual(\"value 1-1\", model1_english[\"field1\"])\n+ self.assertEqual(\"value 1-2\", model1_english[\"field2\"])\n+\n+ model2_translations = translations[\"model2\"]\n+ self.assertIsInstance(model2_translations, dict)\n+ self.assertSetEqual(set([\"en\"]), set(model2_translations.keys()))\n+ model2_english = model2_translations[\"en\"]\n+ self.assertIsInstance(model2_english, dict)\n+ self.assertSetEqual(set([\"field1\", \"field2\"]), set(model2_english.keys()))\n+ self.assertEqual(\"value 2-1\", model2_english[\"field1\"])\n+ self.assertEqual(\"value 2-2\", model2_english[\"field2\"])\ndef test_get_yaml_translations_english_missing_reqd_field(self):\n- pass\n+ yaml_file = \"missingreqdfield.yaml\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ with self.assertRaises(MissingRequiredFieldError):\n+ loader.get_yaml_translations(yaml_file, required_fields=[\"field1\"])\ndef test_get_yaml_translations_english_missing_reqd_slug(self):\n- pass\n+ yaml_file = \"missingreqdslug.yaml\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ with self.assertRaises(MissingRequiredModelsError):\n+ loader.get_yaml_translations(yaml_file, required_slugs=[\"model1\", \"model2\"])\n+\n+ def test_get_yaml_translations_english_missing_file_with_reqd_slugs(self):\n+ yaml_file = \"doesnotexist.yaml\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ # With required slugs, a missing english yaml file should raise Exception\n+ with self.assertRaises(CouldNotFindYAMLFileError):\n+ loader.get_yaml_translations(yaml_file, required_slugs=[\"model1\", \"model2\"])\n+\n+ def test_get_yaml_translations_english_missing_yaml_no_reqd_slugs(self):\n+ yaml_file = \"doesnotexist.yaml\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ # If no required slugs, no error should be raised\n+ loader.get_yaml_translations(yaml_file)\ndef test_get_yaml_translations_field_map(self):\n- pass\n+ yaml_file = \"basic.yaml\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ translations = loader.get_yaml_translations(\n+ yaml_file,\n+ field_map={\"field1\": \"new_field1\"}\n+ )\n+ model1 = translations[\"model1\"][\"en\"]\n+ self.assertSetEqual(set([\"new_field1\", \"field2\"]), set(model1.keys()))\n+ self.assertEqual(\"value 1-1\", model1[\"new_field1\"])\ndef test_get_yaml_translations_translated(self):\n- pass\n+ yaml_file = \"translation.yaml\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ translations = loader.get_yaml_translations(yaml_file)\n+\n+ self.assertIsInstance(translations, dict)\n+ self.assertSetEqual(set([\"model1\", \"model2\"]), set(translations.keys()))\n+\n+ model1_translations = translations[\"model1\"]\n+ self.assertIsInstance(model1_translations, dict)\n+ self.assertSetEqual(set([\"en\", \"de\"]), set(model1_translations.keys()))\n+\n+ model1_english = model1_translations[\"en\"]\n+ self.assertIsInstance(model1_english, dict)\n+ self.assertSetEqual(set([\"field1\", \"field2\"]), set(model1_english.keys()))\n+ self.assertEqual(\"en value 1-1\", model1_english[\"field1\"])\n+ self.assertEqual(\"en value 1-2\", model1_english[\"field2\"])\n+\n+ model1_german = model1_translations[\"de\"]\n+ self.assertIsInstance(model1_german, dict)\n+ self.assertSetEqual(set([\"field1\", \"field2\"]), set(model1_german.keys()))\n+ self.assertEqual(\"de value 1-1\", model1_german[\"field1\"])\n+ self.assertEqual(\"de value 1-2\", model1_german[\"field2\"])\ndef test_get_yaml_translations_translated_missing_reqd_field(self):\n- pass\n+ yaml_file = \"translationmissingreqdfield.yaml\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+\n+ # required fields only apply to default language (en) so no error should be raised\n+ translations = loader.get_yaml_translations(yaml_file, required_fields=[\"field1\"])\n+ self.assertSetEqual(set([\"field1\", \"field2\"]), set(translations[\"model2\"][\"en\"].keys()))\n+ self.assertSetEqual(set([\"field2\"]), set(translations[\"model2\"][\"de\"].keys()))\ndef test_get_yaml_translations_translated_missing_reqd_slug(self):\n- pass\n+ yaml_file = \"translationmissingreqdslug.yaml\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n- def test_get_yaml_translation_missing_yaml(self):\n- pass\n+ # required slugs only apply to default language (en) so no error should be raised\n+ translations = loader.get_yaml_translations(yaml_file, required_slugs=[\"model1\", \"model2\"])\n+ self.assertSetEqual(set([\"en\", \"de\"]), set(translations[\"model1\"].keys()))\n+ self.assertSetEqual(set([\"en\"]), set(translations[\"model2\"].keys()))\ndef test_get_markdown_translations_english(self):\npass\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add unit tests for TranslatableModelLoader.get_yaml_translations
|
701,855 |
08.11.2017 21:24:52
| -46,800 |
2848d7b4eba08784532bf060205203bf63bdb1f5
|
Implement unit tests for remaining functions of TranslatableModelLoader
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/de/translation.md",
"diff": "+# German Heading\n+\n+German Content\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/en/basic.md",
"diff": "+# Heading\n+\n+Basic Content\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/utils/translatable_model_loader/assets/en/translation.md",
"diff": "+# English Heading\n+\n+English Content\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"new_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"diff": "@@ -5,6 +5,40 @@ from utils.TranslatableModelLoader import TranslatableModelLoader\nfrom utils.errors.MissingRequiredModelsError import MissingRequiredModelsError\nfrom utils.errors.MissingRequiredFieldError import MissingRequiredFieldError\nfrom utils.errors.CouldNotFindYAMLFileError import CouldNotFindYAMLFileError\n+from utils.errors.CouldNotFindMarkdownFileError import CouldNotFindMarkdownFileError\n+from django.utils import translation\n+from unittest import mock\n+\n+\n+class MockTranslatableModel(object):\n+ \"\"\"Mock behaviour of a translatable model registered with django-modeltranslation.\n+\n+ Important: This does not handle fallback to default values.\n+ \"\"\"\n+ def __init__(self, translatable_fields=[]):\n+ self.translatable_fields = translatable_fields\n+ for field in self.translatable_fields:\n+ setattr(self, \"{}_en\".format(field), \"\")\n+\n+ def __setattr__(self, field, value):\n+ # Set property first to prevent recursiong on self.translatable_fields\n+ super().__setattr__(field, value)\n+ if field in self.translatable_fields:\n+ # Remove property just created\n+ delattr(self, field)\n+ language = translation.get_language()\n+ field = \"{}_{}\".format(field, language)\n+ super().__setattr__(field, value)\n+\n+ def __getattr__(self, field):\n+ if field in self.translatable_fields:\n+ language = translation.get_language()\n+ field = \"{}_{}\".format(field, language)\n+ try:\n+ return super().__getattribute__(field)\n+ except:\n+ return None\n+\nclass TranslatableModelLoaderTest(SimpleTestCase):\n@@ -119,28 +153,89 @@ class TranslatableModelLoaderTest(SimpleTestCase):\nself.assertSetEqual(set([\"en\"]), set(translations[\"model2\"].keys()))\ndef test_get_markdown_translations_english(self):\n- pass\n+ filename = \"basic.md\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ translations = loader.get_markdown_translations(filename)\n+ self.assertSetEqual(set([\"en\"]), set(translations.keys()))\n+ self.assertIn(\"Basic Content\", translations[\"en\"].html_string)\n+ self.assertIn(\"Heading\", translations[\"en\"].title)\n- def test_get_markdown_translation_english_missing_file(self):\n- pass\n+ def test_get_markdown_translation_english_missing_file_required(self):\n+ filename = \"doesnotexist.md\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ with self.assertRaises(CouldNotFindMarkdownFileError):\n+ loader.get_markdown_translations(filename, required=True)\n+\n+ def test_get_markdown_translation_english_missing_file_not_required(self):\n+ filename = \"doesnotexist.md\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ # Should not raise error if required is False\n+ loader.get_markdown_translations(filename, required=False)\ndef test_get_markdown_translations_translated(self):\n- pass\n+ filename = \"translation.md\"\n+ loader = TranslatableModelLoader(base_path=self.base_path)\n+ translations = loader.get_markdown_translations(filename)\n+ self.assertSetEqual(set([\"en\", \"de\"]), set(translations.keys()))\n+\n+ en = translations[\"en\"]\n+ self.assertIn(\"English Content\", en.html_string)\n+ self.assertIn(\"English Heading\", en.title)\n- def test_get_markdown_translation_translated_missing_file(self):\n- pass\n+ de = translations[\"de\"]\n+ self.assertIn(\"German Content\", de.html_string)\n+ self.assertIn(\"German Heading\", de.title)\ndef test_populate_translations(self):\n- pass\n+ model = MockTranslatableModel(translatable_fields=[\"field1\", \"field2\"])\n+ translations = {\n+ \"en\": {\n+ \"field1\": \"english value 1\",\n+ \"field2\": \"english value 2\"\n+ },\n+ \"de\": {\n+ \"field1\": \"german value 1\",\n+ \"field2\": \"german value 2\"\n+ }\n+ }\n+ TranslatableModelLoader.populate_translations(model, translations)\n+ self.assertEqual(model.field1, \"english value 1\")\n+ self.assertEqual(model.field2, \"english value 2\")\n+ with translation.override(\"de\"):\n+ self.assertEqual(model.field1, \"german value 1\")\n+ self.assertEqual(model.field2, \"german value 2\")\n+\ndef test_mark_translation_availability_all_required_fields_present(self):\n- pass\n+ model = MockTranslatableModel(translatable_fields=[\"title\"])\n+ model.title = \"english title\"\n+ with translation.override(\"de\"):\n+ model.title = \"german title\"\n+ with mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\n+ TranslatableModelLoader.mark_translation_availability(model, required_fields=[\"title\"])\n+ self.assertSetEqual(set([\"en\", \"de\"]), set(model.languages))\ndef test_mark_translation_availability_required_field_missing(self):\n- pass\n+ model = MockTranslatableModel(translatable_fields=[\"title\", \"content\"])\n+ model.title = \"english title\"\n+ model.content = \"english content\"\n+ with translation.override(\"de\"):\n+ model.title = \"german title\"\n+\n+ with mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\n+ TranslatableModelLoader.mark_translation_availability(model, required_fields=[\"title\", \"content\"])\n+ self.assertSetEqual(set([\"en\"]), set(model.languages))\ndef test_mark_translation_availability_required_fields_not_given(self):\n- pass\n+ model = MockTranslatableModel(translatable_fields=[\"title\", \"content\"])\n+ with mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\n+ TranslatableModelLoader.mark_translation_availability(model)\n+ self.assertSetEqual(set([\"en\", \"de\", \"fr\"]), set(model.languages))\ndef test_get_blank_translation_dictionary(self):\n- pass\n+ with mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\n+ translation_dict = TranslatableModelLoader.get_blank_translation_dictionary()\n+ self.assertSetEqual(set([\"en\", \"de\", \"fr\"]), set(translation_dict.keys()))\n+ self.assertDictEqual(translation_dict[\"en\"], {})\n+ # Check to make sure it's not a dictionary of references to the same dictionary\n+ self.assertFalse(translation_dict[\"en\"] is translation_dict[\"de\"])\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/utils/TranslatableModelLoader.py",
"new_path": "csunplugged/utils/TranslatableModelLoader.py",
"diff": "@@ -122,7 +122,8 @@ class TranslatableModelLoader(BaseLoader):\nraise\nreturn content_translations\n- def populate_translations(self, model, model_translations_dict):\n+ @staticmethod\n+ def populate_translations(model, model_translations_dict):\n\"\"\"Populate the translation fields of the given model.\nArgs:\n@@ -140,7 +141,8 @@ class TranslatableModelLoader(BaseLoader):\nfor field, value in values_dict.items():\nsetattr(model, field, value)\n- def mark_translation_availability(self, model, required_fields=[]):\n+ @staticmethod\n+ def mark_translation_availability(model, required_fields=[]):\n\"\"\"Populate the available_languages field of a translatable model.\nArgs:\n@@ -158,6 +160,7 @@ class TranslatableModelLoader(BaseLoader):\navailable_languages.append(language)\nmodel.languages = available_languages\n- def get_blank_translation_dictionary(self):\n+ @staticmethod\n+ def get_blank_translation_dictionary():\n\"\"\"Return a dictionary of blank dictionaries, keyed by all available language.\"\"\"\nreturn {language: dict() for language in get_available_languages()}\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Implement unit tests for remaining functions of TranslatableModelLoader
|
701,855 |
08.11.2017 21:39:11
| -46,800 |
847045e923ed3e5778ad159d88648d256cdb7206
|
Minor tidy-ups on TranslatableModelLoader unit tests
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"new_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"diff": "@@ -8,17 +8,13 @@ from utils.errors.CouldNotFindYAMLFileError import CouldNotFindYAMLFileError\nfrom utils.errors.CouldNotFindMarkdownFileError import CouldNotFindMarkdownFileError\nfrom django.utils import translation\nfrom unittest import mock\n+from modeltranslation import settings\nclass MockTranslatableModel(object):\n- \"\"\"Mock behaviour of a translatable model registered with django-modeltranslation.\n-\n- Important: This does not handle fallback to default values.\n- \"\"\"\n+ \"\"\"Mock behaviour of a translatable model registered with django-modeltranslation.\"\"\"\ndef __init__(self, translatable_fields=[]):\nself.translatable_fields = translatable_fields\n- for field in self.translatable_fields:\n- setattr(self, \"{}_en\".format(field), \"\")\ndef __setattr__(self, field, value):\n# Set property first to prevent recursiong on self.translatable_fields\n@@ -33,14 +29,20 @@ class MockTranslatableModel(object):\ndef __getattr__(self, field):\nif field in self.translatable_fields:\nlanguage = translation.get_language()\n- field = \"{}_{}\".format(field, language)\n+ field_template = \"{}_{}\"\n+ trans_field = field_template.format(field, language)\ntry:\n- return super().__getattribute__(field)\n- except:\n+ return super().__getattribute__(trans_field)\n+ except AttributeError:\n+ if language == \"en\":\n+ return \"\"\n+ elif settings.ENABLE_FALLBACKS:\n+ with translation.override(\"en\"):\n+ return getattr(self, field)\n+ else:\nreturn None\n-\nclass TranslatableModelLoaderTest(SimpleTestCase):\n\"\"\"Test class for TranslatableModelLoader.\"\"\"\n@@ -205,7 +207,6 @@ class TranslatableModelLoaderTest(SimpleTestCase):\nself.assertEqual(model.field1, \"german value 1\")\nself.assertEqual(model.field2, \"german value 2\")\n-\ndef test_mark_translation_availability_all_required_fields_present(self):\nmodel = MockTranslatableModel(translatable_fields=[\"title\"])\nmodel.title = \"english title\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Minor tidy-ups on TranslatableModelLoader unit tests
|
701,855 |
08.11.2017 21:40:31
| -46,800 |
474c5f977ab5b035567f0107c457622c51189ac6
|
Add new topics migration file
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/topics/migrations/0086_auto_20171108_0840.py",
"diff": "+# -*- coding: utf-8 -*-\n+# Generated by Django 1.11.5 on 2017-11-08 08:40\n+from __future__ import unicode_literals\n+\n+from django.db import migrations, models\n+\n+\n+class Migration(migrations.Migration):\n+\n+ dependencies = [\n+ ('topics', '0085_auto_20171030_0035'),\n+ ]\n+\n+ operations = [\n+ migrations.AddField(\n+ model_name='programmingchallengelanguage',\n+ name='name_de',\n+ field=models.CharField(max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengelanguage',\n+ name='name_en',\n+ field=models.CharField(max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengelanguage',\n+ name='name_fr',\n+ field=models.CharField(max_length=200, null=True),\n+ ),\n+ migrations.AlterField(\n+ model_name='classroomresource',\n+ name='description',\n+ field=models.CharField(default='', max_length=100),\n+ ),\n+ migrations.AlterField(\n+ model_name='classroomresource',\n+ name='description_de',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AlterField(\n+ model_name='classroomresource',\n+ name='description_en',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AlterField(\n+ model_name='classroomresource',\n+ name='description_fr',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AlterField(\n+ model_name='curriculumarea',\n+ name='name',\n+ field=models.CharField(default='', max_length=100),\n+ ),\n+ migrations.AlterField(\n+ model_name='curriculumarea',\n+ name='name_de',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AlterField(\n+ model_name='curriculumarea',\n+ name='name_en',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AlterField(\n+ model_name='curriculumarea',\n+ name='name_fr',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AlterField(\n+ model_name='programmingchallengelanguage',\n+ name='name',\n+ field=models.CharField(max_length=200),\n+ ),\n+ ]\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add new topics migration file
|
701,860 |
09.11.2017 12:19:36
| -46,800 |
acb40a10eac51fb3ac0d5be9fa3aa58a3caa1da5
|
Add images for Divide and Conquer lesson (fixes
|
[
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/cards-0.png",
"new_path": "csunplugged/static/img/topics/cards-0.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/cards-0.png differ\n"
},
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/cards-1.png",
"new_path": "csunplugged/static/img/topics/cards-1.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/cards-1.png differ\n"
},
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/cards-2.png",
"new_path": "csunplugged/static/img/topics/cards-2.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/cards-2.png differ\n"
},
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/cards-3.png",
"new_path": "csunplugged/static/img/topics/cards-3.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/cards-3.png differ\n"
},
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/cards-4.png",
"new_path": "csunplugged/static/img/topics/cards-4.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/cards-4.png differ\n"
},
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/child_in_numbers.png",
"new_path": "csunplugged/static/img/topics/child_in_numbers.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/child_in_numbers.png differ\n"
},
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/divide.png",
"new_path": "csunplugged/static/img/topics/divide.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/divide.png differ\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add images for Divide and Conquer lesson (fixes #673)
|
701,855 |
10.11.2017 12:05:50
| -46,800 |
078af51d8c9c9d21a26d2fbce5d66eaee1ed0e66
|
Use real TranslatableModel instance rather than mocking functionality
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"new_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"diff": "\"\"\"Test class for TranslatableModelLoader.\"\"\"\nfrom django.test import SimpleTestCase\n+from django.db import models\nfrom utils.TranslatableModelLoader import TranslatableModelLoader\n+from utils.TranslatableModel import TranslatableModel\nfrom utils.errors.MissingRequiredModelsError import MissingRequiredModelsError\nfrom utils.errors.MissingRequiredFieldError import MissingRequiredFieldError\nfrom utils.errors.CouldNotFindYAMLFileError import CouldNotFindYAMLFileError\nfrom utils.errors.CouldNotFindMarkdownFileError import CouldNotFindMarkdownFileError\nfrom django.utils import translation\nfrom unittest import mock\n-from modeltranslation import settings\n-\n-\n-class MockTranslatableModel(object):\n- \"\"\"Mock behaviour of a translatable model registered with django-modeltranslation.\"\"\"\n- def __init__(self, translatable_fields=[]):\n- self.translatable_fields = translatable_fields\n-\n- def __setattr__(self, field, value):\n- # Set property first to prevent recursiong on self.translatable_fields\n- super().__setattr__(field, value)\n- if field in self.translatable_fields:\n- # Remove property just created\n- delattr(self, field)\n- language = translation.get_language()\n- field = \"{}_{}\".format(field, language)\n- super().__setattr__(field, value)\n-\n- def __getattr__(self, field):\n- if field in self.translatable_fields:\n- language = translation.get_language()\n- field_template = \"{}_{}\"\n- trans_field = field_template.format(field, language)\n- try:\n- return super().__getattribute__(trans_field)\n- except AttributeError:\n- if language == \"en\":\n- return \"\"\n- elif settings.ENABLE_FALLBACKS:\n- with translation.override(\"en\"):\n- return getattr(self, field)\n- else:\n- return None\n+from modeltranslation.translator import translator, TranslationOptions\n+\n+\n+class MockTranslatableModel(TranslatableModel):\n+ \"\"\"Mock TranslatableModel for testing TranslatableModelLoader functionality.\"\"\"\n+ # Fields with fallback to english disabled\n+ nofallback1 = models.CharField(default=\"\")\n+ nofallback2 = models.CharField(default=\"\")\n+ nofallback3 = models.CharField(default=\"\")\n+\n+ # Fields with fallback to english enabled\n+ fallback1 = models.CharField(default=\"\")\n+ fallback2 = models.CharField(default=\"\")\n+\n+ class Meta:\n+ app_label = \"test\",\n+\n+\n+class MockTranslatableModelTranslationOptions(TranslationOptions):\n+ \"\"\"Translation options for MockTranslatableModel model.\"\"\"\n+\n+ fields = (\"nofallback1\", 'nofallback2', 'nofallback3', \"fallback1\", \"fallback2\")\n+ fallback_undefined = {\n+ 'nofallback1': None,\n+ 'nofallback2': None,\n+ 'nofallback3': None,\n+ }\n+\n+\n+translator.register(MockTranslatableModel, MockTranslatableModelTranslationOptions)\nclass TranslatableModelLoaderTest(SimpleTestCase):\n@@ -189,46 +188,59 @@ class TranslatableModelLoaderTest(SimpleTestCase):\nself.assertIn(\"German Heading\", de.title)\ndef test_populate_translations(self):\n- model = MockTranslatableModel(translatable_fields=[\"field1\", \"field2\"])\n+ model = MockTranslatableModel()\ntranslations = {\n\"en\": {\n- \"field1\": \"english value 1\",\n- \"field2\": \"english value 2\"\n+ \"fallback1\": \"english value 1\",\n+ \"nofallback1\": \"english value 2\"\n},\n\"de\": {\n- \"field1\": \"german value 1\",\n- \"field2\": \"german value 2\"\n+ \"fallback1\": \"german value 1\",\n+ \"nofallback1\": \"german value 2\"\n}\n}\nTranslatableModelLoader.populate_translations(model, translations)\n- self.assertEqual(model.field1, \"english value 1\")\n- self.assertEqual(model.field2, \"english value 2\")\n+ self.assertEqual(model.fallback1, \"english value 1\")\n+ self.assertEqual(model.nofallback1, \"english value 2\")\nwith translation.override(\"de\"):\n- self.assertEqual(model.field1, \"german value 1\")\n- self.assertEqual(model.field2, \"german value 2\")\n+ self.assertEqual(model.fallback1, \"german value 1\")\n+ self.assertEqual(model.nofallback1, \"german value 2\")\ndef test_mark_translation_availability_all_required_fields_present(self):\n- model = MockTranslatableModel(translatable_fields=[\"title\"])\n- model.title = \"english title\"\n+ model = MockTranslatableModel()\n+ model.fallback1 = \"english value 1\"\n+ model.nofallback1 = \"english value 2\"\nwith translation.override(\"de\"):\n- model.title = \"german title\"\n+ model.fallback1 = \"german value 1\"\n+ model.nofallback1 = \"german value 2\"\nwith mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\n- TranslatableModelLoader.mark_translation_availability(model, required_fields=[\"title\"])\n+ TranslatableModelLoader.mark_translation_availability(model, required_fields=[\"fallback1\", \"nofallback1\"])\nself.assertSetEqual(set([\"en\", \"de\"]), set(model.languages))\n- def test_mark_translation_availability_required_field_missing(self):\n- model = MockTranslatableModel(translatable_fields=[\"title\", \"content\"])\n- model.title = \"english title\"\n- model.content = \"english content\"\n+ def test_mark_translation_availability_required_fallback_field_missing(self):\n+ model = MockTranslatableModel()\n+ model.fallback1 = \"english value 1\"\n+ model.nofallback1 = \"english value 2\"\nwith translation.override(\"de\"):\n- model.title = \"german title\"\n+ # Don't populate the field \"fallback1\" which has fallback enabled\n+ model.nofallback1 = \"german value 2\"\n+ with mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\n+ TranslatableModelLoader.mark_translation_availability(model, required_fields=[\"fallback1\", \"nofallback1\"])\n+ self.assertSetEqual(set([\"en\"]), set(model.languages))\n+ def test_mark_translation_availability_required_no_fallback_field_missing(self):\n+ model = MockTranslatableModel()\n+ model.fallback1 = \"english value 1\"\n+ model.nofallback1 = \"english value 2\"\n+ with translation.override(\"de\"):\n+ # Don't populate the field \"nofallback1\" which does not have fallback enabled\n+ model.fallback1 = \"german value 1\"\nwith mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\n- TranslatableModelLoader.mark_translation_availability(model, required_fields=[\"title\", \"content\"])\n+ TranslatableModelLoader.mark_translation_availability(model, required_fields=[\"fallback1\", \"nofallback1\"])\nself.assertSetEqual(set([\"en\"]), set(model.languages))\ndef test_mark_translation_availability_required_fields_not_given(self):\n- model = MockTranslatableModel(translatable_fields=[\"title\", \"content\"])\n+ model = MockTranslatableModel()\nwith mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\nTranslatableModelLoader.mark_translation_availability(model)\nself.assertSetEqual(set([\"en\", \"de\", \"fr\"]), set(model.languages))\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Use real TranslatableModel instance rather than mocking functionality
|
701,855 |
10.11.2017 12:26:36
| -46,800 |
fd903f21123144cdefecbe52a909af5ae3b61c2c
|
Remove vinaigrette from resources application
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/models.py",
"new_path": "csunplugged/resources/models.py",
"diff": "\"\"\"Models for the resources application.\"\"\"\nfrom django.db import models\n-import vinaigrette\nclass Resource(models.Model):\n@@ -22,7 +21,3 @@ class Resource(models.Model):\nName of resource (str).\n\"\"\"\nreturn self.name\n-\n-\n-# Extract resource names for tranlsation on makemessages command.\n-vinaigrette.register(Resource, [\"name\"])\n"
},
{
"change_type": "MODIFY",
"old_path": "requirements/base.txt",
"new_path": "requirements/base.txt",
"diff": "@@ -20,4 +20,3 @@ tqdm==4.19.4\n# Translations\ndjango-modeltranslation==0.12.1\n-django-vinaigrette==1.0.1\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Remove vinaigrette from resources application
|
701,855 |
11.11.2017 14:32:59
| -46,800 |
b1890aefa437cc4d20af6aeb3c951aef6b2c3999
|
Override LANGUAGES setting in test environment
This setting is used by django-modeltranslation to determine
which translation fields to add to TranslatableModels, when
creating the database, which should not depend on the production
value of this setting.
The production value is saved in PRODUCTION_LANGUAGES, in case
any tests need to access it.
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/config/settings/testing.py",
"new_path": "csunplugged/config/settings/testing.py",
"diff": "@@ -71,3 +71,15 @@ INSTALLED_APPS += [ # noqa: F405\n\"test_without_migrations\",\n\"dev.apps.DevConfig\",\n]\n+\n+# Save production LANGUAGES setting in case any tests need to refer to it\n+PRODUCTION_LANGUAGES = LANGUAGES # noqa: F405\n+\n+# Override production value of LANGUAGES - this is what django-modeltranslation\n+# will use when adding translated fields to the models on startup, which is\n+# necessary to test i18n backend functionality.\n+LANGUAGES = (\n+ (\"en\", \"English\"),\n+ (\"de\", \"German\"),\n+ (\"fr\", \"French\"),\n+)\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Override LANGUAGES setting in test environment
This setting is used by django-modeltranslation to determine
which translation fields to add to TranslatableModels, when
creating the database, which should not depend on the production
value of this setting.
The production value is saved in PRODUCTION_LANGUAGES, in case
any tests need to access it.
|
701,855 |
11.11.2017 14:36:40
| -46,800 |
8ceadf61bda145a2afe4025a17e300626605c298
|
Fix MockTranslatableModel modeltranslation registration in unit tests
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"new_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"diff": "\"\"\"Test class for TranslatableModelLoader.\"\"\"\n-from django.test import SimpleTestCase\n+import imp\n+from unittest import mock\n+\n+from modeltranslation import settings as mt_settings\n+from modeltranslation.translator import translator, TranslationOptions\n+\nfrom django.db import models\n+from django.test import SimpleTestCase\n+from django.utils import translation\n+\nfrom utils.TranslatableModelLoader import TranslatableModelLoader\nfrom utils.TranslatableModel import TranslatableModel\nfrom utils.errors.MissingRequiredModelsError import MissingRequiredModelsError\nfrom utils.errors.MissingRequiredFieldError import MissingRequiredFieldError\nfrom utils.errors.CouldNotFindYAMLFileError import CouldNotFindYAMLFileError\nfrom utils.errors.CouldNotFindMarkdownFileError import CouldNotFindMarkdownFileError\n-from django.utils import translation\n-from unittest import mock\n-from modeltranslation.translator import translator, TranslationOptions\n+from utils.language_utils import get_available_languages\nclass MockTranslatableModel(TranslatableModel):\n@@ -39,9 +45,6 @@ class MockTranslatableModelTranslationOptions(TranslationOptions):\n}\n-translator.register(MockTranslatableModel, MockTranslatableModelTranslationOptions)\n-\n-\nclass TranslatableModelLoaderTest(SimpleTestCase):\n\"\"\"Test class for TranslatableModelLoader.\"\"\"\n@@ -49,7 +52,14 @@ class TranslatableModelLoaderTest(SimpleTestCase):\nsuper().__init__(*args, **kwargs)\nself.base_path = \"tests/utils/translatable_model_loader/assets\"\n+ @classmethod\n+ def setUpClass(cls):\n+ super().setUpClass()\n+ imp.reload(mt_settings) # Let modeltranslation pick up any overriden settings\n+ translator.register(MockTranslatableModel, MockTranslatableModelTranslationOptions)\n+\ndef test_get_yaml_translations_english(self):\n+\nyaml_file = \"basic.yaml\"\nloader = TranslatableModelLoader(base_path=self.base_path)\ntranslations = loader.get_yaml_translations(yaml_file)\n@@ -213,7 +223,6 @@ class TranslatableModelLoaderTest(SimpleTestCase):\nwith translation.override(\"de\"):\nmodel.fallback1 = \"german value 1\"\nmodel.nofallback1 = \"german value 2\"\n- with mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\nTranslatableModelLoader.mark_translation_availability(model, required_fields=[\"fallback1\", \"nofallback1\"])\nself.assertSetEqual(set([\"en\", \"de\"]), set(model.languages))\n@@ -224,7 +233,6 @@ class TranslatableModelLoaderTest(SimpleTestCase):\nwith translation.override(\"de\"):\n# Don't populate the field \"fallback1\" which has fallback enabled\nmodel.nofallback1 = \"german value 2\"\n- with mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\nTranslatableModelLoader.mark_translation_availability(model, required_fields=[\"fallback1\", \"nofallback1\"])\nself.assertSetEqual(set([\"en\"]), set(model.languages))\n@@ -235,7 +243,6 @@ class TranslatableModelLoaderTest(SimpleTestCase):\nwith translation.override(\"de\"):\n# Don't populate the field \"nofallback1\" which does not have fallback enabled\nmodel.fallback1 = \"german value 1\"\n- with mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\nTranslatableModelLoader.mark_translation_availability(model, required_fields=[\"fallback1\", \"nofallback1\"])\nself.assertSetEqual(set([\"en\"]), set(model.languages))\n@@ -243,12 +250,11 @@ class TranslatableModelLoaderTest(SimpleTestCase):\nmodel = MockTranslatableModel()\nwith mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\nTranslatableModelLoader.mark_translation_availability(model)\n- self.assertSetEqual(set([\"en\", \"de\", \"fr\"]), set(model.languages))\n+ self.assertSetEqual(set(get_available_languages()), set(model.languages))\ndef test_get_blank_translation_dictionary(self):\n- with mock.patch('utils.language_utils.get_available_languages', return_value=[\"en\", \"de\", \"fr\"]):\ntranslation_dict = TranslatableModelLoader.get_blank_translation_dictionary()\n- self.assertSetEqual(set([\"en\", \"de\", \"fr\"]), set(translation_dict.keys()))\n+ self.assertSetEqual(set(get_available_languages()), set(translation_dict.keys()))\nself.assertDictEqual(translation_dict[\"en\"], {})\n# Check to make sure it's not a dictionary of references to the same dictionary\nself.assertFalse(translation_dict[\"en\"] is translation_dict[\"de\"])\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Fix MockTranslatableModel modeltranslation registration in unit tests
|
701,855 |
12.11.2017 11:59:23
| -46,800 |
f7a76cb2b3f04a725167e84f581da6d832341ec8
|
Minor requested changes on PR
|
[
{
"change_type": "MODIFY",
"old_path": "crowdin_content.yaml",
"new_path": "crowdin_content.yaml",
"diff": "\"project_identifier\": \"cs-unplugged\"\n\"api_key_env\": CROWDIN_API_KEY\n\"base_path\": \"\"\n-#\"base_url\" : \"\"\n#\n# Choose file structure in crowdin\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/management/commands/_ResourcesLoader.py",
"new_path": "csunplugged/resources/management/commands/_ResourcesLoader.py",
"diff": "@@ -14,10 +14,6 @@ from django.contrib.staticfiles import finders\nclass ResourcesLoader(BaseLoader):\n\"\"\"Custom loader for loading resources.\"\"\"\n- def __init__(self, **kwargs):\n- \"\"\"Create the loader for loading resources.\"\"\"\n- super().__init__(**kwargs)\n-\n@transaction.atomic\ndef load(self):\n\"\"\"Load the content for resources.\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/templates/base.html",
"new_path": "csunplugged/templates/base.html",
"diff": "<!-- jQuery first, then Tether, then Bootstrap JS. -->\n<script>\n- glossary_url = \"{% url 'topics:glossary_json' %}\"\n+ glossary_url = \"{% url 'topics:glossary_json' %}\";\n</script>\n<script src=\"{% static 'js/jquery-3.1.1.min.js' %}\"></script>\n<script src=\"{% static 'js/tether.min.js' %}\"></script>\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"new_path": "csunplugged/tests/utils/translatable_model_loader/test_TranslatableModelLoader.py",
"diff": "@@ -55,7 +55,7 @@ class TranslatableModelLoaderTest(SimpleTestCase):\n@classmethod\ndef setUpClass(cls):\nsuper().setUpClass()\n- imp.reload(mt_settings) # Let modeltranslation pick up any overriden settings\n+ imp.reload(mt_settings) # Let modeltranslation pick up any overridden settings\ntranslator.register(MockTranslatableModel, MockTranslatableModelTranslationOptions)\ndef test_get_yaml_translations_english(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/utils/TranslatableModel.py",
"new_path": "csunplugged/utils/TranslatableModel.py",
"diff": "@@ -29,7 +29,7 @@ class UntranslatedModelManager(models.Manager):\nclass TranslatableModel(models.Model):\n\"\"\"Abstract base class for models needing to store list of available languages.\"\"\"\n- languages = ArrayField(models.CharField(max_length=5), size=100, default=[])\n+ languages = ArrayField(models.CharField(max_length=5), default=[])\nobjects = models.Manager()\ntranslated_objects = TranslatedModelManager()\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Minor requested changes on PR
|
701,855 |
12.11.2017 13:10:51
| -46,800 |
154b1ac694fb96a5e4908e7586c019da50d05ba2
|
Add unit tests for translate_url template tag
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/config/templatetags/translate_url.py",
"new_path": "csunplugged/config/templatetags/translate_url.py",
"diff": "from django.template import Library\nfrom django.core.urlresolvers import resolve, reverse\nfrom django.utils.translation import activate, get_language\n+from django.template import TemplateSyntaxError\n+from django.urls.exceptions import Resolver404\n+\n+from utils.language_utils import get_available_languages\n+\n+INVALID_ATTRIBUTE_MESSAGE = \"The 'translate_url' tag was given an invalid language code '{}'.\"\n+INVALID_PATH_MESSAGE = \"The 'translate_url' tag could not resolve the current url {}.\"\n+\nregister = Library()\n@register.simple_tag(takes_context=True)\n-def translate_url(context, lang=None, *args, **kwargs):\n+def translate_url(context, lang, *args, **kwargs):\n\"\"\"Get active page's url for a specified language.\nUsage: {% translate_url 'en' %}\n\"\"\"\n+ if lang not in get_available_languages():\n+ raise TemplateSyntaxError(INVALID_ATTRIBUTE_MESSAGE.format(lang))\n+\nurl = context[\"request\"].path\n+ try:\nurl_parts = resolve(url)\n+ except Resolver404:\n+ raise TemplateSyntaxError(INVALID_PATH_MESSAGE.format(url))\ncur_language = get_language()\ntry:\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/general/templatetags/test_translate_url.py",
"diff": "+from django import template\n+from django.test import override_settings\n+from django.http.request import HttpRequest\n+\n+from django.template import TemplateSyntaxError\n+\n+from tests.BaseTest import BaseTest\n+\n+AVAILABLE_LANGUAGES_EN_DE = (\n+ (\"en\", \"English\"),\n+ (\"de\", \"German\")\n+)\n+\n+AVAILABLE_LANGUAGES_EN = (\n+ (\"en\", \"English\"),\n+)\n+\n+VALID_PATH = \"/topics/topic-name/unit-plan/unit-plan-name/\"\n+INVALID_PATH = \"/this/is/an/invalid/url\"\n+\n+\n+class TranslateURLTest(BaseTest):\n+\n+ def render_template(self, string, context):\n+ context = template.Context(context)\n+ return template.Template(string).render(context)\n+\n+ @override_settings(LANGUAGES=AVAILABLE_LANGUAGES_EN_DE)\n+ def test_translate_url(self):\n+ localised_path = \"/en\" + VALID_PATH\n+ request = HttpRequest()\n+ request.path = localised_path\n+ context = {\n+ \"request\": request\n+ }\n+ tag = \"{% load translate_url %}{% translate_url 'de' %}\"\n+ rendered = self.render_template(tag, context)\n+ self.assertEqual(\n+ \"/de\" + VALID_PATH,\n+ rendered\n+ )\n+\n+ @override_settings(LANGUAGES=AVAILABLE_LANGUAGES_EN_DE)\n+ def test_translate_url_invalid_url(self):\n+ path = INVALID_PATH\n+ localised_path = \"/en\" + path\n+ request = HttpRequest()\n+ request.path = localised_path\n+ context = {\n+ \"request\": request\n+ }\n+ tag = \"{% load translate_url %}{% translate_url 'de' %}\"\n+ with self.assertRaises(TemplateSyntaxError):\n+ self.render_template(tag, context)\n+\n+ def test_translate_url_missing_target_language(self):\n+ path = \"/topics/topic-name/unit-plan/unit-plan-name/\"\n+ localised_path = \"/en\" + path\n+ request = HttpRequest()\n+ request.path = localised_path\n+ context = {\n+ \"request\": request\n+ }\n+ tag = \"{% load translate_url %}{% translate_url %}\"\n+ with self.assertRaises(TemplateSyntaxError):\n+ self.render_template(tag, context)\n+\n+ @override_settings(LANGUAGES=AVAILABLE_LANGUAGES_EN)\n+ def test_translate_url_invalid_language(self):\n+ path = \"/topics/topic-name/unit-plan/unit-plan-name/\"\n+ localised_path = \"/en\" + path\n+ request = HttpRequest()\n+ request.path = localised_path\n+ context = {\n+ \"request\": request\n+ }\n+ tag = \"{% load translate_url %}{% translate_url 'de' %}\"\n+ with self.assertRaises(TemplateSyntaxError):\n+ self.render_template(tag, context)\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add unit tests for translate_url template tag
|
701,855 |
12.11.2017 13:22:43
| -46,800 |
d5b249423c8bc4907a8ca31127663d821be62a48
|
Clean up crowdin_content.yaml configuration file
|
[
{
"change_type": "MODIFY",
"old_path": "crowdin_content.yaml",
"new_path": "crowdin_content.yaml",
"diff": "-#\n-# Your crowdin's credentials\n-#\n-\"project_identifier\": \"cs-unplugged\"\n-\"api_key_env\": CROWDIN_API_KEY\n-\"base_path\": \"\"\n+# Project settings\n+project_identifier: \"cs-unplugged\"\n+api_key_env: \"CROWDIN_API_KEY\"\n+base_path: \"\"\n-#\n-# Choose file structure in crowdin\n-# e.g. true or false\n-#\n-\"preserve_hierarchy\": true\n+# Preserve directory tree during upload\n+preserve_hierarchy: true\n-#\n-# Files configuration\n-#\nfiles: [\n{\n- \"source\": \"/csunplugged/topics/content/en/**/*.yaml\",\n- \"translation\": \"/csunplugged/topics/content/%two_letters_code%/**/%original_file_name%\",\n+ source: \"/csunplugged/topics/content/en/**/*.yaml\",\n+ translation: \"/csunplugged/topics/content/%two_letters_code%/**/%original_file_name%\",\n- # The parameter \"update_option\" is optional. If it is not set, translations for changed strings will be lost. Useful for typo fixes and minor changes in source strings.\n- # e.g. \"update_as_unapproved\" or \"update_without_changes\"\n- #\n- #\"update_option\" : \"\",\n},\n{\n- \"source\": \"/csunplugged/topics/content/en/**/*.md\",\n- \"translation\": \"/csunplugged/topics/content/%two_letters_code%/**/%original_file_name%\",\n+ source: \"/csunplugged/topics/content/en/**/*.md\",\n+ translation: \"/csunplugged/topics/content/%two_letters_code%/**/%original_file_name%\",\n}\n]\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Clean up crowdin_content.yaml configuration file
|
701,855 |
12.11.2017 13:29:21
| -46,800 |
3f97fde54d53252ac168b031af66d7168784baf9
|
Remove unnecessary initialisers from BaseResourceLoader subclasses
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/topics/management/commands/_AgeGroupsLoader.py",
"new_path": "csunplugged/topics/management/commands/_AgeGroupsLoader.py",
"diff": "@@ -10,10 +10,6 @@ from topics.models import AgeGroup\nclass AgeGroupsLoader(TranslatableModelLoader):\n\"\"\"Loader for age group content.\"\"\"\n- def __init__(self, **kwargs):\n- \"\"\"Create the loader for loading age groups.\"\"\"\n- super().__init__(**kwargs)\n-\n@transaction.atomic\ndef load(self):\n\"\"\"Load the content for age groups.\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/topics/management/commands/_ClassroomResourcesLoader.py",
"new_path": "csunplugged/topics/management/commands/_ClassroomResourcesLoader.py",
"diff": "@@ -10,10 +10,6 @@ from topics.models import ClassroomResource\nclass ClassroomResourcesLoader(TranslatableModelLoader):\n\"\"\"Loader for curriculum area content.\"\"\"\n- def __init__(self, **kwargs):\n- \"\"\"Create the loader for loading curriculum areas.\"\"\"\n- super().__init__(**kwargs)\n-\n@transaction.atomic\ndef load(self):\n\"\"\"Load the content for classroom resource.\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/topics/management/commands/_CurriculumAreasLoader.py",
"new_path": "csunplugged/topics/management/commands/_CurriculumAreasLoader.py",
"diff": "@@ -10,10 +10,6 @@ from topics.models import CurriculumArea\nclass CurriculumAreasLoader(TranslatableModelLoader):\n\"\"\"Loader for curriculum area content.\"\"\"\n- def __init__(self, **kwargs):\n- \"\"\"Create the loader for loading curriculum areas.\"\"\"\n- super().__init__(**kwargs)\n-\n@transaction.atomic\ndef load(self):\n\"\"\"Load the content for curriculum areas.\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/topics/management/commands/_CurriculumIntegrationsLoader.py",
"new_path": "csunplugged/topics/management/commands/_CurriculumIntegrationsLoader.py",
"diff": "@@ -20,7 +20,6 @@ class CurriculumIntegrationsLoader(TranslatableModelLoader):\ntopic: Object of related topic model (Topic).\n\"\"\"\nsuper().__init__(**kwargs)\n-\nself.topic = topic\ndef load(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/topics/management/commands/_GlossaryTermsLoader.py",
"new_path": "csunplugged/topics/management/commands/_GlossaryTermsLoader.py",
"diff": "@@ -10,11 +10,7 @@ from utils.TranslatableModelLoader import TranslatableModelLoader\nclass GlossaryTermsLoader(TranslatableModelLoader):\n\"\"\"Custom loader for loading glossary terms.\"\"\"\n-\n- def __init__(self, **kwargs):\n- \"\"\"Create the loader for loading glossary terms.\"\"\"\n- super().__init__(**kwargs)\n- self.FILE_EXTENSION = \".md\"\n+ FILE_EXTENSION = \".md\"\n@transaction.atomic\ndef load(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/topics/management/commands/_LearningOutcomesLoader.py",
"new_path": "csunplugged/topics/management/commands/_LearningOutcomesLoader.py",
"diff": "@@ -13,10 +13,6 @@ from topics.models import (\nclass LearningOutcomesLoader(TranslatableModelLoader):\n\"\"\"Custom loader for loading learning outcomes.\"\"\"\n- def __init__(self, **kwargs):\n- \"\"\"Create the loader for loading learning outcomes.\"\"\"\n- super().__init__(**kwargs)\n-\n@transaction.atomic\ndef load(self):\n\"\"\"Load the content for learning outcomes.\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/topics/management/commands/_ProgrammingChallengesStructureLoader.py",
"new_path": "csunplugged/topics/management/commands/_ProgrammingChallengesStructureLoader.py",
"diff": "@@ -10,10 +10,6 @@ from topics.models import ProgrammingChallengeLanguage, ProgrammingChallengeDiff\nclass ProgrammingChallengesStructureLoader(TranslatableModelLoader):\n\"\"\"Custom loader for loading structure of programming challenges.\"\"\"\n- def __init__(self, **kwargs):\n- \"\"\"Create the loader for loading structure of programming challenges.\"\"\"\n- super().__init__(**kwargs)\n-\n@transaction.atomic\ndef load(self):\n\"\"\"Load the content for structure of programming challenges.\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Remove unnecessary initialisers from BaseResourceLoader subclasses
|
701,855 |
13.11.2017 13:46:21
| -46,800 |
5fe9a41ed004684f27bed63c0b4ed52da0e9d8ff
|
Improve docstring for TranslatableModelLoader.get_yaml_translations
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/utils/TranslatableModelLoader.py",
"new_path": "csunplugged/utils/TranslatableModelLoader.py",
"diff": "@@ -17,13 +17,18 @@ class TranslatableModelLoader(BaseLoader):\ndef get_yaml_translations(self, filename, field_map=None, required_slugs=[], required_fields=[]):\n\"\"\"Get a dictionary of translations for the given filename.\n- Yaml files must be structured as follows:\n- <object-slug>:\n- <field>: <translated value for field 2>\n- <field2>: <translated value for field 2>\n+ Yaml files must be structured\n+\n+ <object-slug-1>:\n+ <field-1>: <translated value for field-1>\n+ <field-2>: <translated value for field-2>\n<object-slug-2>\n...\n+ where [object-slug-1, object-slug-2, ...] are slugs of objects of\n+ the same model (eg. ClassroomResource) and [field-1, field-2, ...]\n+ are the names of Char/TextFields defined on that model.\n+\nArgs:\nfilename: (str) path to yaml file from the working directory of the loader\nfield_map: (dict) optional mapping of field names in yaml file to\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Improve docstring for TranslatableModelLoader.get_yaml_translations
|
701,855 |
15.11.2017 13:42:30
| -46,800 |
45e7d703dba9798d093f8569868decca0babd093
|
Modify config file to include in-context translation pseudo-languages
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/config/settings/base.py",
"new_path": "csunplugged/config/settings/base.py",
"diff": "@@ -12,6 +12,10 @@ https://docs.djangoproject.com/en/dev/ref/settings/\nimport environ\nimport os.path\n+# Add custom languages not provided by Django\n+import django.conf.locale\n+from django.conf import global_settings\n+\n# cs-unplugged/csunplugged/config/settings/base.py - 3 = csunplugged/\nROOT_DIR = environ.Path(__file__) - 3\n@@ -102,10 +106,43 @@ TIME_ZONE = \"UTC\"\n# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code\nLANGUAGE_CODE = \"en\"\n+INCONTEXT_L10N_PSEUDOLANGUAGE = \"xx-lr\"\n+INCONTEXT_L10N_PSEUDOLANGUAGE_BIDI = \"xx-rl\"\n+INCONTEXT_L10N_PSEUDOLANGUAGES = (\n+ INCONTEXT_L10N_PSEUDOLANGUAGE,\n+ INCONTEXT_L10N_PSEUDOLANGUAGE_BIDI\n+)\n+\nLANGUAGES = (\n(\"en\", \"English\"),\n)\n+if env.bool(\"INCLUDE_INCONTEXT_L10N\", True):\n+ EXTRA_LANGUAGES = [\n+ (INCONTEXT_L10N_PSEUDOLANGUAGE, \"In-context translations\"),\n+ (INCONTEXT_L10N_PSEUDOLANGUAGE_BIDI, \"In-context translations (Bidi)\"),\n+ ]\n+\n+ LANGUAGES += tuple(EXTRA_LANGUAGES)\n+\n+ EXTRA_LANG_INFO = {\n+ INCONTEXT_L10N_PSEUDOLANGUAGE: {\n+ 'bidi': False,\n+ 'code': INCONTEXT_L10N_PSEUDOLANGUAGE,\n+ 'name': \"In-context translations\",\n+ 'name_local': \"In-context translations\",\n+ },\n+ INCONTEXT_L10N_PSEUDOLANGUAGE_BIDI: {\n+ 'bidi': True,\n+ 'code': INCONTEXT_L10N_PSEUDOLANGUAGE_BIDI,\n+ 'name': \"In-context translations (Bidi)\",\n+ 'name_local': \"In-context translations (Bidi)\",\n+ }\n+ }\n+\n+ django.conf.locale.LANG_INFO.update(EXTRA_LANG_INFO)\n+ global_settings.LANGUAGES = global_settings.LANGUAGES + EXTRA_LANGUAGES\n+\n# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id\nSITE_ID = 1\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Modify config file to include in-context translation pseudo-languages
|
701,855 |
15.11.2017 18:29:14
| -46,800 |
7d5a7dea43e4c206beee5d49901ef0a192d57d49
|
Add scripts for in-context l10n pseudo-translation download
|
[
{
"change_type": "ADD",
"old_path": "csunplugged/__init__.py",
"new_path": "csunplugged/__init__.py",
"diff": ""
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/download.sh",
"diff": "+#!/bin/bash\n+\n+crowdin download -c \"crowdin_content.yaml\" # .md/.yaml files\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/download_xliff.py",
"diff": "+import os\n+import requests\n+import csunplugged\n+from csunplugged.config.settings.base import INCONTEXT_L10N_PSEUDOLANGUAGE\n+\n+INCONTEXT_L10N_PSEUDOLANGUAGE_CROWDIN = \"en-UD\"\n+API_KEY = os.environ[\"CROWDIN_API_KEY\"]\n+API_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\n+\n+CONTENT_ROOT = \"csunplugged/topics/content\"\n+EN_DIR = os.path.join(CONTENT_ROOT, 'en')\n+XLIFF_DIR = os.path.join(CONTENT_ROOT, 'xliff')\n+\n+\n+def download_xliff(source_filename, dest_filename, language=INCONTEXT_L10N_PSEUDOLANGUAGE_CROWDIN):\n+ params = {\n+ \"key\" : API_KEY,\n+ \"file\": source_filename,\n+ \"language\": language,\n+ \"format\": \"xliff\"\n+ }\n+ response = requests.get(\n+ API_URL.format(method=\"export-file\"),\n+ params=params\n+ )\n+ print(\"Downloading {}\".format(response.url))\n+ xliff_text = response.text.replace('\\x0C', '')\n+ with open(dest_filename, 'w') as f:\n+ f.write(xliff_text)\n+\n+if __name__ == \"__main__\":\n+ if not os.path.exists(XLIFF_DIR):\n+ os.mkdir(XLIFF_DIR)\n+ for root, dirs, files in os.walk(EN_DIR):\n+ for name in files:\n+ if name.endswith(\".md\"):\n+ source_path = os.path.join(root, name)\n+ path_from_language_root = os.path.relpath(source_path, start=EN_DIR)\n+ xliff_path = os.path.join(XLIFF_DIR, path_from_language_root)\n+ xliff_path = os.path.splitext(xliff_path)[0] + \".xliff\"\n+ os.makedirs(os.path.split(xliff_path)[0], exist_ok=True)\n+ # path = os.path.join(root, name)\n+ # xliff_path = os.path.splitext(path)[0] + \".xliff\"\n+ download_xliff(source_path, xliff_path)\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/modify_pseudo_translations.py",
"diff": "+from verto import Verto\n+import re\n+import os\n+from lxml import etree\n+\n+CONTENT_ROOT = \"csunplugged/topics/content\"\n+EN_DIR = os.path.join(CONTENT_ROOT, 'en')\n+PSEUDO_LANGUAGE = \"xx-lr\"\n+PSEUDO_DIR = os.path.join(CONTENT_ROOT, PSEUDO_LANGUAGE)\n+XLIFF_DIR = os.path.join(CONTENT_ROOT, 'xliff')\n+\n+NS_DICT = {\n+ 'ns': \"urn:oasis:names:tc:xliff:document:1.2\"\n+}\n+\n+XLIFF_PARSER = etree.XMLParser()\n+\n+def get_xliff_trans(path):\n+ with open(xliff_path, 'r') as f:\n+ xliff = etree.parse(f, XLIFF_PARSER)\n+ xliff_trans = xliff.xpath(\n+ './/ns:file/ns:body',\n+ namespaces=NS_DICT\n+ )[0]\n+ return xliff_trans\n+\n+\n+def get_verto_block_patterns():\n+ convertor = Verto()\n+ ext = convertor.verto_extension\n+ block_pattern = ext.processor_info['style']['block_pattern']\n+ block_strings = ext.processor_info['style']['strings']['block']\n+ patterns = []\n+ for block_string in block_strings:\n+ c = re.compile(block_pattern.format(**{'block': block_string}))\n+ patterns.append(c)\n+ return patterns\n+\n+def is_block(string, patterns):\n+ for pattern in patterns:\n+ if pattern.search(string):\n+ return True\n+ return False\n+\n+def update_markdown_file(md_path, blocks, no_translate):\n+ with open(md_path, 'r') as f:\n+ md = f.read()\n+\n+ for block_id, block_content in blocks.items():\n+ pattern = r'([ \\t]*)crwdns{0}:0(.*?)crwdne{0}:0'.format(block_id)\n+ c = re.compile(pattern)\n+ new_str = \"\\\\1*BlockTag: crwdns{id}:0crwdne{id}:0*\\n\\n\\\\1{content}\".format(id=block_id, content=block_content)\n+ md = re.sub(c, new_str, md)\n+ print(\"{} - {}\".format(block_id, new_str))\n+\n+ for string_id, string in no_translate.items():\n+ pattern = r'crwdns{0}:0(.*?)crwdne{0}:0'.format(string_id)\n+ c = re.compile(pattern)\n+ # new_str = \"crwdns{id}:0crwdne{id}:0*\\n\\n\\\\1{content}\".format(id=url_id, content=url)\n+ md = re.sub(c, string, md)\n+ print(\"{} - {}\".format(string_id, string))\n+\n+ with open(md_path, 'w') as f:\n+ f.write(md)\n+ print(\"Finished updating {}\".format(md_path))\n+\n+\n+if __name__ == \"__main__\":\n+\n+ # for root, files in ((\"csunplugged/topics/content/en/\", (\"unplugged-programming/programming-challenges/draw-different-types-of-triangles/extra-challenge.md\",)),):\n+ for root, dirs, files in os.walk(EN_DIR):\n+\n+ for name in files:\n+ if name.endswith(\".md\"):\n+ source_md_path = os.path.join(root, name)\n+ path_from_language_root = os.path.relpath(source_md_path, start=EN_DIR)\n+ target_md_path = os.path.join(PSEUDO_DIR, path_from_language_root)\n+ xliff_path = os.path.join(XLIFF_DIR, path_from_language_root)\n+ xliff_path = os.path.splitext(xliff_path)[0] + \".xliff\"\n+ xliff_trans = get_xliff_trans(xliff_path)\n+\n+ blocks = {}\n+ block_patterns = get_verto_block_patterns()\n+\n+ no_translate = {}\n+\n+ for string in xliff_trans:\n+ id = string.attrib[\"id\"]\n+ untranslated = string.find('ns:source', namespaces=NS_DICT).text\n+ if untranslated is not None:\n+ if string.attrib.get(\"translate\") == \"no\":\n+ no_translate[id] = untranslated\n+ elif is_block(untranslated, block_patterns):\n+ blocks[id] = untranslated\n+ update_markdown_file(target_md_path, blocks, no_translate)\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/upload.sh",
"diff": "+#!/bin/bash\n+\n+crowdin upload -c \"crowdin_content.yaml\" # .md/.yaml files\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add scripts for in-context l10n pseudo-translation download
|
701,855 |
15.11.2017 18:31:06
| -46,800 |
096e208f82aba61247c082f373799f941c011a32
|
Update crowdin config to include .po files and pseudo-language mapping
|
[
{
"change_type": "MODIFY",
"old_path": "crowdin_content.yaml",
"new_path": "crowdin_content.yaml",
"diff": "@@ -10,10 +10,28 @@ files: [\n{\nsource: \"/csunplugged/topics/content/en/**/*.yaml\",\ntranslation: \"/csunplugged/topics/content/%two_letters_code%/**/%original_file_name%\",\n-\n+ languages_mapping: {\n+ two_letters_code: {\n+ \"en-UD\": \"xx-lr\"\n+ }\n+ }\n},\n{\nsource: \"/csunplugged/topics/content/en/**/*.md\",\ntranslation: \"/csunplugged/topics/content/%two_letters_code%/**/%original_file_name%\",\n+ languages_mapping: {\n+ two_letters_code: {\n+ \"en-UD\": \"xx-lr\"\n}\n+ }\n+ },\n+ {\n+ source: \"/csunplugged/locale/en/LC_MESSAGES/*.po\",\n+ translation: \"/csunplugged/locale/%two_letters_code%/LC_MESSAGES/%original_file_name%\",\n+ languages_mapping: {\n+ two_letters_code: {\n+ \"en-UD\": \"xx_LR\"\n+ }\n+ }\n+ },\n]\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update crowdin config to include .po files and pseudo-language mapping
|
701,855 |
15.11.2017 18:34:07
| -46,800 |
101df6da091c9d42a9ab0519637dc9e06ffdedb0
|
Add javascript for in-context translation
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/templates/base.html",
"new_path": "csunplugged/templates/base.html",
"diff": "{% get_language_info for LANGUAGE_CODE as current_language %}\n{% get_available_languages as LANGUAGES %}\n+\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<!-- Required meta tags -->\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n-\n+ {% if LANGUAGE_CODE == \"xx-lr\" or LANGUAGE_CODE == \"xx-rl\" %}\n+ <script type=\"text/javascript\">\n+ var _jipt = [];\n+ _jipt.push(['project', 'cs-unplugged']);\n+ </script>\n+ <script type=\"text/javascript\" src=\"//cdn.crowdin.com/jipt/jipt.js\"></script>\n+ {% endif %}\n<title>\n{% block custom_title %}\n{% block title %}{% endblock title %} - {% trans \"CS Unplugged\" %}\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add javascript for in-context translation
|
701,855 |
15.11.2017 19:02:50
| -46,800 |
3a8542e909ad64caef3fc90990cc321122601604
|
Update migrations for in-context localisation
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/topics/migrations/0087_auto_20171115_0551.py",
"diff": "+# -*- coding: utf-8 -*-\n+# Generated by Django 1.11.5 on 2017-11-15 05:51\n+from __future__ import unicode_literals\n+\n+import django.contrib.postgres.fields\n+import django.contrib.postgres.fields.jsonb\n+from django.db import migrations, models\n+\n+\n+class Migration(migrations.Migration):\n+\n+ dependencies = [\n+ ('topics', '0086_auto_20171108_0840'),\n+ ]\n+\n+ operations = [\n+ migrations.RemoveField(\n+ model_name='agegroup',\n+ name='description_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='agegroup',\n+ name='description_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='classroomresource',\n+ name='description_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='classroomresource',\n+ name='description_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumarea',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumarea',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumintegration',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumintegration',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumintegration',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumintegration',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='glossaryterm',\n+ name='definition_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='glossaryterm',\n+ name='definition_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='glossaryterm',\n+ name='term_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='glossaryterm',\n+ name='term_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='learningoutcome',\n+ name='text_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='learningoutcome',\n+ name='text_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='computational_thinking_links_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='computational_thinking_links_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='heading_tree_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='heading_tree_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='programming_challenges_description_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='programming_challenges_description_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='extra_challenge_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='extra_challenge_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengedifficulty',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengedifficulty',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='expected_result_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='expected_result_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='hints_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='hints_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='solution_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='solution_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengelanguage',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengelanguage',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='resourcedescription',\n+ name='description_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='resourcedescription',\n+ name='description_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='other_resources_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='other_resources_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='computational_thinking_links_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='computational_thinking_links_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='heading_tree_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='heading_tree_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='name_fr',\n+ ),\n+ migrations.AddField(\n+ model_name='agegroup',\n+ name='description_xx_lr',\n+ field=models.CharField(default='', max_length=500, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='agegroup',\n+ name='description_xx_rl',\n+ field=models.CharField(default='', max_length=500, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='classroomresource',\n+ name='description_xx_lr',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='classroomresource',\n+ name='description_xx_rl',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='curriculumarea',\n+ name='name_xx_lr',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='curriculumarea',\n+ name='name_xx_rl',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='curriculumintegration',\n+ name='content_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='curriculumintegration',\n+ name='content_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='curriculumintegration',\n+ name='name_xx_lr',\n+ field=models.CharField(default='', max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='curriculumintegration',\n+ name='name_xx_rl',\n+ field=models.CharField(default='', max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='glossaryterm',\n+ name='definition_xx_lr',\n+ field=models.TextField(null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='glossaryterm',\n+ name='definition_xx_rl',\n+ field=models.TextField(null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='glossaryterm',\n+ name='term_xx_lr',\n+ field=models.CharField(max_length=200, null=True, unique=True),\n+ ),\n+ migrations.AddField(\n+ model_name='glossaryterm',\n+ name='term_xx_rl',\n+ field=models.CharField(max_length=200, null=True, unique=True),\n+ ),\n+ migrations.AddField(\n+ model_name='learningoutcome',\n+ name='text_xx_lr',\n+ field=models.CharField(default='', max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='learningoutcome',\n+ name='text_xx_rl',\n+ field=models.CharField(default='', max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='computational_thinking_links_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='computational_thinking_links_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='content_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='content_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='heading_tree_xx_lr',\n+ field=django.contrib.postgres.fields.jsonb.JSONField(default=list, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='heading_tree_xx_rl',\n+ field=django.contrib.postgres.fields.jsonb.JSONField(default=list, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='name_xx_lr',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='name_xx_rl',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='programming_challenges_description_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='lesson',\n+ name='programming_challenges_description_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallenge',\n+ name='content_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallenge',\n+ name='content_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallenge',\n+ name='extra_challenge_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallenge',\n+ name='extra_challenge_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallenge',\n+ name='name_xx_lr',\n+ field=models.CharField(default='', max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallenge',\n+ name='name_xx_rl',\n+ field=models.CharField(default='', max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengedifficulty',\n+ name='name_xx_lr',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengedifficulty',\n+ name='name_xx_rl',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengeimplementation',\n+ name='expected_result_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengeimplementation',\n+ name='expected_result_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengeimplementation',\n+ name='hints_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengeimplementation',\n+ name='hints_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengeimplementation',\n+ name='solution_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengeimplementation',\n+ name='solution_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengelanguage',\n+ name='name_xx_lr',\n+ field=models.CharField(max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='programmingchallengelanguage',\n+ name='name_xx_rl',\n+ field=models.CharField(max_length=200, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='resourcedescription',\n+ name='description_xx_lr',\n+ field=models.CharField(default='', max_length=300, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='resourcedescription',\n+ name='description_xx_rl',\n+ field=models.CharField(default='', max_length=300, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='topic',\n+ name='content_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='topic',\n+ name='content_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='topic',\n+ name='name_xx_lr',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='topic',\n+ name='name_xx_rl',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='topic',\n+ name='other_resources_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='topic',\n+ name='other_resources_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='unitplan',\n+ name='computational_thinking_links_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='unitplan',\n+ name='computational_thinking_links_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='unitplan',\n+ name='content_xx_lr',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='unitplan',\n+ name='content_xx_rl',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='unitplan',\n+ name='heading_tree_xx_lr',\n+ field=django.contrib.postgres.fields.jsonb.JSONField(default=dict, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='unitplan',\n+ name='heading_tree_xx_rl',\n+ field=django.contrib.postgres.fields.jsonb.JSONField(default=dict, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='unitplan',\n+ name='name_xx_lr',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='unitplan',\n+ name='name_xx_rl',\n+ field=models.CharField(default='', max_length=100, null=True),\n+ ),\n+ migrations.AlterField(\n+ model_name='agegroup',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='classroomresource',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='curriculumarea',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='curriculumintegration',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='glossaryterm',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='learningoutcome',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='lesson',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='programmingchallenge',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='programmingchallengedifficulty',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='programmingchallengeimplementation',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='programmingchallengelanguage',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='resourcedescription',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='topic',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='unitplan',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ ]\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update migrations for in-context localisation
|
701,855 |
15.11.2017 19:03:20
| -46,800 |
e0587d44fa08812204658093ebe710f3cdb49622
|
Update makemigrations command to suppress prompts
|
[
{
"change_type": "MODIFY",
"old_path": "csu",
"new_path": "csu",
"diff": "@@ -126,7 +126,7 @@ defhelp -dev flush 'Run Django flush command.'\n# Run Django makemigrations command\ndev_makemigrations() {\necho \"Creating database migrations...\"\n- docker-compose exec django /docker_venv/bin/python3 ./manage.py makemigrations\n+ docker-compose exec django /docker_venv/bin/python3 ./manage.py makemigrations --no-input\n}\ndefhelp -dev makemigrations 'Run Django makemigrations command.'\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update makemigrations command to suppress prompts
|
701,860 |
16.11.2017 18:07:09
| -46,800 |
347a268d17c10880790799e07f0290f05d3d862a
|
Adds images for lesson (fixes
|
[
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/binary_search_books.png",
"new_path": "csunplugged/static/img/topics/binary_search_books.png",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/binary_search_books.png differ\n"
},
{
"change_type": "ADD",
"old_path": "csunplugged/static/img/topics/binary_search_chests.gif",
"new_path": "csunplugged/static/img/topics/binary_search_chests.gif",
"diff": "Binary files /dev/null and b/csunplugged/static/img/topics/binary_search_chests.gif differ\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/topics/content/en/searching-algorithms/sequential-and-binary-search-unit-plan/lessons/the-great-treasure-hunt-sorted.md",
"new_path": "csunplugged/topics/content/en/searching-algorithms/sequential-and-binary-search-unit-plan/lessons/the-great-treasure-hunt-sorted.md",
"diff": "## Key questions\n+{image file-path=\"img/topics/binary_search_books.png\" alt=\"A row of books in alphabetical order.\"}\n+\nHow would you look for a book in a library if the books were sorted in alphabetical order?\nIs that easier than if they were out of order?\n@@ -55,4 +57,6 @@ This is a pleasant contrast to some other problems where we don't have such effi\n## Lesson reflection\n+{image file-path=\"img/topics/binary_search_chests.gif\" alt=\"This animation shows binary search being used to find the chest that holds the number 64.\"}\n+\nWhat is the algorithm for a binary search for the Treasure Hunt game?\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Adds images for lesson (fixes #672)
|
701,855 |
17.11.2017 00:14:05
| -46,800 |
b8d948fb6196bc47b0fa700b18f87675955d56ae
|
Remove unnecessary imports in download_xliff.py script
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/download_xliff.py",
"new_path": "infrastructure/crowdin/download_xliff.py",
"diff": "import os\nimport requests\n-import csunplugged\n-from csunplugged.config.settings.base import INCONTEXT_L10N_PSEUDOLANGUAGE\nINCONTEXT_L10N_PSEUDOLANGUAGE_CROWDIN = \"en-UD\"\nAPI_KEY = os.environ[\"CROWDIN_API_KEY\"]\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Remove unnecessary imports in download_xliff.py script
|
701,855 |
17.11.2017 00:14:54
| -46,800 |
17aabb0fdd2e70842f90848029643fbc9af0599b
|
Add script to upload source files to Crowdin for translation
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/upload-crowdin-source-files.sh",
"diff": "+# Deal with SSH KEYS here\n+ set -e\n+\n+REPO=\"git@github.com:uccser/cs-unplugged.git\"\n+CLONED_REPO_DIR=\"source-upload-cloned-repo\"\n+SOURCE_BRANCH=\"develop\"\n+CROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n+\n+if [ -d \"${CLONED_REPO_DIR}\" ]; then\n+ rm -rf \"${CLONED_REPO_DIR}\"\n+fi\n+git clone \"${REPO}\" \"${CLONED_REPO_DIR}\"\n+\n+cd \"${CLONED_REPO_DIR}\"\n+\n+git checkout \"${SOURCE_BRANCH}\"\n+\n+crowdin upload -c \"${CROWDIN_CONFIG_FILE}\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add script to upload source files to Crowdin for translation
|
701,855 |
17.11.2017 00:15:36
| -46,800 |
98630105ee8f90ff087b6e4fcf6b80d294434bc8
|
Add script to update the in-context pseudo translation files in github
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"diff": "+# Deal with SSH KEYS here\n+ set -e\n+\n+REPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\n+CLONED_REPO_DIR=\"incontext-download-cloned-repo\"\n+CROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n+\n+if [ -d \"${CLONED_REPO_DIR}\" ]; then\n+ rm -rf \"${CLONED_REPO_DIR}\"\n+fi\n+git clone \"${REPO}\" \"${CLONED_REPO_DIR}\"\n+cd \"${CLONED_REPO_DIR}\"\n+\n+SHA=$(git rev-parse --verify HEAD)\n+\n+git config user.name \"Travis CI\"\n+git config user.email \"test@test.com\"\n+\n+SOURCE_BRANCH=\"develop\"\n+TARGET_BRANCH=\"develop-in-context-l10n\"\n+\n+git config user.name \"Travis CI\"\n+git config user.email \"test@test.com\"\n+\n+git checkout $TARGET_BRANCH || git checkout -b $TARGET_BRANCH origin/$SOURCE_BRANCH\n+# Merge if required\n+git merge origin/$SOURCE_BRANCH --quiet --no-edit\n+\n+crowdin -c \"${CROWDIN_CONFIG_FILE}\" download\n+python3 infrastructure/crowdin/download_xliff.py\n+python3 infrastructure/crowdin/modify_pseudo_translations.py\n+\n+git add csunplugged/topics/content/xx-lr\n+\n+# If there are no changes to the compiled out (e.g. this is a README update) then just bail.\n+if [[ $(git diff --cached) ]]; then\n+ git commit -m \"Update in-context l10n: ${SHA}\"\n+ git push -q origin $TARGET_BRANCH > /dev/null\n+fi\n+\n+# If there are no changes to the compiled out (e.g. this is a README update) then just bail.\n+if [[ $(git diff $TARGET_BRANCH origin/$SOURCE_BRANCH) ]]; then\n+ hub pull-request -m \"Update in-context localisation files\" -b \"${SOURCE_BRANCH}\" -h \"${TARGET_BRANCH}\" || \\\n+ echo \"Could not create pull request - perhaps one already exists?\"\n+fi\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add script to update the in-context pseudo translation files in github
|
701,855 |
17.11.2017 00:17:13
| -46,800 |
1f64df178880233f2f81733e6c08049d0ee7b225
|
Add script to pull completed translations from Crowdin and push them GitHub
This script is intended to be run as a cron job, possible on GCE.
Completed translations are added to a new branch off develop
(one branch per language).
A pull request is automatically opened for developer review.
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/get_complete_translations.py",
"diff": "+import os\n+import requests\n+from lxml import etree\n+import sys\n+from django.conf import settings\n+from django.utils import translation\n+\n+settings.configure()\n+\n+API_KEY = os.environ[\"CROWDIN_API_KEY\"]\n+API_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\n+\n+NS_DICT = {\n+ 'ns': \"urn:oasis:names:tc:xliff:document:1.2\"\n+}\n+\n+if len(sys.argv) != 2:\n+ raise Exception(\"Usage: python3 get_completed_translations.py <language code>\")\n+\n+SOURCE_LANGUAGE = \"en\"\n+TARGET_LANGUAGE = sys.argv[1]\n+\n+def get_language_info(language):\n+ params = {\n+ \"key\" : API_KEY,\n+ \"language\": language\n+ }\n+ response = requests.get(\n+ API_URL.format(method=\"language-status\"),\n+ params=params\n+ )\n+ info = etree.fromstring(response.text.encode())\n+ return info\n+\n+def convert_source_language(source_language, path_to_dir):\n+ if path_to_dir == \"csunplugged/locale\":\n+ return translation.to_locale(TARGET_LANGUAGE)\n+ return TARGET_LANGUAGE.lower()\n+\n+def process_item(item, parent_path=None):\n+ if item.find(\"node_type\").text == \"file\":\n+ filename = item.find(\"name\").text\n+ if parent_path:\n+ path = os.path.join(parent_path, filename)\n+ else:\n+ path = filename\n+\n+ # Skip full translated check for *.po - they can always be included\n+ if filename.endswith(\".po\"):\n+ return [path]\n+\n+ if item.find(\"phrases\") != item.find(\"approved\"):\n+ return [path]\n+ else:\n+ return []\n+\n+ else:\n+ inner_nodes = item.find(\"files\")\n+ dirname = item.find(\"name\").text\n+ if dirname == SOURCE_LANGUAGE:\n+ dirname = convert_source_language(dirname, parent_path)\n+ if parent_path:\n+ path = os.path.join(parent_path, dirname)\n+ else:\n+ path = dirname\n+ completed = []\n+ for inner_node in inner_nodes:\n+ completed += process_item(inner_node, parent_path=path)\n+ return completed\n+\n+\n+if __name__ == \"__main__\":\n+ lang_info = get_language_info(TARGET_LANGUAGE)\n+ files = lang_info.find(\"files\")\n+ completed = []\n+ for item in files:\n+ completed += process_item(item)\n+ print('\\n'.join(completed))\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/get_crowdin_languages.py",
"diff": "+import os\n+import requests\n+from lxml import etree\n+\n+API_KEY = os.environ[\"CROWDIN_API_KEY\"]\n+API_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\n+\n+NS_DICT = {\n+ 'ns': \"urn:oasis:names:tc:xliff:document:1.2\"\n+}\n+\n+def get_project_languages():\n+ params = {\n+ \"key\" : API_KEY,\n+ }\n+ response = requests.get(\n+ API_URL.format(method=\"info\"),\n+ params=params\n+ )\n+ info = etree.fromstring(response.text.encode())\n+ languages = info.find('languages')\n+ translatable_languages = []\n+ for language in languages:\n+ # Check it's not the incontext pseudo language\n+ if language.find(\"can_translate\").text == \"1\":\n+ translatable_languages.append(language.find('code').text)\n+ return translatable_languages\n+\n+if __name__ == \"__main__\":\n+ print('\\n'.join(get_project_languages()))\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/update-completed-translations.sh",
"diff": "+set -e\n+set -x\n+\n+REPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\n+CLONED_REPO_DIR=\"translations-download-cloned-repo\"\n+CROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n+CROWDIN_BUILD_DIR=\"crowdin_build\"\n+\n+SOURCE_BRANCH=\"develop\"\n+TARGET_BRANCH_BASE=\"develop-translations\"\n+\n+# Clone repo, deleting old clone if exists\n+if [ -d \"${CLONED_REPO_DIR}\" ]; then\n+ rm -rf \"${CLONED_REPO_DIR}\"\n+fi\n+git clone \"${REPO}\" \"${CLONED_REPO_DIR}\" --branch ${SOURCE_BRANCH}\n+\n+# Copy repo to separate build directory\n+# This keeps it out of the way when changing between branches etc.\n+if [ -d \"${CROWDIN_BUILD_DIR}\" ]; then\n+ rm -rf \"${CROWDIN_BUILD_DIR}\"\n+fi\n+cp -r ${CLONED_REPO_DIR} ${CROWDIN_BUILD_DIR}\n+\n+# Download all translation files from crowdin\n+cd \"${CROWDIN_BUILD_DIR}\"\n+crowdin -c \"${CROWDIN_CONFIG_FILE}\" download\n+\n+# Change into the working repo\n+cd \"../${CLONED_REPO_DIR}\"\n+\n+# Set up git bot parameters\n+# TODO: Change these\n+git config user.name \"Travis CI\"\n+git config user.email \"test@test.com\"\n+\n+# Populate array of all project languages\n+languages=($(python3 infrastructure/crowdin/get_crowdin_languages.py))\n+\n+\n+for language in ${languages[@]}; do\n+\n+ # The branch for new translationss\n+ TARGET_BRANCH=\"${TARGET_BRANCH_BASE}-${language}\"\n+\n+ # Checkout the translation branch, creating if off $SOURCE_BRANCH if it didn't already exist\n+ git checkout $TARGET_BRANCH || git checkout -b $TARGET_BRANCH $SOURCE_BRANCH\n+\n+ # Merge if required\n+ git merge $SOURCE_BRANCH --quiet --no-edit\n+\n+ # Overwrite directory tree with saved built version\n+ cp -r \"../${CROWDIN_BUILD_DIR}/csunplugged\" .\n+\n+ # Get list of files that are completely translated/ready for committing\n+ # Note that .po files are included even if not completely translated\n+ python3 infrastructure/crowdin/get_complete_translations.py \"${language}\" > \"${language}_completed\"\n+\n+\n+ changes=0\n+ # Loop through each completed translation file:\n+ while read path; do\n+ # If file is different to what's already on the branch, commit it\n+ git add \"${path}\" >/dev/null 2>&1 || true\n+ if [[ $(git diff --cached -- \"${path}\") ]]; then\n+ git commit -m \"New translations for ${path}\"\n+ changes=1\n+ fi\n+ done < \"${language}_completed\"\n+\n+ # If any changes were made, push to github\n+ if [[ $changes -eq 1 ]]; then\n+ git push -q origin $TARGET_BRANCH > /dev/null\n+ fi\n+\n+ # If the target branch differs from the source branch, create a PR\n+ if [[ $(git diff $TARGET_BRANCH $SOURCE_BRANCH) ]]; then\n+ hub pull-request -m \"Updated translations for ${language}\" -b \"${SOURCE_BRANCH}\" -h \"${TARGET_BRANCH}\" || \\\n+ echo \"Could not create pull request - perhaps one already exists?\"\n+ fi\n+\n+ # Return repo to clean state for next language\n+ git reset --hard\n+ git clean -fd\n+\n+done\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add script to pull completed translations from Crowdin and push them GitHub
This script is intended to be run as a cron job, possible on GCE.
Completed translations are added to a new branch off develop
(one branch per language).
A pull request is automatically opened for developer review.
|
701,855 |
17.11.2017 17:44:09
| -46,800 |
4a35806f41800eed1f6d1ebec7519721cc84a968
|
Update crowdin scripts, WIP
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/get_complete_translations.py",
"new_path": "infrastructure/crowdin/get_complete_translations.py",
"diff": "@@ -4,6 +4,7 @@ from lxml import etree\nimport sys\nfrom django.conf import settings\nfrom django.utils import translation\n+import language_map\nsettings.configure()\n@@ -15,7 +16,7 @@ NS_DICT = {\n}\nif len(sys.argv) != 2:\n- raise Exception(\"Usage: python3 get_completed_translations.py <language code>\")\n+ raise Exception(\"Usage: python3 get_completed_translations.py <crowdin language code>\")\nSOURCE_LANGUAGE = \"en\"\nTARGET_LANGUAGE = sys.argv[1]\n@@ -32,10 +33,6 @@ def get_language_info(language):\ninfo = etree.fromstring(response.text.encode())\nreturn info\n-def convert_source_language(source_language, path_to_dir):\n- if path_to_dir == \"csunplugged/locale\":\n- return translation.to_locale(TARGET_LANGUAGE)\n- return TARGET_LANGUAGE.lower()\ndef process_item(item, parent_path=None):\nif item.find(\"node_type\").text == \"file\":\n@@ -49,7 +46,7 @@ def process_item(item, parent_path=None):\nif filename.endswith(\".po\"):\nreturn [path]\n- if item.find(\"phrases\") != item.find(\"approved\"):\n+ if item.find(\"phrases\") == item.find(\"approved\"):\nreturn [path]\nelse:\nreturn []\n@@ -58,7 +55,7 @@ def process_item(item, parent_path=None):\ninner_nodes = item.find(\"files\")\ndirname = item.find(\"name\").text\nif dirname == SOURCE_LANGUAGE:\n- dirname = convert_source_language(dirname, parent_path)\n+ dirname = language_map.from_crowdin(TARGET_LANGUAGE)\nif parent_path:\npath = os.path.join(parent_path, dirname)\nelse:\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/language_map.py",
"diff": "+import sys\n+\n+# In general, this is crowdin-osx-locale -> crowdin-code, except for some\n+# special cases like Simplified/Traditional Chinese, which also need to be\n+# overriden in the crowdin.yaml file, using the language mapping parameter\n+\n+# The base list was generated from https://api.crowdin.com/api/supported-languages?json=True\n+\n+FROM_CROWDIN_MAP = {\n+ \"aa\": \"aa\",\n+ \"ach\": \"ach\",\n+ \"ae\": \"ae\",\n+ \"af\": \"af\",\n+ \"ak\": \"ak\",\n+ \"am\": \"am\",\n+ \"an\": \"an\",\n+ \"ar\": \"ar\",\n+ \"ar-BH\": \"ar_BH\",\n+ \"ar-EG\": \"ar_EG\",\n+ \"ar-SA\": \"ar_SA\",\n+ \"ar-YE\": \"ar_YE\",\n+ \"arn\": \"arn\",\n+ \"as\": \"as\",\n+ \"ast\": \"ast\",\n+ \"av\": \"av\",\n+ \"ay\": \"ay\",\n+ \"az\": \"az\",\n+ \"ba\": \"ba\",\n+ \"bal\": \"bal\",\n+ \"ban\": \"ban\",\n+ \"be\": \"be\",\n+ \"ber\": \"ber\",\n+ \"bfo\": \"bfo\",\n+ \"bg\": \"bg\",\n+ \"bh\": \"bh\",\n+ \"bi\": \"bi\",\n+ \"bm\": \"bm\",\n+ \"bn\": \"bn\",\n+ \"bn-IN\": \"bn_IN\",\n+ \"bo-BT\": \"bo\",\n+ \"br-FR\": \"br\",\n+ \"bs\": \"bs\",\n+ \"ca\": \"ca\",\n+ \"ce\": \"ce\",\n+ \"ceb\": \"ceb\",\n+ \"ch\": \"ch\",\n+ \"chr\": \"chr\",\n+ \"ckb\": \"ckb\",\n+ \"co\": \"co\",\n+ \"cr\": \"cr\",\n+ \"crs\": \"crs\",\n+ \"cs\": \"cs\",\n+ \"csb\": \"csb\",\n+ \"cv\": \"cv\",\n+ \"cy\": \"cy\",\n+ \"da\": \"da\",\n+ \"de\": \"de\",\n+ \"de-AT\": \"de_AT\",\n+ \"de-BE\": \"de_BE\",\n+ \"de-CH\": \"de_CH\",\n+ \"de-LI\": \"de_LI\",\n+ \"de-LU\": \"de_LU\",\n+ \"dsb-DE\": \"dsb\",\n+ \"dv\": \"dv\",\n+ \"dz\": \"dz\",\n+ \"ee\": \"ee\",\n+ \"el\": \"el\",\n+ \"el-CY\": \"el_CY\",\n+ \"en\": \"en\",\n+ \"en-AR\": \"en_AR\",\n+ \"en-AU\": \"en_AU\",\n+ \"en-BZ\": \"en_BZ\",\n+ \"en-CA\": \"en_CA\",\n+ \"en-CB\": \"en_CB\",\n+ \"en-CN\": \"en_CN\",\n+ \"en-DK\": \"en_DK\",\n+ \"en-GB\": \"en_GB\",\n+ \"en-HK\": \"en_HK\",\n+ \"en-ID\": \"en_ID\",\n+ \"en-IE\": \"en_IE\",\n+ \"en-IN\": \"en_IN\",\n+ \"en-JA\": \"en_JA\",\n+ \"en-JM\": \"en_JM\",\n+ \"en-MY\": \"en_MY\",\n+ \"en-NO\": \"en_NO\",\n+ \"en-NZ\": \"en_NZ\",\n+ \"en-PH\": \"en_PH\",\n+ \"en-PR\": \"en_PR\",\n+ \"en-PT\": \"en_PT\",\n+ \"en-SE\": \"en_SE\",\n+ \"en-SG\": \"en_SG\",\n+ \"en-UD\": \"xx_LR\", # Modified, for the in context translation pseudo language\n+ \"en-US\": \"en_US\",\n+ \"en-ZA\": \"en_ZA\",\n+ \"en-ZW\": \"en_ZW\",\n+ \"eo\": \"eo\",\n+ \"es-AR\": \"es_AR\",\n+ \"es-BO\": \"es_BO\",\n+ \"es-CL\": \"es_CL\",\n+ \"es-CO\": \"es_CO\",\n+ \"es-CR\": \"es_CR\",\n+ \"es-DO\": \"es_DO\",\n+ \"es-EC\": \"es_EC\",\n+ \"es-EM\": \"es_EM\",\n+ \"es-ES\": \"es\",\n+ \"es-GT\": \"es_GT\",\n+ \"es-HN\": \"es_HN\",\n+ \"es-MX\": \"es_MX\",\n+ \"es-NI\": \"es_NI\",\n+ \"es-PA\": \"es_PA\",\n+ \"es-PE\": \"es_PE\",\n+ \"es-PR\": \"es_PR\",\n+ \"es-PY\": \"es_PY\",\n+ \"es-SV\": \"es_SV\",\n+ \"es-US\": \"es_US\",\n+ \"es-UY\": \"es_UY\",\n+ \"es-VE\": \"es_VE\",\n+ \"et\": \"et\",\n+ \"eu\": \"eu\",\n+ \"fa\": \"fa\",\n+ \"fa-AF\": \"fa_AF\",\n+ \"ff\": \"ff\",\n+ \"fi\": \"fi\",\n+ \"fil\": \"fil\",\n+ \"fj\": \"fj\",\n+ \"fo\": \"fo\",\n+ \"fr\": \"fr\",\n+ \"fr-BE\": \"fr_BE\",\n+ \"fr-CA\": \"fr_CA\",\n+ \"fr-CH\": \"fr_CH\",\n+ \"fr-LU\": \"fr_LU\",\n+ \"fr-QC\": \"fr_QC\",\n+ \"fra-DE\": \"fra\",\n+ \"frp\": \"frp\",\n+ \"fur-IT\": \"fur\",\n+ \"fy-NL\": \"fy\",\n+ \"ga-IE\": \"ga\",\n+ \"gaa\": \"gaa\",\n+ \"gd\": \"gd\",\n+ \"gl\": \"gl\",\n+ \"gn\": \"gn\",\n+ \"got\": \"got\",\n+ \"gu-IN\": \"gu\",\n+ \"gv\": \"gv\",\n+ \"ha\": \"ha\",\n+ \"haw\": \"haw\",\n+ \"he\": \"he\",\n+ \"hi\": \"hi\",\n+ \"hil\": \"hil\",\n+ \"hmn\": \"hmn\",\n+ \"ho\": \"ho\",\n+ \"hr\": \"hr\",\n+ \"hsb-DE\": \"hsb\",\n+ \"ht\": \"ht\",\n+ \"hu\": \"hu\",\n+ \"hy-AM\": \"hy\",\n+ \"hz\": \"hz\",\n+ \"id\": \"id\",\n+ \"ido\": \"ido\",\n+ \"ig\": \"ig\",\n+ \"ii\": \"ii\",\n+ \"ilo\": \"ilo\",\n+ \"is\": \"is\",\n+ \"it\": \"it\",\n+ \"it-CH\": \"it_CH\",\n+ \"iu\": \"iu\",\n+ \"ja\": \"ja\",\n+ \"jbo\": \"jbo\",\n+ \"jv\": \"jv\",\n+ \"ka\": \"ka\",\n+ \"kab\": \"kab\",\n+ \"kdh\": \"kdh\",\n+ \"kg\": \"kg\",\n+ \"kj\": \"kj\",\n+ \"kk\": \"kk\",\n+ \"kl\": \"kl\",\n+ \"km\": \"km\",\n+ \"kmr\": \"kmr\",\n+ \"kn\": \"kn\",\n+ \"ko\": \"ko\",\n+ \"kok\": \"kok\",\n+ \"ks\": \"ks\",\n+ \"ks-PK\": \"ks_PK\",\n+ \"ku\": \"ku\",\n+ \"kv\": \"kv\",\n+ \"kw\": \"kw\",\n+ \"ky\": \"ky\",\n+ \"la-LA\": \"la\",\n+ \"lb\": \"lb\",\n+ \"lg\": \"lg\",\n+ \"li\": \"li\",\n+ \"lij\": \"lij\",\n+ \"ln\": \"ln\",\n+ \"lo\": \"lo\",\n+ \"lol\": \"lol\",\n+ \"lt\": \"lt\",\n+ \"luy\": \"luy\",\n+ \"lv\": \"lv\",\n+ \"mai\": \"mai\",\n+ \"me\": \"me\",\n+ \"mg\": \"mg\",\n+ \"mh\": \"mh\",\n+ \"mi\": \"mi\",\n+ \"mk\": \"mk\",\n+ \"ml-IN\": \"ml\",\n+ \"mn\": \"mn\",\n+ \"moh\": \"moh\",\n+ \"mos\": \"mos\",\n+ \"mr\": \"mr\",\n+ \"ms\": \"ms\",\n+ \"ms-BN\": \"ms_BN\",\n+ \"mt\": \"mt\",\n+ \"my\": \"my\",\n+ \"na\": \"na\",\n+ \"nb\": \"nb\",\n+ \"nds\": \"nds\",\n+ \"ne-IN\": \"ne_IN\",\n+ \"ne-NP\": \"ne\",\n+ \"ng\": \"ng\",\n+ \"nl\": \"nl\",\n+ \"nl-BE\": \"nl_BE\",\n+ \"nl-SR\": \"nl_SR\",\n+ \"nn-NO\": \"nn_NO\",\n+ \"no\": \"no\",\n+ \"nr\": \"nr\",\n+ \"nso\": \"nso\",\n+ \"ny\": \"ny\",\n+ \"oc\": \"oc\",\n+ \"oj\": \"oj\",\n+ \"om\": \"om\",\n+ \"or\": \"or\",\n+ \"os\": \"os\",\n+ \"pa-IN\": \"pa\",\n+ \"pa-PK\": \"pa_PK\",\n+ \"pam\": \"pam\",\n+ \"pap\": \"pap\",\n+ \"pcm\": \"pcm\",\n+ \"pi\": \"pi\",\n+ \"pl\": \"pl\",\n+ \"ps\": \"ps\",\n+ \"pt-BR\": \"pt_BR\",\n+ \"pt-PT\": \"pt\",\n+ \"qu\": \"qu\",\n+ \"quc\": \"quc\",\n+ \"qya-AA\": \"qya\",\n+ \"rm-CH\": \"rm\",\n+ \"rn\": \"rn\",\n+ \"ro\": \"ro\",\n+ \"ru\": \"ru\",\n+ \"ru-BY\": \"ru_BY\",\n+ \"ru-MD\": \"ru_MD\",\n+ \"ru-UA\": \"ru_UA\",\n+ \"rw\": \"rw\",\n+ \"ry-UA\": \"ry\",\n+ \"sa\": \"sa\",\n+ \"sah\": \"sah\",\n+ \"sat\": \"sat\",\n+ \"sc\": \"sc\",\n+ \"sco\": \"sco\",\n+ \"sd\": \"sd\",\n+ \"se\": \"se\",\n+ \"sg\": \"sg\",\n+ \"sh\": \"sh\",\n+ \"si-LK\": \"si\",\n+ \"sk\": \"sk\",\n+ \"sl\": \"sl\",\n+ \"sma\": \"sma\",\n+ \"sn\": \"sn\",\n+ \"so\": \"so\",\n+ \"son\": \"son\",\n+ \"sq\": \"sq\",\n+ \"sr\": \"sr\",\n+ \"sr-CS\": \"sr_CS\",\n+ \"sr-Cyrl-ME\": \"sr_Cyrl_ME\",\n+ \"ss\": \"ss\",\n+ \"st\": \"st\",\n+ \"su\": \"su\",\n+ \"sv-FI\": \"sv_FI\",\n+ \"sv-SE\": \"sv\",\n+ \"sw\": \"sw\",\n+ \"sw-KE\": \"sw_KE\",\n+ \"sw-TZ\": \"sw_TZ\",\n+ \"syc\": \"syc\",\n+ \"ta\": \"ta\",\n+ \"tay\": \"tay\",\n+ \"te\": \"te\",\n+ \"tg\": \"tg\",\n+ \"th\": \"th\",\n+ \"ti\": \"ti\",\n+ \"tk\": \"tk\",\n+ \"tl\": \"tl\",\n+ \"tlh-AA\": \"tlh\",\n+ \"tn\": \"tn\",\n+ \"tr\": \"tr\",\n+ \"tr-CY\": \"tr_CY\",\n+ \"ts\": \"ts\",\n+ \"tt-RU\": \"tt\",\n+ \"tw\": \"tw\",\n+ \"ty\": \"ty\",\n+ \"tzl\": \"tzl\",\n+ \"ug\": \"ug\",\n+ \"uk\": \"uk\",\n+ \"ur-IN\": \"ur_IN\",\n+ \"ur-PK\": \"ur\",\n+ \"uz\": \"uz\",\n+ \"val-ES\": \"val\",\n+ \"ve\": \"ve\",\n+ \"vec\": \"vec\",\n+ \"vi\": \"vi\",\n+ \"vls-BE\": \"vls\",\n+ \"wa\": \"wa\",\n+ \"wo\": \"wo\",\n+ \"xh\": \"xh\",\n+ \"yi\": \"yi\",\n+ \"yo\": \"yo\",\n+ \"zea\": \"zea\",\n+ \"zh-CN\": \"zh_Hans\", # Modified\n+ \"zh-HK\": \"zh_HK\",\n+ \"zh-MO\": \"zh_MO\",\n+ \"zh-SG\": \"zh_SG\",\n+ \"zh-TW\": \"zh_Hant\", # Modified\n+ \"zu\": \"zu\"\n+}\n+\n+def from_crowdin(crowdin_code):\n+ return FROM_CROWDIN_MAP[crowdin_code]\n+\n+if __name__ == \"__main__\":\n+ if len(sys.argv) != 2:\n+ raise Exception(\"Missing argument\\n\\nUsage: python3 language_map.py <crowdin language code>\")\n+ crowdin_code = sys.argv[1]\n+ try:\n+ print(from_crowdin(crowdin_code))\n+ except KeyError:\n+ raise Exception(\"No mapping found for {}\".format(crowdin_code))\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/modify_pseudo_translations.py",
"new_path": "infrastructure/crowdin/modify_pseudo_translations.py",
"diff": "@@ -5,7 +5,7 @@ from lxml import etree\nCONTENT_ROOT = \"csunplugged/topics/content\"\nEN_DIR = os.path.join(CONTENT_ROOT, 'en')\n-PSEUDO_LANGUAGE = \"xx-lr\"\n+PSEUDO_LANGUAGE = \"xx_LR\"\nPSEUDO_DIR = os.path.join(CONTENT_ROOT, PSEUDO_LANGUAGE)\nXLIFF_DIR = os.path.join(CONTENT_ROOT, 'xliff')\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-completed-translations.sh",
"new_path": "infrastructure/crowdin/update-completed-translations.sh",
"diff": "@@ -4,30 +4,23 @@ set -x\nREPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\nCLONED_REPO_DIR=\"translations-download-cloned-repo\"\nCROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n-CROWDIN_BUILD_DIR=\"crowdin_build\"\nSOURCE_BRANCH=\"develop\"\nTARGET_BRANCH_BASE=\"develop-translations\"\n+CONTENT_PATHS=(\n+ \"csunplugged/topics/content\"\n+ \"csunplugged/locale\"\n+)\n+\n# Clone repo, deleting old clone if exists\nif [ -d \"${CLONED_REPO_DIR}\" ]; then\nrm -rf \"${CLONED_REPO_DIR}\"\nfi\ngit clone \"${REPO}\" \"${CLONED_REPO_DIR}\" --branch ${SOURCE_BRANCH}\n-# Copy repo to separate build directory\n-# This keeps it out of the way when changing between branches etc.\n-if [ -d \"${CROWDIN_BUILD_DIR}\" ]; then\n- rm -rf \"${CROWDIN_BUILD_DIR}\"\n-fi\n-cp -r ${CLONED_REPO_DIR} ${CROWDIN_BUILD_DIR}\n-\n-# Download all translation files from crowdin\n-cd \"${CROWDIN_BUILD_DIR}\"\n-crowdin -c \"${CROWDIN_CONFIG_FILE}\" download\n-\n# Change into the working repo\n-cd \"../${CLONED_REPO_DIR}\"\n+cd \"${CLONED_REPO_DIR}\"\n# Set up git bot parameters\n# TODO: Change these\n@@ -35,8 +28,7 @@ git config user.name \"Travis CI\"\ngit config user.email \"test@test.com\"\n# Populate array of all project languages\n-languages=($(python3 infrastructure/crowdin/get_crowdin_languages.py))\n-\n+languages=($(python3 ../get_crowdin_languages.py))\nfor language in ${languages[@]}; do\n@@ -49,15 +41,33 @@ for language in ${languages[@]}; do\n# Merge if required\ngit merge $SOURCE_BRANCH --quiet --no-edit\n- # Overwrite directory tree with saved built version\n- cp -r \"../${CROWDIN_BUILD_DIR}/csunplugged\" .\n+ # Delete existing translation directories\n+ mapped_code=$(python3 ../language_map.py ${language})\n+ for content_path in \"${CONTENT_PATHS[@]}\"; do\n+ translation_path=\"${content_path}/${mapped_code}\"\n+ if [ -d \"${translation_path}\" ]; then\n+ rm -r \"${translation_path}\"\n+ fi\n+ done\n+\n+ # Download translations from crowdin\n+ crowdin -c \"${CROWDIN_CONFIG_FILE}\" -l \"${language}\" download\n+\n+ # Boolean flag indicating whether changes are made that should be pushed\n+ changes=0\n+\n+ # If there are any files that were not re-downloaded from crowdin, they\n+ # no longer exist on the translation server - delete them\n+ if [[ $(git ls-files --deleted) ]]; then\n+ git rm $(git ls-files --deleted)\n+ git commit -m \"Deleting old translation files no longer present on Crowdin\"\n+ changes=1\n+ fi\n# Get list of files that are completely translated/ready for committing\n# Note that .po files are included even if not completely translated\n- python3 infrastructure/crowdin/get_complete_translations.py \"${language}\" > \"${language}_completed\"\n-\n+ python3 ../get_complete_translations.py \"${language}\" > \"${language}_completed\"\n- changes=0\n# Loop through each completed translation file:\nwhile read path; do\n# If file is different to what's already on the branch, commit it\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"new_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"diff": "@@ -5,6 +5,9 @@ REPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\nCLONED_REPO_DIR=\"incontext-download-cloned-repo\"\nCROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n+CROWDIN_PSEUDO_LANGUAGE=\"en-UD\"\n+CSU_PSEUDO_LANGUAGE=\"xx_LR\"\n+\nif [ -d \"${CLONED_REPO_DIR}\" ]; then\nrm -rf \"${CLONED_REPO_DIR}\"\nfi\n@@ -26,11 +29,11 @@ git checkout $TARGET_BRANCH || git checkout -b $TARGET_BRANCH origin/$SOURCE_BRA\n# Merge if required\ngit merge origin/$SOURCE_BRANCH --quiet --no-edit\n-crowdin -c \"${CROWDIN_CONFIG_FILE}\" download\n-python3 infrastructure/crowdin/download_xliff.py\n-python3 infrastructure/crowdin/modify_pseudo_translations.py\n+crowdin -c \"${CROWDIN_CONFIG_FILE}\" -l \"${CROWDIN_PSEUDO_LANGUAGE}\" download\n+python3 ../download_xliff.py\n+python3 ../modify_pseudo_translations.py\n-git add csunplugged/topics/content/xx-lr\n+git add \"csunplugged/topics/content/${CSU_PSEUDO_LANGUAGE}\"\n# If there are no changes to the compiled out (e.g. this is a README update) then just bail.\nif [[ $(git diff --cached) ]]; then\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update crowdin scripts, WIP
|
701,855 |
17.11.2017 17:45:30
| -46,800 |
f9d76e18cc76ed9d689372ff56c59fb0f3bd3e5f
|
Update crowdin_content.yaml to use osx-locale instead of two-letter-code
osx-locale is the closest mapping to the locale codes that Django uses,
and does not restrict us from using multiple languages with the same
two letter code
Details on osx locale codes can be found here:
|
[
{
"change_type": "MODIFY",
"old_path": "crowdin_content.yaml",
"new_path": "crowdin_content.yaml",
"diff": "# Project settings\nproject_identifier: \"cs-unplugged\"\napi_key_env: \"CROWDIN_API_KEY\"\n-base_path: \"\"\n# Preserve directory tree during upload\npreserve_hierarchy: true\n@@ -9,28 +8,34 @@ preserve_hierarchy: true\nfiles: [\n{\nsource: \"/csunplugged/topics/content/en/**/*.yaml\",\n- translation: \"/csunplugged/topics/content/%two_letters_code%/**/%original_file_name%\",\n+ translation: \"/csunplugged/topics/content/%osx_locale%/**/%original_file_name%\",\nlanguages_mapping: {\ntwo_letters_code: {\n- \"en-UD\": \"xx-lr\"\n+ \"en-UD\": \"xx_LR\", # Pseudo language\n+ \"zh-CN\": \"zh_Hans\",\n+ \"zh-TW\": \"zh_Hant\"\n}\n}\n},\n{\nsource: \"/csunplugged/topics/content/en/**/*.md\",\n- translation: \"/csunplugged/topics/content/%two_letters_code%/**/%original_file_name%\",\n+ translation: \"/csunplugged/topics/content/%osx_locale%/**/%original_file_name%\",\nlanguages_mapping: {\ntwo_letters_code: {\n- \"en-UD\": \"xx-lr\"\n+ \"en-UD\": \"xx_LR\", # Pseudo language\n+ \"zh-CN\": \"zh_Hans\",\n+ \"zh-TW\": \"zh_Hant\"\n}\n}\n},\n{\nsource: \"/csunplugged/locale/en/LC_MESSAGES/*.po\",\n- translation: \"/csunplugged/locale/%two_letters_code%/LC_MESSAGES/%original_file_name%\",\n+ translation: \"/csunplugged/locale/%osx_locale%/LC_MESSAGES/%original_file_name%\",\nlanguages_mapping: {\ntwo_letters_code: {\n- \"en-UD\": \"xx_LR\"\n+ \"en-UD\": \"xx_LR\", # Pseudo language\n+ \"zh-CN\": \"zh_Hans\",\n+ \"zh-TW\": \"zh_Hant\"\n}\n}\n},\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update crowdin_content.yaml to use osx-locale instead of two-letter-code
osx-locale is the closest mapping to the locale codes that Django uses,
and does not restrict us from using multiple languages with the same
two letter code
Details on osx locale codes can be found here:
https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html
|
701,855 |
18.11.2017 09:46:47
| -46,800 |
ca14916b4148bfe434d3107991f1a2b7330a2d55
|
Add script to list files on crowdin that are no longer required
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/get-unused-crowdin-files.sh",
"diff": "+# Deal with SSH KEYS here\n+ set -e\n+\n+ REPO=\"git@github.com:uccser/cs-unplugged.git\"\n+ CLONED_REPO_DIR=\"get-unused-crowdin-files-cloned-repo\"\n+ SOURCE_BRANCH=\"develop\"\n+ CROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n+\n+ if [ -d \"${CLONED_REPO_DIR}\" ]; then\n+ rm -rf \"${CLONED_REPO_DIR}\"\n+ fi\n+ git clone \"${REPO}\" \"${CLONED_REPO_DIR}\"\n+\n+ cd \"${CLONED_REPO_DIR}\"\n+\n+git checkout \"${SOURCE_BRANCH}\"\n+\n+python3 ../get_crowdin_files.py | sort > all_crowdin_files\n+crowdin -c \"${CROWDIN_CONFIG_FILE}\" --dryrun upload | sort > current_crowdin_files\n+\n+diff --new-line-format=\"\" --unchanged-line-format=\"\" all_crowdin_files current_crowdin_files > unused_crowdin_files\n+\n+cat unused_crowdin_files\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/get_crowdin_files.py",
"diff": "+import os\n+import requests\n+from lxml import etree\n+import sys\n+import language_map\n+\n+API_KEY = os.environ[\"CROWDIN_API_KEY\"]\n+API_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\n+\n+def get_project_info():\n+ params = {\n+ \"key\" : API_KEY,\n+ }\n+ response = requests.get(\n+ API_URL.format(method=\"info\"),\n+ params=params\n+ )\n+ info = etree.fromstring(response.text.encode())\n+ return info\n+\n+\n+def process_item(item, parent_path=\"/\"):\n+ if item.find(\"node_type\").text == \"file\":\n+ filename = item.find(\"name\").text\n+ path = os.path.join(parent_path, filename)\n+ return [path]\n+ else:\n+ inner_nodes = item.find(\"files\")\n+ dirname = item.find(\"name\").text\n+ path = os.path.join(parent_path, dirname)\n+ files = []\n+ for inner_node in inner_nodes:\n+ files += process_item(inner_node, parent_path=path)\n+ return files\n+\n+\n+if __name__ == \"__main__\":\n+ proj_info = get_project_info()\n+ files_elem = proj_info.find(\"files\")\n+ file_paths = []\n+ for item in files_elem:\n+ file_paths += process_item(item)\n+ print('\\n'.join(file_paths))\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add script to list files on crowdin that are no longer required
|
701,855 |
18.11.2017 12:35:31
| -46,800 |
e59927ec872ef6b7f59a8d55dee1bea613083b3e
|
Add config file for crowdin scripts
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/config.sh",
"diff": "+# CS Unplugged repo\n+REPO=\"git@github.com:uccser/cs-unplugged.git\"\n+\n+# Branch for upload of source content to crowdin\n+TRANSLATION_SOURCE_BRANCH=\"develop\"\n+\n+# Branch that new translations will be merged into\n+TRANSLATION_TARGET_BRANCH=\"develop\"\n+\n+# Branch that new metadata for in context localisation will be merged into\n+IN_CONTEXT_L10N_TARGET_BRANCH=\"develop\"\n+\n+# Name of crowdin config file\n+CROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n+\n+# Code for in-context localisation pseudo language on Crowdin\n+CROWDIN_PSEUDO_LANGUAGE=\"en-UD\"\n+\n+# Code for in-context localisation pseudo language on CS Unplugged\n+CSU_PSEUDO_LANGUAGE=\"xx_LR\"\n+\n+# GitHub Bot Parameters\n+GITHUB_BOT_EMAIL=\"33709036+uccser-bot@users.noreply.github.com\"\n+GITHUB_BOT_NAME=\"UCCSER Bot\"\n+\n+# Paths under which translated content lives\n+CONTENT_PATHS=(\n+ \"csunplugged/topics/content\"\n+ \"csunplugged/locale\"\n+)\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add config file for crowdin scripts
|
701,855 |
18.11.2017 12:36:06
| -46,800 |
20bb62804a3cf9bc0b9dbaa8e38449e0ad7e102d
|
Add util function to reset existing git directory to like-clone state
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/utils.sh",
"diff": "+reset_repo() {\n+ repo_dir=$1\n+ branch=$2\n+\n+ git -C \"${repo_dir}\" fetch --prune\n+ git -C \"${repo_dir}\" reset --hard\n+ git -C \"${repo_dir}\" clean -d --force\n+\n+ # Either create branch, or reset existing branch to origin state\n+ git -C \"${repo_dir}\" checkout -B \"${branch}\" \"origin/${branch}\"\n+\n+ # Delete all local branches except for current branch\n+ if git -C \"${repo_dir}\" branch | grep -v \"^*\"; then\n+ git -C \"${repo_dir}\" branch | grep -v \"^*\" | xargs git -C \"${repo_dir}\" branch -D\n+ fi\n+}\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add util function to reset existing git directory to like-clone state
|
701,855 |
18.11.2017 12:36:53
| -46,800 |
1d3f0fe01d47f086a87503e440ea22130a8dc842
|
Update scripts to not clone repo every time
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/get-unused-crowdin-files.sh",
"new_path": "infrastructure/crowdin/get-unused-crowdin-files.sh",
"diff": "-# Deal with SSH KEYS here\nset -e\n+set -x\n+\n+source config.sh\n+source utils.sh\n- REPO=\"git@github.com:uccser/cs-unplugged.git\"\nCLONED_REPO_DIR=\"get-unused-crowdin-files-cloned-repo\"\n- SOURCE_BRANCH=\"develop\"\n- CROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n+# Clone repo, deleting old clone if exists\nif [ -d \"${CLONED_REPO_DIR}\" ]; then\n- rm -rf \"${CLONED_REPO_DIR}\"\n+ reset_repo \"${CLONED_REPO_DIR}\" \"${TRANSLATION_SOURCE_BRANCH}\"\n+else\n+ git clone \"${REPO}\" \"${CLONED_REPO_DIR}\" --branch ${TRANSLATION_SOURCE_BRANCH}\nfi\n- git clone \"${REPO}\" \"${CLONED_REPO_DIR}\"\ncd \"${CLONED_REPO_DIR}\"\n-git checkout \"${SOURCE_BRANCH}\"\n-\npython3 ../get_crowdin_files.py | sort > all_crowdin_files\ncrowdin -c \"${CROWDIN_CONFIG_FILE}\" --dryrun upload | sort > current_crowdin_files\n-diff --new-line-format=\"\" --unchanged-line-format=\"\" all_crowdin_files current_crowdin_files > unused_crowdin_files\n+# Diff returns exit code 1 if diff found - don't abort script if that is the case\n+diff --new-line-format=\"\" --unchanged-line-format=\"\" all_crowdin_files current_crowdin_files > unused_crowdin_files || [ $? -eq 1 ]\n+echo \"Files present on Crowdin that are unused (i.e. do not match any current english source file):\"\ncat unused_crowdin_files\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-completed-translations.sh",
"new_path": "infrastructure/crowdin/update-completed-translations.sh",
"diff": "set -e\nset -x\n+source config.sh\n+source utils.sh\n+\nREPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\nCLONED_REPO_DIR=\"translations-download-cloned-repo\"\n-CROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n-\n-SOURCE_BRANCH=\"develop\"\n-TARGET_BRANCH_BASE=\"develop-translations\"\n+TRANSLATION_PR_BRANCH_BASE=\"${TRANSLATION_TARGET_BRANCH}-translations\"\n-CONTENT_PATHS=(\n- \"csunplugged/topics/content\"\n- \"csunplugged/locale\"\n-)\n+echo ${REPO}\n# Clone repo, deleting old clone if exists\nif [ -d \"${CLONED_REPO_DIR}\" ]; then\n- rm -rf \"${CLONED_REPO_DIR}\"\n+ reset_repo \"${CLONED_REPO_DIR}\" \"${TRANSLATION_TARGET_BRANCH}\"\n+else\n+ git clone \"${REPO}\" \"${CLONED_REPO_DIR}\" --branch ${TRANSLATION_TARGET_BRANCH}\nfi\n-git clone \"${REPO}\" \"${CLONED_REPO_DIR}\" --branch ${SOURCE_BRANCH}\n# Change into the working repo\ncd \"${CLONED_REPO_DIR}\"\n# Set up git bot parameters\n-# TODO: Change these\n-git config user.name \"Travis CI\"\n-git config user.email \"test@test.com\"\n+git config user.name \"${GITHUB_BOT_NAME}\"\n+git config user.email \"${GITHUB_BOT_EMAIL}\"\n# Populate array of all project languages\nlanguages=($(python3 ../get_crowdin_languages.py))\n@@ -33,13 +30,13 @@ languages=($(python3 ../get_crowdin_languages.py))\nfor language in ${languages[@]}; do\n# The branch for new translationss\n- TARGET_BRANCH=\"${TARGET_BRANCH_BASE}-${language}\"\n+ TRANSLATION_PR_BRANCH=\"${TRANSLATION_PR_BRANCH_BASE}-${language}\"\n- # Checkout the translation branch, creating if off $SOURCE_BRANCH if it didn't already exist\n- git checkout $TARGET_BRANCH || git checkout -b $TARGET_BRANCH $SOURCE_BRANCH\n+ # Checkout the translation branch, creating if off $TRANSLATION_TARGET_BRANCH if it didn't already exist\n+ git checkout -B $TRANSLATION_PR_BRANCH $TRANSLATION_TARGET_BRANCH\n# Merge if required\n- git merge $SOURCE_BRANCH --quiet --no-edit\n+ git merge $TRANSLATION_TARGET_BRANCH --quiet --no-edit\n# Delete existing translation directories\nmapped_code=$(python3 ../language_map.py ${language})\n@@ -80,17 +77,17 @@ for language in ${languages[@]}; do\n# If any changes were made, push to github\nif [[ $changes -eq 1 ]]; then\n- git push -q origin $TARGET_BRANCH > /dev/null\n+ git push -q origin $TRANSLATION_PR_BRANCH > /dev/null\nfi\n# If the target branch differs from the source branch, create a PR\n- if [[ $(git diff $TARGET_BRANCH $SOURCE_BRANCH) ]]; then\n- hub pull-request -m \"Updated translations for ${language}\" -b \"${SOURCE_BRANCH}\" -h \"${TARGET_BRANCH}\" || \\\n+ if [[ $(git diff $TRANSLATION_PR_BRANCH $TRANSLATION_TARGET_BRANCH) ]]; then\n+ hub pull-request -m \"Updated translations for ${language}\" -b \"${TRANSLATION_TARGET_BRANCH}\" -h \"${TRANSLATION_PR_BRANCH}\" || \\\necho \"Could not create pull request - perhaps one already exists?\"\nfi\n# Return repo to clean state for next language\ngit reset --hard\n- git clean -fd\n+ git clean -fdx\ndone\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"new_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"diff": "# Deal with SSH KEYS here\nset -e\n+ set -x\n+\n+source config.sh\n+source utils.sh\nREPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\nCLONED_REPO_DIR=\"incontext-download-cloned-repo\"\n-CROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n-\n-CROWDIN_PSEUDO_LANGUAGE=\"en-UD\"\n-CSU_PSEUDO_LANGUAGE=\"xx_LR\"\n+IN_CONTEXT_L10N_PR_BRANCH=\"${IN_CONTEXT_L10N_TARGET_BRANCH}-in-context-l10n\"\n+# Clone repo, deleting old clone if exists\nif [ -d \"${CLONED_REPO_DIR}\" ]; then\n- rm -rf \"${CLONED_REPO_DIR}\"\n+ reset_repo \"${CLONED_REPO_DIR}\" \"${IN_CONTEXT_L10N_TARGET_BRANCH}\"\n+else\n+ git clone \"${REPO}\" \"${CLONED_REPO_DIR}\" --branch ${IN_CONTEXT_L10N_TARGET_BRANCH}\nfi\n-git clone \"${REPO}\" \"${CLONED_REPO_DIR}\"\n-cd \"${CLONED_REPO_DIR}\"\n-SHA=$(git rev-parse --verify HEAD)\n+cd \"${CLONED_REPO_DIR}\"\n-git config user.name \"Travis CI\"\n-git config user.email \"test@test.com\"\n+# Set up git bot parameters\n+git config user.name \"${GITHUB_BOT_NAME}\"\n+git config user.email \"${GITHUB_BOT_EMAIL}\"\n-SOURCE_BRANCH=\"develop\"\n-TARGET_BRANCH=\"develop-in-context-l10n\"\n+SHA=$(git rev-parse --verify HEAD)\n-git config user.name \"Travis CI\"\n-git config user.email \"test@test.com\"\n+git checkout -B $IN_CONTEXT_L10N_PR_BRANCH\n-git checkout $TARGET_BRANCH || git checkout -b $TARGET_BRANCH origin/$SOURCE_BRANCH\n# Merge if required\n-git merge origin/$SOURCE_BRANCH --quiet --no-edit\n+git merge origin/$IN_CONTEXT_L10N_TARGET_BRANCH --quiet --no-edit\ncrowdin -c \"${CROWDIN_CONFIG_FILE}\" -l \"${CROWDIN_PSEUDO_LANGUAGE}\" download\npython3 ../download_xliff.py\n@@ -38,11 +38,11 @@ git add \"csunplugged/topics/content/${CSU_PSEUDO_LANGUAGE}\"\n# If there are no changes to the compiled out (e.g. this is a README update) then just bail.\nif [[ $(git diff --cached) ]]; then\ngit commit -m \"Update in-context l10n: ${SHA}\"\n- git push -q origin $TARGET_BRANCH > /dev/null\n+ git push -q origin $IN_CONTEXT_L10N_PR_BRANCH > /dev/null\nfi\n# If there are no changes to the compiled out (e.g. this is a README update) then just bail.\n-if [[ $(git diff $TARGET_BRANCH origin/$SOURCE_BRANCH) ]]; then\n- hub pull-request -m \"Update in-context localisation files\" -b \"${SOURCE_BRANCH}\" -h \"${TARGET_BRANCH}\" || \\\n+if [[ $(git diff $IN_CONTEXT_L10N_PR_BRANCH origin/$IN_CONTEXT_L10N_TARGET_BRANCH) ]]; then\n+ hub pull-request -m \"Update in-context localisation files\" -b \"${IN_CONTEXT_L10N_TARGET_BRANCH}\" -h \"${IN_CONTEXT_L10N_PR_BRANCH}\" || \\\necho \"Could not create pull request - perhaps one already exists?\"\nfi\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/upload-crowdin-source-files.sh",
"new_path": "infrastructure/crowdin/upload-crowdin-source-files.sh",
"diff": "-# Deal with SSH KEYS here\nset -e\n+set -x\n+\n+source config.sh\n+source utils.sh\nREPO=\"git@github.com:uccser/cs-unplugged.git\"\nCLONED_REPO_DIR=\"source-upload-cloned-repo\"\n-SOURCE_BRANCH=\"develop\"\n+TRANSLATION_SOURCE_BRANCH=\"develop\"\nCROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n+# Clone repo, deleting old clone if exists\nif [ -d \"${CLONED_REPO_DIR}\" ]; then\n- rm -rf \"${CLONED_REPO_DIR}\"\n+ reset_repo \"${CLONED_REPO_DIR}\" \"${TRANSLATION_SOURCE_BRANCH}\"\n+else\n+ git clone \"${REPO}\" \"${CLONED_REPO_DIR}\" --branch ${TRANSLATION_SOURCE_BRANCH}\nfi\n-git clone \"${REPO}\" \"${CLONED_REPO_DIR}\"\ncd \"${CLONED_REPO_DIR}\"\n-git checkout \"${SOURCE_BRANCH}\"\n-\ncrowdin upload -c \"${CROWDIN_CONFIG_FILE}\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update scripts to not clone repo every time
|
701,855 |
18.11.2017 12:38:12
| -46,800 |
8b7bc59062118a8b6bf61d91bc1f560e5f09c9c1
|
Remove old script files
|
[
{
"change_type": "DELETE",
"old_path": "infrastructure/crowdin/download.sh",
"new_path": null,
"diff": "-#!/bin/bash\n-\n-crowdin download -c \"crowdin_content.yaml\" # .md/.yaml files\n"
},
{
"change_type": "DELETE",
"old_path": "infrastructure/crowdin/upload.sh",
"new_path": null,
"diff": "-#!/bin/bash\n-\n-crowdin upload -c \"crowdin_content.yaml\" # .md/.yaml files\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Remove old script files
|
701,855 |
18.11.2017 14:10:04
| -46,800 |
3f8090753d683a4daef099a2004254194770fd7d
|
Swap incorrect two_letters_code mapping to osx_locale
|
[
{
"change_type": "MODIFY",
"old_path": "crowdin_content.yaml",
"new_path": "crowdin_content.yaml",
"diff": "@@ -10,7 +10,7 @@ files: [\nsource: \"/csunplugged/topics/content/en/**/*.yaml\",\ntranslation: \"/csunplugged/topics/content/%osx_locale%/**/%original_file_name%\",\nlanguages_mapping: {\n- two_letters_code: {\n+ osx_locale: {\n\"en-UD\": \"xx_LR\", # Pseudo language\n\"zh-CN\": \"zh_Hans\",\n\"zh-TW\": \"zh_Hant\"\n@@ -21,7 +21,7 @@ files: [\nsource: \"/csunplugged/topics/content/en/**/*.md\",\ntranslation: \"/csunplugged/topics/content/%osx_locale%/**/%original_file_name%\",\nlanguages_mapping: {\n- two_letters_code: {\n+ osx_locale: {\n\"en-UD\": \"xx_LR\", # Pseudo language\n\"zh-CN\": \"zh_Hans\",\n\"zh-TW\": \"zh_Hant\"\n@@ -32,7 +32,7 @@ files: [\nsource: \"/csunplugged/locale/en/LC_MESSAGES/*.po\",\ntranslation: \"/csunplugged/locale/%osx_locale%/LC_MESSAGES/%original_file_name%\",\nlanguages_mapping: {\n- two_letters_code: {\n+ osx_locale: {\n\"en-UD\": \"xx_LR\", # Pseudo language\n\"zh-CN\": \"zh_Hans\",\n\"zh-TW\": \"zh_Hant\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Swap incorrect two_letters_code mapping to osx_locale
|
701,855 |
18.11.2017 14:30:30
| -46,800 |
514209d1a08318594aad0e444360a0f694094e40
|
Temporarily modify translation source/target branch to translation-pipeline
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/config.sh",
"new_path": "infrastructure/crowdin/config.sh",
"diff": "REPO=\"git@github.com:uccser/cs-unplugged.git\"\n# Branch for upload of source content to crowdin\n-TRANSLATION_SOURCE_BRANCH=\"develop\"\n+TRANSLATION_SOURCE_BRANCH=\"translation-pipeline\"\n# Branch that new translations will be merged into\n-TRANSLATION_TARGET_BRANCH=\"develop\"\n+TRANSLATION_TARGET_BRANCH=\"translation-pipeline\"\n# Branch that new metadata for in context localisation will be merged into\n-IN_CONTEXT_L10N_TARGET_BRANCH=\"develop\"\n+IN_CONTEXT_L10N_TARGET_BRANCH=\"translation-pipeline\"\n# Name of crowdin config file\nCROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Temporarily modify translation source/target branch to translation-pipeline
|
701,855 |
18.11.2017 14:31:39
| -46,800 |
555c9310ea1b2dc78f7011d12d1aeea0440ae939
|
Fix bug in logic determining whether file is translated
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/get_complete_translations.py",
"new_path": "infrastructure/crowdin/get_complete_translations.py",
"diff": "@@ -46,7 +46,7 @@ def process_item(item, parent_path=None):\nif filename.endswith(\".po\"):\nreturn [path]\n- if item.find(\"phrases\") == item.find(\"approved\"):\n+ if item.find(\"phrases\").text == item.find(\"approved\").text:\nreturn [path]\nelse:\nreturn []\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Fix bug in logic determining whether file is translated
|
701,855 |
18.11.2017 14:32:38
| -46,800 |
936b66c13b26b86010bb673a1d8de536e88ace9e
|
Small fixes to crowdin scripts
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-completed-translations.sh",
"new_path": "infrastructure/crowdin/update-completed-translations.sh",
"diff": "@@ -8,8 +8,6 @@ REPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\nCLONED_REPO_DIR=\"translations-download-cloned-repo\"\nTRANSLATION_PR_BRANCH_BASE=\"${TRANSLATION_TARGET_BRANCH}-translations\"\n-echo ${REPO}\n-\n# Clone repo, deleting old clone if exists\nif [ -d \"${CLONED_REPO_DIR}\" ]; then\nreset_repo \"${CLONED_REPO_DIR}\" \"${TRANSLATION_TARGET_BRANCH}\"\n@@ -33,7 +31,7 @@ for language in ${languages[@]}; do\nTRANSLATION_PR_BRANCH=\"${TRANSLATION_PR_BRANCH_BASE}-${language}\"\n# Checkout the translation branch, creating if off $TRANSLATION_TARGET_BRANCH if it didn't already exist\n- git checkout -B $TRANSLATION_PR_BRANCH $TRANSLATION_TARGET_BRANCH\n+ git checkout $TRANSLATION_PR_BRANCH || git checkout -b $TRANSLATION_PR_BRANCH $TRANSLATION_TARGET_BRANCH\n# Merge if required\ngit merge $TRANSLATION_TARGET_BRANCH --quiet --no-edit\n@@ -82,8 +80,8 @@ for language in ${languages[@]}; do\n# If the target branch differs from the source branch, create a PR\nif [[ $(git diff $TRANSLATION_PR_BRANCH $TRANSLATION_TARGET_BRANCH) ]]; then\n- hub pull-request -m \"Updated translations for ${language}\" -b \"${TRANSLATION_TARGET_BRANCH}\" -h \"${TRANSLATION_PR_BRANCH}\" || \\\n- echo \"Could not create pull request - perhaps one already exists?\"\n+ hub pull-request -f -m \"Updated translations for ${language}\" -b \"${TRANSLATION_TARGET_BRANCH}\" -h \"${TRANSLATION_PR_BRANCH}\" || \\\n+ echo \"Could not create pull request - this probably means one already exists\"\nfi\n# Return repo to clean state for next language\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"new_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"diff": "@@ -24,7 +24,7 @@ git config user.email \"${GITHUB_BOT_EMAIL}\"\nSHA=$(git rev-parse --verify HEAD)\n-git checkout -B $IN_CONTEXT_L10N_PR_BRANCH\n+git checkout $IN_CONTEXT_L10N_PR_BRANCH || git checkout -b $IN_CONTEXT_L10N_PR_BRANCH $IN_CONTEXT_L10N_TARGET_BRANCH\n# Merge if required\ngit merge origin/$IN_CONTEXT_L10N_TARGET_BRANCH --quiet --no-edit\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/upload-crowdin-source-files.sh",
"new_path": "infrastructure/crowdin/upload-crowdin-source-files.sh",
"diff": "@@ -4,10 +4,7 @@ set -x\nsource config.sh\nsource utils.sh\n-REPO=\"git@github.com:uccser/cs-unplugged.git\"\nCLONED_REPO_DIR=\"source-upload-cloned-repo\"\n-TRANSLATION_SOURCE_BRANCH=\"develop\"\n-CROWDIN_CONFIG_FILE=\"crowdin_content.yaml\"\n# Clone repo, deleting old clone if exists\nif [ -d \"${CLONED_REPO_DIR}\" ]; then\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Small fixes to crowdin scripts
|
701,855 |
18.11.2017 21:06:47
| -46,800 |
6d2753ce7ff4b12c5b4542434e9511938f306a43
|
Add pipefail flag to shell scripts
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/get-unused-crowdin-files.sh",
"new_path": "infrastructure/crowdin/get-unused-crowdin-files.sh",
"diff": "set -e\nset -x\n+set -o pipefail\nsource config.sh\nsource utils.sh\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-completed-translations.sh",
"new_path": "infrastructure/crowdin/update-completed-translations.sh",
"diff": "set -e\nset -x\n+set -o pipefail\nsource config.sh\nsource utils.sh\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"new_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"diff": "# Deal with SSH KEYS here\nset -e\nset -x\n+ set -o pipefail\nsource config.sh\nsource utils.sh\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/upload-crowdin-source-files.sh",
"new_path": "infrastructure/crowdin/upload-crowdin-source-files.sh",
"diff": "set -e\nset -x\n+set -o pipefail\nsource config.sh\nsource utils.sh\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add pipefail flag to shell scripts
|
701,855 |
18.11.2017 21:07:14
| -46,800 |
24dc40c8fffbbd6d60752f7cd0dbb5702092dc17
|
Remove unnecessary imports from get_complete_translations.py
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/get_complete_translations.py",
"new_path": "infrastructure/crowdin/get_complete_translations.py",
"diff": "@@ -2,11 +2,8 @@ import os\nimport requests\nfrom lxml import etree\nimport sys\n-from django.conf import settings\n-from django.utils import translation\nimport language_map\n-settings.configure()\nAPI_KEY = os.environ[\"CROWDIN_API_KEY\"]\nAPI_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Remove unnecessary imports from get_complete_translations.py
|
701,855 |
18.11.2017 21:08:21
| -46,800 |
4441711dc64e258a4b2d8d06627b5bb86fa44a5c
|
(WIP) Add setup-instance.sh script for configuring GCE instance
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/setup-instance.sh",
"diff": "+# TODO: PAth manipulations?\n+\n+tar -xvzf crowdin.tar.gz\n+\n+gcloud kms decrypt --ciphertext-file=uccser_bot_token.enc --plaintext-file=uccser_bot_token --location=global --keyring=csunplugged-keyring --key=uccser-bot-token\n+gcloud kms decrypt --ciphertext-file=crowdin_api_key.enc --plaintext-file=crowdin_api_key --location=global --keyring=csunplugged-keyring --key=crowdin-api-key\n+cat >> ~/.bashrc << EOF\n+export CROWDIN_API_KEY=$(cat crowdin_api_key)\n+export GITHUB_TOKEN=$(cat uccser_bot_token)\n+EOF\n+\n+# TODO: Activate service account to get access to KMS\n+gcloud kms decrypt --ciphertext-file=gce_key.enc --plaintext-file=gce_key --location=global --keyring=csunplugged-keyring --key=uccser-bot-ssh-key\n+eval \"$(ssh-agent -s)\"\n+cp gce_key ~/.ssh\n+chmod 400 ~/.ssh/gce_key\n+ssh-add ~/.ssh/gce_key\n+\n+cat >> ~/.ssh/config << EOF\n+Host github.com\n+ IdentityFile ~/.ssh/gce_key\n+EOF\n+\n+apt-get install git --yes\n+apt-get install python3-pip\n+pip3 install verto\n+\n+apt-get install python3-lxml # Can't use pip - not enough RAM for compilation!\n+\n+# Install Crowdin CLI\n+wget -qO - https://artifacts.crowdin.com/repo/GPG-KEY-crowdin | sudo apt-key add -\n+echo \"deb https://artifacts.crowdin.com/repo/deb/ /\" > /etc/apt/sources.list.d/crowdin.list\n+apt-get update\n+apt-get install crowdin --yes\n+# ... and Java dependency\n+apt-get install default-jre --yes\n+\n+# Install hub\n+wget https://github.com/github/hub/releases/download/v2.2.5/hub-linux-amd64-2.2.5.tgz\n+tar zvxvf hub-linux-amd64-2.2.5.tgz\n+sudo ./hub-linux-amd64-2.2.5/install\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
(WIP) Add setup-instance.sh script for configuring GCE instance
|
701,855 |
18.11.2017 21:09:10
| -46,800 |
6f6d2cfdd151954fccc1b80052ce3376e138f97a
|
Add encrypted secrets files for crowdin automation
|
[
{
"change_type": "ADD",
"old_path": "infrastructure/crowdin_api_key.enc",
"new_path": "infrastructure/crowdin_api_key.enc",
"diff": "Binary files /dev/null and b/infrastructure/crowdin_api_key.enc differ\n"
},
{
"change_type": "ADD",
"old_path": "infrastructure/gce_key.enc",
"new_path": "infrastructure/gce_key.enc",
"diff": "Binary files /dev/null and b/infrastructure/gce_key.enc differ\n"
},
{
"change_type": "ADD",
"old_path": "infrastructure/uccser_bot_token.enc",
"new_path": "infrastructure/uccser_bot_token.enc",
"diff": "Binary files /dev/null and b/infrastructure/uccser_bot_token.enc differ\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add encrypted secrets files for crowdin automation
|
701,855 |
19.11.2017 17:22:23
| -46,800 |
cf61f81916fca41933ff549a71e3a2bb127ee794
|
Move crowdin bot python scripts into python package
|
[
{
"change_type": "ADD",
"old_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/__init__.py",
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/__init__.py",
"diff": ""
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/api.py",
"diff": "+import lxml.etree\n+import json\n+import os\n+import requests\n+\n+API_KEY = os.environ[\"CROWDIN_API_KEY\"]\n+API_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\n+\n+\n+def api_call_text(method, **params):\n+ params[\"key\"] = API_KEY\n+ response = requests.get(\n+ API_URL.format(method=method),\n+ params=params\n+ )\n+ return response.text\n+\n+\n+def api_call_xml(method, **params):\n+ response_text = api_call_text(method, **params)\n+ xml = lxml.etree.fromstring(response_text.encode())\n+ return xml\n+\n+def api_call_json(method, **params):\n+ response_text = api_call_text(method, json=True, **params)\n+ return json.loads(response_text)\n"
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/download_xliff.py",
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/download_xliff.py",
"diff": "import os\n-import requests\n-INCONTEXT_L10N_PSEUDOLANGUAGE_CROWDIN = \"en-UD\"\n-API_KEY = os.environ[\"CROWDIN_API_KEY\"]\n-API_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\n+from crowdin_bot import api\n+INCONTEXT_L10N_PSEUDOLANGUAGE_CROWDIN = \"en-UD\"\nCONTENT_ROOT = \"csunplugged/topics/content\"\nEN_DIR = os.path.join(CONTENT_ROOT, 'en')\nXLIFF_DIR = os.path.join(CONTENT_ROOT, 'xliff')\n@@ -17,14 +15,10 @@ def download_xliff(source_filename, dest_filename, language=INCONTEXT_L10N_PSEUD\n\"language\": language,\n\"format\": \"xliff\"\n}\n- response = requests.get(\n- API_URL.format(method=\"export-file\"),\n- params=params\n- )\n- print(\"Downloading {}\".format(response.url))\n- xliff_text = response.text.replace('\\x0C', '')\n+ xliff_content = api.api_call_text(\"export-file\", **params)\n+ xliff_content = xliff_content.replace('\\x0C', '')\nwith open(dest_filename, 'w') as f:\n- f.write(xliff_text)\n+ f.write(xliff_content)\nif __name__ == \"__main__\":\nif not os.path.exists(XLIFF_DIR):\n"
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/get_complete_translations.py",
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/get_complete_translations.py",
"diff": "import os\n-import requests\n-from lxml import etree\n-import sys\n-import language_map\n+import argparse\n-\n-API_KEY = os.environ[\"CROWDIN_API_KEY\"]\n-API_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\n-\n-NS_DICT = {\n- 'ns': \"urn:oasis:names:tc:xliff:document:1.2\"\n-}\n-\n-if len(sys.argv) != 2:\n- raise Exception(\"Usage: python3 get_completed_translations.py <crowdin language code>\")\n+from crowdin_bot import api\nSOURCE_LANGUAGE = \"en\"\n-TARGET_LANGUAGE = sys.argv[1]\ndef get_language_info(language):\n- params = {\n- \"key\" : API_KEY,\n- \"language\": language\n- }\n- response = requests.get(\n- API_URL.format(method=\"language-status\"),\n- params=params\n+ return api.api_call_xml(\n+ \"language-status\",\n+ language=language\n)\n- info = etree.fromstring(response.text.encode())\n- return info\n-\n-def process_item(item, parent_path=None):\n+def process_item(item, parent_path=None, csu_language_code=None):\nif item.find(\"node_type\").text == \"file\":\nfilename = item.find(\"name\").text\nif parent_path:\n@@ -52,21 +32,29 @@ def process_item(item, parent_path=None):\ninner_nodes = item.find(\"files\")\ndirname = item.find(\"name\").text\nif dirname == SOURCE_LANGUAGE:\n- dirname = language_map.from_crowdin(TARGET_LANGUAGE)\n+ dirname = csu_language_code\nif parent_path:\npath = os.path.join(parent_path, dirname)\nelse:\npath = dirname\ncompleted = []\nfor inner_node in inner_nodes:\n- completed += process_item(inner_node, parent_path=path)\n+ completed += process_item(inner_node, parent_path=path, csu_language_code=csu_language_code)\nreturn completed\nif __name__ == \"__main__\":\n- lang_info = get_language_info(TARGET_LANGUAGE)\n+ parser = argparse.ArgumentParser()\n+ # parser.add_argument('--crowdin-code', required=True,\n+ # help='Crowdin language code')\n+ parser.add_argument('--crowdin-code', required=True,\n+ help='Crowdin language code for target language')\n+ parser.add_argument('--csu-code', required=True,\n+ help='CSU language code for target language')\n+ args = parser.parse_args()\n+ lang_info = get_language_info(args.crowdin_code)\nfiles = lang_info.find(\"files\")\ncompleted = []\nfor item in files:\n- completed += process_item(item)\n+ completed += process_item(item, csu_language_code=args.csu_code)\nprint('\\n'.join(completed))\n"
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/get_crowdin_files.py",
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/get_crowdin_files.py",
"diff": "import os\n-import requests\n-from lxml import etree\n-import sys\n-import language_map\n+from crowdin_bot import api\n-API_KEY = os.environ[\"CROWDIN_API_KEY\"]\n-API_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\ndef get_project_info():\n- params = {\n- \"key\" : API_KEY,\n- }\n- response = requests.get(\n- API_URL.format(method=\"info\"),\n- params=params\n- )\n- info = etree.fromstring(response.text.encode())\n- return info\n+ return api.api_call_xml(\"info\")\ndef process_item(item, parent_path=\"/\"):\n"
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/get_crowdin_languages.py",
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/get_crowdin_languages.py",
"diff": "-import os\n-import requests\n-from lxml import etree\n-\n-API_KEY = os.environ[\"CROWDIN_API_KEY\"]\n-API_URL = \"https://api.crowdin.com/api/project/cs-unplugged/{method}\"\n+from crowdin_bot import api\nNS_DICT = {\n'ns': \"urn:oasis:names:tc:xliff:document:1.2\"\n}\ndef get_project_languages():\n- params = {\n- \"key\" : API_KEY,\n- }\n- response = requests.get(\n- API_URL.format(method=\"info\"),\n- params=params\n- )\n- info = etree.fromstring(response.text.encode())\n- languages = info.find('languages')\n+ info_xml = api.api_call_xml(\"info\")\n+ languages = info_xml.find('languages')\ntranslatable_languages = []\nfor language in languages:\n# Check it's not the incontext pseudo language\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/get_language_map.py",
"diff": "+import argparse\n+import json\n+from crowdin_bot import api\n+import yaml\n+import re\n+\n+# import sys\n+#\n+# # In general, this is crowdin-osx-locale -> crowdin-code, except for some\n+# # special cases like Simplified/Traditional Chinese, which also need to be\n+# # overriden in the crowdin.yaml file, using the language mapping parameter\n+#\n+# # The base list was generated from https://api.crowdin.com/api/supported-languages?json=True\n+#\n+# FROM_CROWDIN_MAP = {\n+# \"aa\": \"aa\",\n+# \"ach\": \"ach\",\n+# \"ae\": \"ae\",\n+# \"af\": \"af\",\n+# \"ak\": \"ak\",\n+# \"am\": \"am\",\n+# \"an\": \"an\",\n+# \"ar\": \"ar\",\n+# \"ar-BH\": \"ar_BH\",\n+# \"ar-EG\": \"ar_EG\",\n+# \"ar-SA\": \"ar_SA\",\n+# \"ar-YE\": \"ar_YE\",\n+# \"arn\": \"arn\",\n+# \"as\": \"as\",\n+# \"ast\": \"ast\",\n+# \"av\": \"av\",\n+# \"ay\": \"ay\",\n+# \"az\": \"az\",\n+# \"ba\": \"ba\",\n+# \"bal\": \"bal\",\n+# \"ban\": \"ban\",\n+# \"be\": \"be\",\n+# \"ber\": \"ber\",\n+# \"bfo\": \"bfo\",\n+# \"bg\": \"bg\",\n+# \"bh\": \"bh\",\n+# \"bi\": \"bi\",\n+# \"bm\": \"bm\",\n+# \"bn\": \"bn\",\n+# \"bn-IN\": \"bn_IN\",\n+# \"bo-BT\": \"bo\",\n+# \"br-FR\": \"br\",\n+# \"bs\": \"bs\",\n+# \"ca\": \"ca\",\n+# \"ce\": \"ce\",\n+# \"ceb\": \"ceb\",\n+# \"ch\": \"ch\",\n+# \"chr\": \"chr\",\n+# \"ckb\": \"ckb\",\n+# \"co\": \"co\",\n+# \"cr\": \"cr\",\n+# \"crs\": \"crs\",\n+# \"cs\": \"cs\",\n+# \"csb\": \"csb\",\n+# \"cv\": \"cv\",\n+# \"cy\": \"cy\",\n+# \"da\": \"da\",\n+# \"de\": \"de\",\n+# \"de-AT\": \"de_AT\",\n+# \"de-BE\": \"de_BE\",\n+# \"de-CH\": \"de_CH\",\n+# \"de-LI\": \"de_LI\",\n+# \"de-LU\": \"de_LU\",\n+# \"dsb-DE\": \"dsb\",\n+# \"dv\": \"dv\",\n+# \"dz\": \"dz\",\n+# \"ee\": \"ee\",\n+# \"el\": \"el\",\n+# \"el-CY\": \"el_CY\",\n+# \"en\": \"en\",\n+# \"en-AR\": \"en_AR\",\n+# \"en-AU\": \"en_AU\",\n+# \"en-BZ\": \"en_BZ\",\n+# \"en-CA\": \"en_CA\",\n+# \"en-CB\": \"en_CB\",\n+# \"en-CN\": \"en_CN\",\n+# \"en-DK\": \"en_DK\",\n+# \"en-GB\": \"en_GB\",\n+# \"en-HK\": \"en_HK\",\n+# \"en-ID\": \"en_ID\",\n+# \"en-IE\": \"en_IE\",\n+# \"en-IN\": \"en_IN\",\n+# \"en-JA\": \"en_JA\",\n+# \"en-JM\": \"en_JM\",\n+# \"en-MY\": \"en_MY\",\n+# \"en-NO\": \"en_NO\",\n+# \"en-NZ\": \"en_NZ\",\n+# \"en-PH\": \"en_PH\",\n+# \"en-PR\": \"en_PR\",\n+# \"en-PT\": \"en_PT\",\n+# \"en-SE\": \"en_SE\",\n+# \"en-SG\": \"en_SG\",\n+# \"en-UD\": \"xx_LR\", # Modified, for the in context translation pseudo language\n+# \"en-US\": \"en_US\",\n+# \"en-ZA\": \"en_ZA\",\n+# \"en-ZW\": \"en_ZW\",\n+# \"eo\": \"eo\",\n+# \"es-AR\": \"es_AR\",\n+# \"es-BO\": \"es_BO\",\n+# \"es-CL\": \"es_CL\",\n+# \"es-CO\": \"es_CO\",\n+# \"es-CR\": \"es_CR\",\n+# \"es-DO\": \"es_DO\",\n+# \"es-EC\": \"es_EC\",\n+# \"es-EM\": \"es_EM\",\n+# \"es-ES\": \"es\",\n+# \"es-GT\": \"es_GT\",\n+# \"es-HN\": \"es_HN\",\n+# \"es-MX\": \"es_MX\",\n+# \"es-NI\": \"es_NI\",\n+# \"es-PA\": \"es_PA\",\n+# \"es-PE\": \"es_PE\",\n+# \"es-PR\": \"es_PR\",\n+# \"es-PY\": \"es_PY\",\n+# \"es-SV\": \"es_SV\",\n+# \"es-US\": \"es_US\",\n+# \"es-UY\": \"es_UY\",\n+# \"es-VE\": \"es_VE\",\n+# \"et\": \"et\",\n+# \"eu\": \"eu\",\n+# \"fa\": \"fa\",\n+# \"fa-AF\": \"fa_AF\",\n+# \"ff\": \"ff\",\n+# \"fi\": \"fi\",\n+# \"fil\": \"fil\",\n+# \"fj\": \"fj\",\n+# \"fo\": \"fo\",\n+# \"fr\": \"fr\",\n+# \"fr-BE\": \"fr_BE\",\n+# \"fr-CA\": \"fr_CA\",\n+# \"fr-CH\": \"fr_CH\",\n+# \"fr-LU\": \"fr_LU\",\n+# \"fr-QC\": \"fr_QC\",\n+# \"fra-DE\": \"fra\",\n+# \"frp\": \"frp\",\n+# \"fur-IT\": \"fur\",\n+# \"fy-NL\": \"fy\",\n+# \"ga-IE\": \"ga\",\n+# \"gaa\": \"gaa\",\n+# \"gd\": \"gd\",\n+# \"gl\": \"gl\",\n+# \"gn\": \"gn\",\n+# \"got\": \"got\",\n+# \"gu-IN\": \"gu\",\n+# \"gv\": \"gv\",\n+# \"ha\": \"ha\",\n+# \"haw\": \"haw\",\n+# \"he\": \"he\",\n+# \"hi\": \"hi\",\n+# \"hil\": \"hil\",\n+# \"hmn\": \"hmn\",\n+# \"ho\": \"ho\",\n+# \"hr\": \"hr\",\n+# \"hsb-DE\": \"hsb\",\n+# \"ht\": \"ht\",\n+# \"hu\": \"hu\",\n+# \"hy-AM\": \"hy\",\n+# \"hz\": \"hz\",\n+# \"id\": \"id\",\n+# \"ido\": \"ido\",\n+# \"ig\": \"ig\",\n+# \"ii\": \"ii\",\n+# \"ilo\": \"ilo\",\n+# \"is\": \"is\",\n+# \"it\": \"it\",\n+# \"it-CH\": \"it_CH\",\n+# \"iu\": \"iu\",\n+# \"ja\": \"ja\",\n+# \"jbo\": \"jbo\",\n+# \"jv\": \"jv\",\n+# \"ka\": \"ka\",\n+# \"kab\": \"kab\",\n+# \"kdh\": \"kdh\",\n+# \"kg\": \"kg\",\n+# \"kj\": \"kj\",\n+# \"kk\": \"kk\",\n+# \"kl\": \"kl\",\n+# \"km\": \"km\",\n+# \"kmr\": \"kmr\",\n+# \"kn\": \"kn\",\n+# \"ko\": \"ko\",\n+# \"kok\": \"kok\",\n+# \"ks\": \"ks\",\n+# \"ks-PK\": \"ks_PK\",\n+# \"ku\": \"ku\",\n+# \"kv\": \"kv\",\n+# \"kw\": \"kw\",\n+# \"ky\": \"ky\",\n+# \"la-LA\": \"la\",\n+# \"lb\": \"lb\",\n+# \"lg\": \"lg\",\n+# \"li\": \"li\",\n+# \"lij\": \"lij\",\n+# \"ln\": \"ln\",\n+# \"lo\": \"lo\",\n+# \"lol\": \"lol\",\n+# \"lt\": \"lt\",\n+# \"luy\": \"luy\",\n+# \"lv\": \"lv\",\n+# \"mai\": \"mai\",\n+# \"me\": \"me\",\n+# \"mg\": \"mg\",\n+# \"mh\": \"mh\",\n+# \"mi\": \"mi\",\n+# \"mk\": \"mk\",\n+# \"ml-IN\": \"ml\",\n+# \"mn\": \"mn\",\n+# \"moh\": \"moh\",\n+# \"mos\": \"mos\",\n+# \"mr\": \"mr\",\n+# \"ms\": \"ms\",\n+# \"ms-BN\": \"ms_BN\",\n+# \"mt\": \"mt\",\n+# \"my\": \"my\",\n+# \"na\": \"na\",\n+# \"nb\": \"nb\",\n+# \"nds\": \"nds\",\n+# \"ne-IN\": \"ne_IN\",\n+# \"ne-NP\": \"ne\",\n+# \"ng\": \"ng\",\n+# \"nl\": \"nl\",\n+# \"nl-BE\": \"nl_BE\",\n+# \"nl-SR\": \"nl_SR\",\n+# \"nn-NO\": \"nn_NO\",\n+# \"no\": \"no\",\n+# \"nr\": \"nr\",\n+# \"nso\": \"nso\",\n+# \"ny\": \"ny\",\n+# \"oc\": \"oc\",\n+# \"oj\": \"oj\",\n+# \"om\": \"om\",\n+# \"or\": \"or\",\n+# \"os\": \"os\",\n+# \"pa-IN\": \"pa\",\n+# \"pa-PK\": \"pa_PK\",\n+# \"pam\": \"pam\",\n+# \"pap\": \"pap\",\n+# \"pcm\": \"pcm\",\n+# \"pi\": \"pi\",\n+# \"pl\": \"pl\",\n+# \"ps\": \"ps\",\n+# \"pt-BR\": \"pt_BR\",\n+# \"pt-PT\": \"pt\",\n+# \"qu\": \"qu\",\n+# \"quc\": \"quc\",\n+# \"qya-AA\": \"qya\",\n+# \"rm-CH\": \"rm\",\n+# \"rn\": \"rn\",\n+# \"ro\": \"ro\",\n+# \"ru\": \"ru\",\n+# \"ru-BY\": \"ru_BY\",\n+# \"ru-MD\": \"ru_MD\",\n+# \"ru-UA\": \"ru_UA\",\n+# \"rw\": \"rw\",\n+# \"ry-UA\": \"ry\",\n+# \"sa\": \"sa\",\n+# \"sah\": \"sah\",\n+# \"sat\": \"sat\",\n+# \"sc\": \"sc\",\n+# \"sco\": \"sco\",\n+# \"sd\": \"sd\",\n+# \"se\": \"se\",\n+# \"sg\": \"sg\",\n+# \"sh\": \"sh\",\n+# \"si-LK\": \"si\",\n+# \"sk\": \"sk\",\n+# \"sl\": \"sl\",\n+# \"sma\": \"sma\",\n+# \"sn\": \"sn\",\n+# \"so\": \"so\",\n+# \"son\": \"son\",\n+# \"sq\": \"sq\",\n+# \"sr\": \"sr\",\n+# \"sr-CS\": \"sr_CS\",\n+# \"sr-Cyrl-ME\": \"sr_Cyrl_ME\",\n+# \"ss\": \"ss\",\n+# \"st\": \"st\",\n+# \"su\": \"su\",\n+# \"sv-FI\": \"sv_FI\",\n+# \"sv-SE\": \"sv\",\n+# \"sw\": \"sw\",\n+# \"sw-KE\": \"sw_KE\",\n+# \"sw-TZ\": \"sw_TZ\",\n+# \"syc\": \"syc\",\n+# \"ta\": \"ta\",\n+# \"tay\": \"tay\",\n+# \"te\": \"te\",\n+# \"tg\": \"tg\",\n+# \"th\": \"th\",\n+# \"ti\": \"ti\",\n+# \"tk\": \"tk\",\n+# \"tl\": \"tl\",\n+# \"tlh-AA\": \"tlh\",\n+# \"tn\": \"tn\",\n+# \"tr\": \"tr\",\n+# \"tr-CY\": \"tr_CY\",\n+# \"ts\": \"ts\",\n+# \"tt-RU\": \"tt\",\n+# \"tw\": \"tw\",\n+# \"ty\": \"ty\",\n+# \"tzl\": \"tzl\",\n+# \"ug\": \"ug\",\n+# \"uk\": \"uk\",\n+# \"ur-IN\": \"ur_IN\",\n+# \"ur-PK\": \"ur\",\n+# \"uz\": \"uz\",\n+# \"val-ES\": \"val\",\n+# \"ve\": \"ve\",\n+# \"vec\": \"vec\",\n+# \"vi\": \"vi\",\n+# \"vls-BE\": \"vls\",\n+# \"wa\": \"wa\",\n+# \"wo\": \"wo\",\n+# \"xh\": \"xh\",\n+# \"yi\": \"yi\",\n+# \"yo\": \"yo\",\n+# \"zea\": \"zea\",\n+# \"zh-CN\": \"zh_Hans\", # Modified\n+# \"zh-HK\": \"zh_HK\",\n+# \"zh-MO\": \"zh_MO\",\n+# \"zh-SG\": \"zh_SG\",\n+# \"zh-TW\": \"zh-Hant\", # Modified\n+# \"zu\": \"zu\"\n+# }\n+\n+def get_osx_locale_mapping():\n+ languages_json = api.api_call_json(\"supported-languages\")\n+ return {\n+ language[\"crowdin_code\"]: language[\"osx_locale\"] for language in languages_json\n+ }\n+\n+\n+def validate_config(config):\n+ files = config.get(\"files\", [])\n+ if len(files) == 0:\n+ raise Exception(\"Crowdin config must contain at least one file config\")\n+ osx_locale_map_overriide = get_overrides(config)\n+ translation_regex=re.compile(r\"[^%]*%osx_locale%[^%]*%original_file_name%\")\n+ for file in files:\n+ translation_pattern=file.get(\"translation\", \"\")\n+ if not translation_regex.match(translation_pattern):\n+ raise Exception(\"Translation patterns in the crowdin config file must \"\n+ \"contain %osx_locale% and %original_file_name% placeholders (and no others). \"\n+ \"The following pattern does not meet this criteria: {}\".format(translation_pattern))\n+ if osx_locale_map_overriide:\n+ if file.get(\"languages_mapping\", {}).get(\"osx_locale\") != osx_locale_map_overriide:\n+ raise Exception(\"All files entries in the crowdin config file must have the same osx_locale language mapping.\")\n+\n+\n+def get_overrides(config):\n+ return config[\"files\"][0].get(\"languages_mapping\").get(\"osx_locale\", {})\n+\n+if __name__ == \"__main__\":\n+ parser = argparse.ArgumentParser()\n+ # parser.add_argument('--crowdin-code', required=True,\n+ # help='Crowdin language code')\n+ parser.add_argument('--crowdin-config', required=True,\n+ help='Path to crowdin config yaml file')\n+ args = parser.parse_args()\n+ with open(args.crowdin_config) as f:\n+ config = yaml.load(f)\n+ validate_config(config)\n+ osx_locale_mapping = get_osx_locale_mapping()\n+ overrides = get_overrides(config)\n+ osx_locale_mapping.update(overrides)\n+ print(json.dumps(osx_locale_mapping, sort_keys=True, indent=4))\n"
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/modify_pseudo_translations.py",
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/modify_pseudo_translations.py",
"diff": ""
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/setup.py",
"diff": "+from distutils.core import setup\n+setup(\n+ name='crowdin_bot',\n+ version='1.0',\n+ packages=[\"crowdin_bot\"]\n+)\n"
},
{
"change_type": "DELETE",
"old_path": "infrastructure/crowdin/language_map.py",
"new_path": null,
"diff": "-import sys\n-\n-# In general, this is crowdin-osx-locale -> crowdin-code, except for some\n-# special cases like Simplified/Traditional Chinese, which also need to be\n-# overriden in the crowdin.yaml file, using the language mapping parameter\n-\n-# The base list was generated from https://api.crowdin.com/api/supported-languages?json=True\n-\n-FROM_CROWDIN_MAP = {\n- \"aa\": \"aa\",\n- \"ach\": \"ach\",\n- \"ae\": \"ae\",\n- \"af\": \"af\",\n- \"ak\": \"ak\",\n- \"am\": \"am\",\n- \"an\": \"an\",\n- \"ar\": \"ar\",\n- \"ar-BH\": \"ar_BH\",\n- \"ar-EG\": \"ar_EG\",\n- \"ar-SA\": \"ar_SA\",\n- \"ar-YE\": \"ar_YE\",\n- \"arn\": \"arn\",\n- \"as\": \"as\",\n- \"ast\": \"ast\",\n- \"av\": \"av\",\n- \"ay\": \"ay\",\n- \"az\": \"az\",\n- \"ba\": \"ba\",\n- \"bal\": \"bal\",\n- \"ban\": \"ban\",\n- \"be\": \"be\",\n- \"ber\": \"ber\",\n- \"bfo\": \"bfo\",\n- \"bg\": \"bg\",\n- \"bh\": \"bh\",\n- \"bi\": \"bi\",\n- \"bm\": \"bm\",\n- \"bn\": \"bn\",\n- \"bn-IN\": \"bn_IN\",\n- \"bo-BT\": \"bo\",\n- \"br-FR\": \"br\",\n- \"bs\": \"bs\",\n- \"ca\": \"ca\",\n- \"ce\": \"ce\",\n- \"ceb\": \"ceb\",\n- \"ch\": \"ch\",\n- \"chr\": \"chr\",\n- \"ckb\": \"ckb\",\n- \"co\": \"co\",\n- \"cr\": \"cr\",\n- \"crs\": \"crs\",\n- \"cs\": \"cs\",\n- \"csb\": \"csb\",\n- \"cv\": \"cv\",\n- \"cy\": \"cy\",\n- \"da\": \"da\",\n- \"de\": \"de\",\n- \"de-AT\": \"de_AT\",\n- \"de-BE\": \"de_BE\",\n- \"de-CH\": \"de_CH\",\n- \"de-LI\": \"de_LI\",\n- \"de-LU\": \"de_LU\",\n- \"dsb-DE\": \"dsb\",\n- \"dv\": \"dv\",\n- \"dz\": \"dz\",\n- \"ee\": \"ee\",\n- \"el\": \"el\",\n- \"el-CY\": \"el_CY\",\n- \"en\": \"en\",\n- \"en-AR\": \"en_AR\",\n- \"en-AU\": \"en_AU\",\n- \"en-BZ\": \"en_BZ\",\n- \"en-CA\": \"en_CA\",\n- \"en-CB\": \"en_CB\",\n- \"en-CN\": \"en_CN\",\n- \"en-DK\": \"en_DK\",\n- \"en-GB\": \"en_GB\",\n- \"en-HK\": \"en_HK\",\n- \"en-ID\": \"en_ID\",\n- \"en-IE\": \"en_IE\",\n- \"en-IN\": \"en_IN\",\n- \"en-JA\": \"en_JA\",\n- \"en-JM\": \"en_JM\",\n- \"en-MY\": \"en_MY\",\n- \"en-NO\": \"en_NO\",\n- \"en-NZ\": \"en_NZ\",\n- \"en-PH\": \"en_PH\",\n- \"en-PR\": \"en_PR\",\n- \"en-PT\": \"en_PT\",\n- \"en-SE\": \"en_SE\",\n- \"en-SG\": \"en_SG\",\n- \"en-UD\": \"xx_LR\", # Modified, for the in context translation pseudo language\n- \"en-US\": \"en_US\",\n- \"en-ZA\": \"en_ZA\",\n- \"en-ZW\": \"en_ZW\",\n- \"eo\": \"eo\",\n- \"es-AR\": \"es_AR\",\n- \"es-BO\": \"es_BO\",\n- \"es-CL\": \"es_CL\",\n- \"es-CO\": \"es_CO\",\n- \"es-CR\": \"es_CR\",\n- \"es-DO\": \"es_DO\",\n- \"es-EC\": \"es_EC\",\n- \"es-EM\": \"es_EM\",\n- \"es-ES\": \"es\",\n- \"es-GT\": \"es_GT\",\n- \"es-HN\": \"es_HN\",\n- \"es-MX\": \"es_MX\",\n- \"es-NI\": \"es_NI\",\n- \"es-PA\": \"es_PA\",\n- \"es-PE\": \"es_PE\",\n- \"es-PR\": \"es_PR\",\n- \"es-PY\": \"es_PY\",\n- \"es-SV\": \"es_SV\",\n- \"es-US\": \"es_US\",\n- \"es-UY\": \"es_UY\",\n- \"es-VE\": \"es_VE\",\n- \"et\": \"et\",\n- \"eu\": \"eu\",\n- \"fa\": \"fa\",\n- \"fa-AF\": \"fa_AF\",\n- \"ff\": \"ff\",\n- \"fi\": \"fi\",\n- \"fil\": \"fil\",\n- \"fj\": \"fj\",\n- \"fo\": \"fo\",\n- \"fr\": \"fr\",\n- \"fr-BE\": \"fr_BE\",\n- \"fr-CA\": \"fr_CA\",\n- \"fr-CH\": \"fr_CH\",\n- \"fr-LU\": \"fr_LU\",\n- \"fr-QC\": \"fr_QC\",\n- \"fra-DE\": \"fra\",\n- \"frp\": \"frp\",\n- \"fur-IT\": \"fur\",\n- \"fy-NL\": \"fy\",\n- \"ga-IE\": \"ga\",\n- \"gaa\": \"gaa\",\n- \"gd\": \"gd\",\n- \"gl\": \"gl\",\n- \"gn\": \"gn\",\n- \"got\": \"got\",\n- \"gu-IN\": \"gu\",\n- \"gv\": \"gv\",\n- \"ha\": \"ha\",\n- \"haw\": \"haw\",\n- \"he\": \"he\",\n- \"hi\": \"hi\",\n- \"hil\": \"hil\",\n- \"hmn\": \"hmn\",\n- \"ho\": \"ho\",\n- \"hr\": \"hr\",\n- \"hsb-DE\": \"hsb\",\n- \"ht\": \"ht\",\n- \"hu\": \"hu\",\n- \"hy-AM\": \"hy\",\n- \"hz\": \"hz\",\n- \"id\": \"id\",\n- \"ido\": \"ido\",\n- \"ig\": \"ig\",\n- \"ii\": \"ii\",\n- \"ilo\": \"ilo\",\n- \"is\": \"is\",\n- \"it\": \"it\",\n- \"it-CH\": \"it_CH\",\n- \"iu\": \"iu\",\n- \"ja\": \"ja\",\n- \"jbo\": \"jbo\",\n- \"jv\": \"jv\",\n- \"ka\": \"ka\",\n- \"kab\": \"kab\",\n- \"kdh\": \"kdh\",\n- \"kg\": \"kg\",\n- \"kj\": \"kj\",\n- \"kk\": \"kk\",\n- \"kl\": \"kl\",\n- \"km\": \"km\",\n- \"kmr\": \"kmr\",\n- \"kn\": \"kn\",\n- \"ko\": \"ko\",\n- \"kok\": \"kok\",\n- \"ks\": \"ks\",\n- \"ks-PK\": \"ks_PK\",\n- \"ku\": \"ku\",\n- \"kv\": \"kv\",\n- \"kw\": \"kw\",\n- \"ky\": \"ky\",\n- \"la-LA\": \"la\",\n- \"lb\": \"lb\",\n- \"lg\": \"lg\",\n- \"li\": \"li\",\n- \"lij\": \"lij\",\n- \"ln\": \"ln\",\n- \"lo\": \"lo\",\n- \"lol\": \"lol\",\n- \"lt\": \"lt\",\n- \"luy\": \"luy\",\n- \"lv\": \"lv\",\n- \"mai\": \"mai\",\n- \"me\": \"me\",\n- \"mg\": \"mg\",\n- \"mh\": \"mh\",\n- \"mi\": \"mi\",\n- \"mk\": \"mk\",\n- \"ml-IN\": \"ml\",\n- \"mn\": \"mn\",\n- \"moh\": \"moh\",\n- \"mos\": \"mos\",\n- \"mr\": \"mr\",\n- \"ms\": \"ms\",\n- \"ms-BN\": \"ms_BN\",\n- \"mt\": \"mt\",\n- \"my\": \"my\",\n- \"na\": \"na\",\n- \"nb\": \"nb\",\n- \"nds\": \"nds\",\n- \"ne-IN\": \"ne_IN\",\n- \"ne-NP\": \"ne\",\n- \"ng\": \"ng\",\n- \"nl\": \"nl\",\n- \"nl-BE\": \"nl_BE\",\n- \"nl-SR\": \"nl_SR\",\n- \"nn-NO\": \"nn_NO\",\n- \"no\": \"no\",\n- \"nr\": \"nr\",\n- \"nso\": \"nso\",\n- \"ny\": \"ny\",\n- \"oc\": \"oc\",\n- \"oj\": \"oj\",\n- \"om\": \"om\",\n- \"or\": \"or\",\n- \"os\": \"os\",\n- \"pa-IN\": \"pa\",\n- \"pa-PK\": \"pa_PK\",\n- \"pam\": \"pam\",\n- \"pap\": \"pap\",\n- \"pcm\": \"pcm\",\n- \"pi\": \"pi\",\n- \"pl\": \"pl\",\n- \"ps\": \"ps\",\n- \"pt-BR\": \"pt_BR\",\n- \"pt-PT\": \"pt\",\n- \"qu\": \"qu\",\n- \"quc\": \"quc\",\n- \"qya-AA\": \"qya\",\n- \"rm-CH\": \"rm\",\n- \"rn\": \"rn\",\n- \"ro\": \"ro\",\n- \"ru\": \"ru\",\n- \"ru-BY\": \"ru_BY\",\n- \"ru-MD\": \"ru_MD\",\n- \"ru-UA\": \"ru_UA\",\n- \"rw\": \"rw\",\n- \"ry-UA\": \"ry\",\n- \"sa\": \"sa\",\n- \"sah\": \"sah\",\n- \"sat\": \"sat\",\n- \"sc\": \"sc\",\n- \"sco\": \"sco\",\n- \"sd\": \"sd\",\n- \"se\": \"se\",\n- \"sg\": \"sg\",\n- \"sh\": \"sh\",\n- \"si-LK\": \"si\",\n- \"sk\": \"sk\",\n- \"sl\": \"sl\",\n- \"sma\": \"sma\",\n- \"sn\": \"sn\",\n- \"so\": \"so\",\n- \"son\": \"son\",\n- \"sq\": \"sq\",\n- \"sr\": \"sr\",\n- \"sr-CS\": \"sr_CS\",\n- \"sr-Cyrl-ME\": \"sr_Cyrl_ME\",\n- \"ss\": \"ss\",\n- \"st\": \"st\",\n- \"su\": \"su\",\n- \"sv-FI\": \"sv_FI\",\n- \"sv-SE\": \"sv\",\n- \"sw\": \"sw\",\n- \"sw-KE\": \"sw_KE\",\n- \"sw-TZ\": \"sw_TZ\",\n- \"syc\": \"syc\",\n- \"ta\": \"ta\",\n- \"tay\": \"tay\",\n- \"te\": \"te\",\n- \"tg\": \"tg\",\n- \"th\": \"th\",\n- \"ti\": \"ti\",\n- \"tk\": \"tk\",\n- \"tl\": \"tl\",\n- \"tlh-AA\": \"tlh\",\n- \"tn\": \"tn\",\n- \"tr\": \"tr\",\n- \"tr-CY\": \"tr_CY\",\n- \"ts\": \"ts\",\n- \"tt-RU\": \"tt\",\n- \"tw\": \"tw\",\n- \"ty\": \"ty\",\n- \"tzl\": \"tzl\",\n- \"ug\": \"ug\",\n- \"uk\": \"uk\",\n- \"ur-IN\": \"ur_IN\",\n- \"ur-PK\": \"ur\",\n- \"uz\": \"uz\",\n- \"val-ES\": \"val\",\n- \"ve\": \"ve\",\n- \"vec\": \"vec\",\n- \"vi\": \"vi\",\n- \"vls-BE\": \"vls\",\n- \"wa\": \"wa\",\n- \"wo\": \"wo\",\n- \"xh\": \"xh\",\n- \"yi\": \"yi\",\n- \"yo\": \"yo\",\n- \"zea\": \"zea\",\n- \"zh-CN\": \"zh_Hans\", # Modified\n- \"zh-HK\": \"zh_HK\",\n- \"zh-MO\": \"zh_MO\",\n- \"zh-SG\": \"zh_SG\",\n- \"zh-TW\": \"zh_Hant\", # Modified\n- \"zu\": \"zu\"\n-}\n-\n-def from_crowdin(crowdin_code):\n- return FROM_CROWDIN_MAP[crowdin_code]\n-\n-if __name__ == \"__main__\":\n- if len(sys.argv) != 2:\n- raise Exception(\"Missing argument\\n\\nUsage: python3 language_map.py <crowdin language code>\")\n- crowdin_code = sys.argv[1]\n- try:\n- print(from_crowdin(crowdin_code))\n- except KeyError:\n- raise Exception(\"No mapping found for {}\".format(crowdin_code))\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Move crowdin bot python scripts into python package
|
701,855 |
19.11.2017 17:23:35
| -46,800 |
1a09dac4a9724996d99a281058ccc03526a2622b
|
Modify scripts to use python package
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/get-unused-crowdin-files.sh",
"new_path": "infrastructure/crowdin/get-unused-crowdin-files.sh",
"diff": "@@ -16,7 +16,7 @@ fi\ncd \"${CLONED_REPO_DIR}\"\n-python3 ../get_crowdin_files.py | sort > all_crowdin_files\n+python3 -m crowdin_bot.get_crowdin_files | sort > all_crowdin_files\ncrowdin -c \"${CROWDIN_CONFIG_FILE}\" --dryrun upload | sort > current_crowdin_files\n# Diff returns exit code 1 if diff found - don't abort script if that is the case\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-completed-translations.sh",
"new_path": "infrastructure/crowdin/update-completed-translations.sh",
"diff": "@@ -6,7 +6,7 @@ source config.sh\nsource utils.sh\nREPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\n-CLONED_REPO_DIR=\"translations-download-cloned-repo\"\n+CLONED_REPO_DIR=\"update-completed-translations-cloned-repo\"\nTRANSLATION_PR_BRANCH_BASE=\"${TRANSLATION_TARGET_BRANCH}-translations\"\n# Clone repo, deleting old clone if exists\n@@ -23,8 +23,10 @@ cd \"${CLONED_REPO_DIR}\"\ngit config user.name \"${GITHUB_BOT_NAME}\"\ngit config user.email \"${GITHUB_BOT_EMAIL}\"\n+python3 -m crowdin_bot.get_language_map --crowdin-config \"${CROWDIN_CONFIG_FILE}\" > language_map.json\n+\n# Populate array of all project languages\n-languages=($(python3 ../get_crowdin_languages.py))\n+languages=($(python3 -m crowdin_bot.get_crowdin_languages))\nfor language in ${languages[@]}; do\n@@ -38,7 +40,7 @@ for language in ${languages[@]}; do\ngit merge $TRANSLATION_TARGET_BRANCH --quiet --no-edit\n# Delete existing translation directories\n- mapped_code=$(python3 ../language_map.py ${language})\n+ mapped_code=$(cat ../language_map.json | python -c \"import json,sys;obj=json.load(sys.stdin);print(obj[\\\"${language}\\\"]);\")\nfor content_path in \"${CONTENT_PATHS[@]}\"; do\ntranslation_path=\"${content_path}/${mapped_code}\"\nif [ -d \"${translation_path}\" ]; then\n@@ -62,7 +64,7 @@ for language in ${languages[@]}; do\n# Get list of files that are completely translated/ready for committing\n# Note that .po files are included even if not completely translated\n- python3 ../get_complete_translations.py \"${language}\" > \"${language}_completed\"\n+ python3 -m crowdin_bot.get_complete_translations --crowdin-code \"${language}\" --csu-code \"${mapped_code}\" > \"${language}_completed\"\n# Loop through each completed translation file:\nwhile read path; do\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"new_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"diff": "@@ -31,8 +31,8 @@ git checkout $IN_CONTEXT_L10N_PR_BRANCH || git checkout -b $IN_CONTEXT_L10N_PR_B\ngit merge origin/$IN_CONTEXT_L10N_TARGET_BRANCH --quiet --no-edit\ncrowdin -c \"${CROWDIN_CONFIG_FILE}\" -l \"${CROWDIN_PSEUDO_LANGUAGE}\" download\n-python3 ../download_xliff.py\n-python3 ../modify_pseudo_translations.py\n+python3 -m crowdin_bot.download_xliff\n+python3 -m modify_pseudo_translations\ngit add \"csunplugged/topics/content/${CSU_PSEUDO_LANGUAGE}\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Modify scripts to use python package
|
701,855 |
19.11.2017 17:29:55
| -46,800 |
610f0587d3aa58121f9c0ca58592fd1fef940b8f
|
Fix language map bug
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/update-completed-translations.sh",
"new_path": "infrastructure/crowdin/update-completed-translations.sh",
"diff": "@@ -16,6 +16,8 @@ else\ngit clone \"${REPO}\" \"${CLONED_REPO_DIR}\" --branch ${TRANSLATION_TARGET_BRANCH}\nfi\n+python3 -m crowdin_bot.get_language_map --crowdin-config \"${CLONED_REPO_DIR}/${CROWDIN_CONFIG_FILE}\" > language_map.json\n+\n# Change into the working repo\ncd \"${CLONED_REPO_DIR}\"\n@@ -23,8 +25,6 @@ cd \"${CLONED_REPO_DIR}\"\ngit config user.name \"${GITHUB_BOT_NAME}\"\ngit config user.email \"${GITHUB_BOT_EMAIL}\"\n-python3 -m crowdin_bot.get_language_map --crowdin-config \"${CROWDIN_CONFIG_FILE}\" > language_map.json\n-\n# Populate array of all project languages\nlanguages=($(python3 -m crowdin_bot.get_crowdin_languages))\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Fix language map bug
|
701,855 |
19.11.2017 20:08:15
| -46,800 |
91166fab8ffb306aaad5ddcd15af2fcd1b3ab96e
|
Restructure crowdin_bot directory structure
|
[
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/config.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-config.sh",
"diff": ""
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/get-unused-crowdin-files.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-list-unused.sh",
"diff": "@@ -2,8 +2,8 @@ set -e\nset -x\nset -o pipefail\n-source config.sh\n-source utils.sh\n+source crowdin-bot-config.sh\n+source crowdin-bot-utils.sh\nCLONED_REPO_DIR=\"get-unused-crowdin-files-cloned-repo\"\n"
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/update-incontext-l10n.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-pull-incontext.sh",
"diff": "set -x\nset -o pipefail\n-source config.sh\n-source utils.sh\n+source crowdin-bot-config.sh\n+source crowdin-bot-utils.sh\nREPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\nCLONED_REPO_DIR=\"incontext-download-cloned-repo\"\n"
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/update-completed-translations.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-pull-translations.sh",
"diff": "@@ -2,8 +2,8 @@ set -e\nset -x\nset -o pipefail\n-source config.sh\n-source utils.sh\n+source crowdin-bot-config.sh\n+source crowdin-bot-utils.sh\nREPO=\"git@github.com:jordangriffiths01/crowdin_testing.git\"\nCLONED_REPO_DIR=\"update-completed-translations-cloned-repo\"\n"
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/upload-crowdin-source-files.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-push-source.sh",
"diff": "@@ -2,8 +2,8 @@ set -e\nset -x\nset -o pipefail\n-source config.sh\n-source utils.sh\n+source crowdin-bot-config.sh\n+source crowdin-bot-utils.sh\nCLONED_REPO_DIR=\"source-upload-cloned-repo\"\n"
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin/utils.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-utils.sh",
"diff": ""
},
{
"change_type": "RENAME",
"old_path": "infrastructure/crowdin_api_key.enc",
"new_path": "infrastructure/crowdin/crowdin_bot_secrets/crowdin_api_key.enc",
"diff": ""
},
{
"change_type": "RENAME",
"old_path": "infrastructure/gce_key.enc",
"new_path": "infrastructure/crowdin/crowdin_bot_secrets/gce_key.enc",
"diff": ""
},
{
"change_type": "RENAME",
"old_path": "infrastructure/uccser_bot_token.enc",
"new_path": "infrastructure/crowdin/crowdin_bot_secrets/uccser_bot_token.enc",
"diff": ""
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Restructure crowdin_bot directory structure
|
701,855 |
19.11.2017 20:08:49
| -46,800 |
1df76d89dc20bd3da0af67b99a5b25143fe735c1
|
Update setup-instance.sh script (almost production ready)
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/setup-instance.sh",
"new_path": "infrastructure/crowdin/setup-instance.sh",
"diff": "-# TODO: PAth manipulations?\n+set -e\n-tar -xvzf crowdin.tar.gz\n+SECRETS_DIR=\"crowdin_bot_secrets\"\n+SCRIPTS_DIR=\"crowdin_bot_scripts\"\n+PYTHON_PACKAGE_DIR=\"crowdin_bot_python_package\"\n+# Install packages\n+apt-get install git --yes\n+apt-get install default-jre --yes # Java, for crowdin cli\n+apt-get install python3-pip --yes\n+apt-get install python3-lxml --yes # Install here instead of pip3 because compilation uses too much RAM\n+pip3 install -U pip setuptools\n+pip3 install verto\n+\n+# Install crowdin cli\n+wget -qO - https://artifacts.crowdin.com/repo/GPG-KEY-crowdin | sudo apt-key add -\n+echo \"deb https://artifacts.crowdin.com/repo/deb/ /\" > /etc/apt/sources.list.d/crowdin.list\n+apt-get update\n+apt-get install crowdin --yes\n+\n+# Install hub\n+wget https://github.com/github/hub/releases/download/v2.2.5/hub-linux-amd64-2.2.5.tgz\n+tar zvxvf hub-linux-amd64-2.2.5.tgz\n+./hub-linux-amd64-2.2.5/install\n+rm -rf hub-linux-amd64-2.2.5\n+\n+# Unzip crowdin-bot source\n+tar -xvzf crowdin-bot.tar.gz\n+\n+# Move into secrets directory\n+cd \"${SECRETS_DIR}\"\n+\n+# Decrypt secrets\ngcloud kms decrypt --ciphertext-file=uccser_bot_token.enc --plaintext-file=uccser_bot_token --location=global --keyring=csunplugged-keyring --key=uccser-bot-token\ngcloud kms decrypt --ciphertext-file=crowdin_api_key.enc --plaintext-file=crowdin_api_key --location=global --keyring=csunplugged-keyring --key=crowdin-api-key\n+gcloud kms decrypt --ciphertext-file=gce_key.enc --plaintext-file=gce_key --location=global --keyring=csunplugged-keyring --key=uccser-bot-ssh-key\n+\n+# Add secret env vars to bashrc\ncat >> ~/.bashrc << EOF\nexport CROWDIN_API_KEY=$(cat crowdin_api_key)\nexport GITHUB_TOKEN=$(cat uccser_bot_token)\nEOF\n-# TODO: Activate service account to get access to KMS\n-gcloud kms decrypt --ciphertext-file=gce_key.enc --plaintext-file=gce_key --location=global --keyring=csunplugged-keyring --key=uccser-bot-ssh-key\n+# Add github ssh key to ssh agent\neval \"$(ssh-agent -s)\"\n-cp gce_key ~/.ssh\n-chmod 400 ~/.ssh/gce_key\n-ssh-add ~/.ssh/gce_key\n-\n+cp gce_key ~/.ssh/id_rsa\n+chmod 400 ~/.ssh/id_rsa\n+# ...and add it to config file in case of restart\n+# TODO: Fix this, it's not registering properly, so can't git clone\ncat >> ~/.ssh/config << EOF\nHost github.com\nIdentityFile ~/.ssh/gce_key\n+ StrictHostKeyChecking no\nEOF\n-apt-get install git --yes\n-apt-get install python3-pip\n-pip3 install verto\n-apt-get install python3-lxml # Can't use pip - not enough RAM for compilation!\n+# Move into scripts directory\n+cd ..\n+cd \"${SCRIPTS_DIR}\"\n-# Install Crowdin CLI\n-wget -qO - https://artifacts.crowdin.com/repo/GPG-KEY-crowdin | sudo apt-key add -\n-echo \"deb https://artifacts.crowdin.com/repo/deb/ /\" > /etc/apt/sources.list.d/crowdin.list\n-apt-get update\n-apt-get install crowdin --yes\n-# ... and Java dependency\n-apt-get install default-jre --yes\n+# Copy scripts into /usr/local/bin and make them executable\n+for script in *; do\n+ cp \"${script}\" /usr/local/bin\n+ chmod +x \"/usr/local/bin/${script}\"\n+done\n-# Install hub\n-wget https://github.com/github/hub/releases/download/v2.2.5/hub-linux-amd64-2.2.5.tgz\n-tar zvxvf hub-linux-amd64-2.2.5.tgz\n-sudo ./hub-linux-amd64-2.2.5/install\n+# Return to parent directory\n+cd ..\n+\n+# Install crowdin-bot python package\n+pip3 install \"${PYTHON_PACKAGE_DIR}\"/\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update setup-instance.sh script (almost production ready)
|
701,855 |
19.11.2017 20:09:30
| -46,800 |
65e77fe33c3ffb44f262eb2187364be83c4a0c36
|
Add deployment script for crowdin_bot
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/deploy.sh",
"diff": "+set -e\n+\n+PROJECT=\"cs-unplugged-dev\"\n+ZONE=\"us-central1-c\"\n+\n+INSTANCE_NAME=\"crowdin-bot\"\n+MACHINE_TYPE=\"f1-micro\"\n+SERVICE_ACCOUNT=\"uccser-bot@cs-unplugged-dev.iam.gserviceaccount.com\"\n+\n+# Create instance\n+gcloud compute --project \"${PROJECT}\" instances create \"${INSTANCE_NAME}\" \\\n+ --zone \"${ZONE}\" --machine-type \"${MACHINE_TYPE}\" \\\n+ --image-family \"ubuntu-1404-lts\" \\\n+ --image-project \"ubuntu-os-cloud\" \\\n+ --service-account \"${SERVICE_ACCOUNT}\" \\\n+ --scopes \"https://www.googleapis.com/auth/cloudkms\" \\\n+ --boot-disk-size \"10\" --boot-disk-type \"pd-standard\"\n+\n+# Transfer files to instance\n+tar cvzf crowdin-bot.tar.gz crowdin_bot_python_package crowdin_bot_scripts crowdin_bot_secrets\n+gcloud beta compute scp setup-instance.sh crowdin-bot.tar.gz \"${INSTANCE_NAME}:/tmp\" --zone=\"${ZONE}\"\n+\n+# Unzip files and run setup script\n+gcloud compute ssh \"${INSTANCE_NAME}\" --zone=\"${ZONE}\" -- \"cp /tmp/crowdin-bot.tar.gz /tmp/setup-instance.sh ~ && chmod +x setup-instance.sh && sudo ./setup-instance.sh\"\n+\n+\n+\n+# Only once, check in encrypted key\n+# gcloud kms encrypt --plaintext-file=gce_key --ciphertext-file=gce_key.enc --keyring=csunplugged-keyring --key=uccser-bot-ssh-key --location=global\n+# gcloud kms encrypt --plaintext-file=crowdin_api_key --ciphertext-file=crowdin_api_key.enc --keyring=csunplugged-keyring --key=crowdin-api-key --location=global\n+# gcloud kms encrypt --plaintext-file=uccser_bot_token --ciphertext-file=uccser_bot_token.enc --keyring=csunplugged-keyring --key=uccser-bot-token --location=global\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add deployment script for crowdin_bot
|
701,855 |
20.11.2017 01:02:38
| -46,800 |
e17e73232f4187208eb0da5a225d6586f902fd14
|
Add bash shebang lines
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-config.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-config.sh",
"diff": "+#!/usr/bin/env bash\n+\n# CS Unplugged repo\nREPO=\"git@github.com:uccser/cs-unplugged.git\"\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-list-unused.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-list-unused.sh",
"diff": "+#!/usr/bin/env bash\n+\nset -e\nset -x\nset -o pipefail\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-pull-incontext.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-pull-incontext.sh",
"diff": "-# Deal with SSH KEYS here\n+#!/usr/bin/env bash\n+\nset -e\nset -x\nset -o pipefail\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-pull-translations.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-pull-translations.sh",
"diff": "+#!/usr/bin/env bash\n+\nset -e\nset -x\nset -o pipefail\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-push-source.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-push-source.sh",
"diff": "+#!/usr/bin/env bash\n+\nset -e\nset -x\nset -o pipefail\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-utils.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-utils.sh",
"diff": "+#!/usr/bin/env bash\n+\nreset_repo() {\nrepo_dir=$1\nbranch=$2\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add bash shebang lines
|
701,855 |
20.11.2017 01:03:01
| -46,800 |
915534a748448897e4145efbaf3de5d6dba21db5
|
Bugfix in download_xliff
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/download_xliff.py",
"new_path": "infrastructure/crowdin/crowdin_bot_python_package/crowdin_bot/download_xliff.py",
"diff": "@@ -10,7 +10,6 @@ XLIFF_DIR = os.path.join(CONTENT_ROOT, 'xliff')\ndef download_xliff(source_filename, dest_filename, language=INCONTEXT_L10N_PSEUDOLANGUAGE_CROWDIN):\nparams = {\n- \"key\" : API_KEY,\n\"file\": source_filename,\n\"language\": language,\n\"format\": \"xliff\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Bugfix in download_xliff
|
701,855 |
20.11.2017 01:03:36
| -46,800 |
ef178f38fa9608e8f7dd1c3adeb266764924574e
|
Refine setup-instance.sh, add crontab configuration
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/setup-instance.sh",
"new_path": "infrastructure/crowdin/setup-instance.sh",
"diff": "@@ -5,23 +5,23 @@ SCRIPTS_DIR=\"crowdin_bot_scripts\"\nPYTHON_PACKAGE_DIR=\"crowdin_bot_python_package\"\n# Install packages\n-apt-get install git --yes\n-apt-get install default-jre --yes # Java, for crowdin cli\n-apt-get install python3-pip --yes\n-apt-get install python3-lxml --yes # Install here instead of pip3 because compilation uses too much RAM\n-pip3 install -U pip setuptools\n-pip3 install verto\n+sudo apt-get install git --yes\n+sudo apt-get install default-jre --yes # Java, for crowdin cli\n+sudo apt-get install python3-pip --yes\n+sudo apt-get install python3-lxml --yes # Install here instead of pip3 because compilation uses too much RAM\n+sudo pip3 install -U pip setuptools\n+sudo pip3 install verto pyyaml\n# Install crowdin cli\nwget -qO - https://artifacts.crowdin.com/repo/GPG-KEY-crowdin | sudo apt-key add -\n-echo \"deb https://artifacts.crowdin.com/repo/deb/ /\" > /etc/apt/sources.list.d/crowdin.list\n-apt-get update\n-apt-get install crowdin --yes\n+echo \"deb https://artifacts.crowdin.com/repo/deb/ /\" | sudo tee /etc/apt/sources.list.d/crowdin.list > /dev/null\n+sudo apt-get update\n+sudo apt-get install crowdin --yes\n# Install hub\nwget https://github.com/github/hub/releases/download/v2.2.5/hub-linux-amd64-2.2.5.tgz\ntar zvxvf hub-linux-amd64-2.2.5.tgz\n-./hub-linux-amd64-2.2.5/install\n+sudo ./hub-linux-amd64-2.2.5/install\nrm -rf hub-linux-amd64-2.2.5\n# Unzip crowdin-bot source\n@@ -36,36 +36,41 @@ gcloud kms decrypt --ciphertext-file=crowdin_api_key.enc --plaintext-file=crowdi\ngcloud kms decrypt --ciphertext-file=gce_key.enc --plaintext-file=gce_key --location=global --keyring=csunplugged-keyring --key=uccser-bot-ssh-key\n# Add secret env vars to bashrc\n-cat >> ~/.bashrc << EOF\n+cat > crowdin-bot-env-secrets.sh << EOF\nexport CROWDIN_API_KEY=$(cat crowdin_api_key)\nexport GITHUB_TOKEN=$(cat uccser_bot_token)\nEOF\n+sudo cp crowdin-bot-env-secrets.sh \"../${SCRIPTS_DIR}\"\n-# Add github ssh key to ssh agent\n-eval \"$(ssh-agent -s)\"\n-cp gce_key ~/.ssh/id_rsa\n-chmod 400 ~/.ssh/id_rsa\n-# ...and add it to config file in case of restart\n-# TODO: Fix this, it's not registering properly, so can't git clone\n+# Setup github SSH key\n+cp gce_key ~/.ssh/gce_key\n+chmod 400 ~/.ssh/gce_key\ncat >> ~/.ssh/config << EOF\nHost github.com\nIdentityFile ~/.ssh/gce_key\nStrictHostKeyChecking no\nEOF\n-\n# Move into scripts directory\ncd ..\ncd \"${SCRIPTS_DIR}\"\n# Copy scripts into /usr/local/bin and make them executable\nfor script in *; do\n- cp \"${script}\" /usr/local/bin\n- chmod +x \"/usr/local/bin/${script}\"\n+ sudo cp \"${script}\" /usr/local/bin\n+ sudo chmod +x \"/usr/local/bin/${script}\"\ndone\n# Return to parent directory\ncd ..\n# Install crowdin-bot python package\n-pip3 install \"${PYTHON_PACKAGE_DIR}\"/\n+sudo pip3 install \"${PYTHON_PACKAGE_DIR}\"/\n+\n+# Setup crontab\n+crontab << EOF\n+SHELL=/bin/bash\n+4 12 * * * PATH=\\$PATH:/usr/local/bin; source crowdin-bot-env-secrets.sh; crowdin-bot-push-source.sh > crowdin-bot-push-source.log 2> crowdin-bot-push-source.err\n+4 13 * * * PATH=\\$PATH:/usr/local/bin; source crowdin-bot-env-secrets.sh; crowdin-bot-pull-translations.sh > crowdin-bot-push-source.log 2> crowdin-bot-pull-translations.err\n+4 14 * * * PATH=\\$PATH:/usr/local/bin; source crowdin-bot-env-secrets.sh; crowdin-bot-pull-incontext.sh > crowdin-bot-pull-incontext.log 2> crowdin-bot-pull-incontext.err\n+EOF\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Refine setup-instance.sh, add crontab configuration
|
701,855 |
20.11.2017 01:07:35
| -46,800 |
1c45d579767d7cfbeafd0b76259e26ab18721c01
|
Tidyup deploy script
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/deploy.sh",
"new_path": "infrastructure/crowdin/deploy.sh",
"diff": "@@ -21,11 +21,4 @@ tar cvzf crowdin-bot.tar.gz crowdin_bot_python_package crowdin_bot_scripts crowd\ngcloud beta compute scp setup-instance.sh crowdin-bot.tar.gz \"${INSTANCE_NAME}:/tmp\" --zone=\"${ZONE}\"\n# Unzip files and run setup script\n-gcloud compute ssh \"${INSTANCE_NAME}\" --zone=\"${ZONE}\" -- \"cp /tmp/crowdin-bot.tar.gz /tmp/setup-instance.sh ~ && chmod +x setup-instance.sh && sudo ./setup-instance.sh\"\n-\n-\n-\n-# Only once, check in encrypted key\n-# gcloud kms encrypt --plaintext-file=gce_key --ciphertext-file=gce_key.enc --keyring=csunplugged-keyring --key=uccser-bot-ssh-key --location=global\n-# gcloud kms encrypt --plaintext-file=crowdin_api_key --ciphertext-file=crowdin_api_key.enc --keyring=csunplugged-keyring --key=crowdin-api-key --location=global\n-# gcloud kms encrypt --plaintext-file=uccser_bot_token --ciphertext-file=uccser_bot_token.enc --keyring=csunplugged-keyring --key=uccser-bot-token --location=global\n+gcloud compute ssh \"${INSTANCE_NAME}\" --zone=\"${ZONE}\" -- \"cp /tmp/crowdin-bot.tar.gz /tmp/setup-instance.sh ~ && chmod +x setup-instance.sh && ./setup-instance.sh\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Tidyup deploy script
|
701,855 |
20.11.2017 01:08:06
| -46,800 |
e7baf320c9d3325bd0edef810d3761110d81e670
|
Add encrypt-secrets.sh script
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "infrastructure/crowdin/encrypt-secrets.sh",
"diff": "+# Encrypt file \"gce_key\", a github ssh private key attached to the uccser bot account\n+gcloud kms encrypt --plaintext-file=gce_key --ciphertext-file=gce_key.enc --keyring=csunplugged-keyring --key=uccser-bot-ssh-key --location=global\n+\n+# Encrypt file \"uccser_bot_token\", the github personal access token for the uccser bot account\n+gcloud kms encrypt --plaintext-file=uccser_bot_token --ciphertext-file=uccser_bot_token.enc --keyring=csunplugged-keyring --key=uccser-bot-token --location=global\n+\n+# Encrypt file \"crowdin_api_key\", the crowdin API key\n+gcloud kms encrypt --plaintext-file=crowdin_api_key --ciphertext-file=crowdin_api_key.enc --keyring=csunplugged-keyring --key=crowdin-api-key --location=global\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add encrypt-secrets.sh script
|
701,855 |
20.11.2017 10:42:41
| -46,800 |
0ee3a9260eed36bd7b0476476a87de065155b0e8
|
Bugfix in pull-incontext script
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-pull-incontext.sh",
"new_path": "infrastructure/crowdin/crowdin_bot_scripts/crowdin-bot-pull-incontext.sh",
"diff": "@@ -33,7 +33,7 @@ git merge origin/$IN_CONTEXT_L10N_TARGET_BRANCH --quiet --no-edit\ncrowdin -c \"${CROWDIN_CONFIG_FILE}\" -l \"${CROWDIN_PSEUDO_LANGUAGE}\" download\npython3 -m crowdin_bot.download_xliff\n-python3 -m modify_pseudo_translations\n+python3 -m crowdin_bot.modify_pseudo_translations\ngit add \"csunplugged/topics/content/${CSU_PSEUDO_LANGUAGE}\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Bugfix in pull-incontext script
|
701,855 |
20.11.2017 10:43:18
| -46,800 |
dd0224452deaa61215189815b44db0d27a57ba3e
|
Add retry on scp command to wait for instance to be up
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/deploy.sh",
"new_path": "infrastructure/crowdin/deploy.sh",
"diff": "@@ -8,6 +8,7 @@ MACHINE_TYPE=\"f1-micro\"\nSERVICE_ACCOUNT=\"uccser-bot@cs-unplugged-dev.iam.gserviceaccount.com\"\n# Create instance\n+echo \"Creating instance ${INSTANCE_NAME}\"\ngcloud compute --project \"${PROJECT}\" instances create \"${INSTANCE_NAME}\" \\\n--zone \"${ZONE}\" --machine-type \"${MACHINE_TYPE}\" \\\n--image-family \"ubuntu-1404-lts\" \\\n@@ -17,8 +18,21 @@ gcloud compute --project \"${PROJECT}\" instances create \"${INSTANCE_NAME}\" \\\n--boot-disk-size \"10\" --boot-disk-type \"pd-standard\"\n# Transfer files to instance\n-tar cvzf crowdin-bot.tar.gz crowdin_bot_python_package crowdin_bot_scripts crowdin_bot_secrets\n-gcloud beta compute scp setup-instance.sh crowdin-bot.tar.gz \"${INSTANCE_NAME}:/tmp\" --zone=\"${ZONE}\"\n+source_tarball=crowdin-bot.tar.gz\n+echo \"Creating tarball ${source_tarball}\"\n+tar cvzf \"${source_tarball}\" crowdin_bot_python_package crowdin_bot_scripts crowdin_bot_secrets\n+for i in $(seq 1 10); do\n+ echo \"Copying ${source_tarball} to /tmp on ${INSTANCE_NAME}\"\n+ gcloud beta compute scp setup-instance.sh \"${source_tarball}\" \"${INSTANCE_NAME}:/tmp\" --zone=\"${ZONE}\" && break\n+ echo \"Could not SCP, instance is probably still booting. Retrying in 10 seconds\"\n+ sleep 10\n+done\n# Unzip files and run setup script\n+echo \"Setting up instance and installing crowdin_bot\"\ngcloud compute ssh \"${INSTANCE_NAME}\" --zone=\"${ZONE}\" -- \"cp /tmp/crowdin-bot.tar.gz /tmp/setup-instance.sh ~ && chmod +x setup-instance.sh && ./setup-instance.sh\"\n+\n+echo \"Cleaning up\"\n+rm crowdin-bot.tar.gz\n+\n+echo \"Deployed Successfully\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add retry on scp command to wait for instance to be up
|
701,855 |
20.11.2017 10:43:59
| -46,800 |
c272348c21c332eb31a28a2ba2a447c8a9aea3b8
|
Bugfix - wrong logfile name
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/crowdin/setup-instance.sh",
"new_path": "infrastructure/crowdin/setup-instance.sh",
"diff": "@@ -71,6 +71,6 @@ sudo pip3 install \"${PYTHON_PACKAGE_DIR}\"/\ncrontab << EOF\nSHELL=/bin/bash\n4 12 * * * PATH=\\$PATH:/usr/local/bin; source crowdin-bot-env-secrets.sh; crowdin-bot-push-source.sh > crowdin-bot-push-source.log 2> crowdin-bot-push-source.err\n-4 13 * * * PATH=\\$PATH:/usr/local/bin; source crowdin-bot-env-secrets.sh; crowdin-bot-pull-translations.sh > crowdin-bot-push-source.log 2> crowdin-bot-pull-translations.err\n+4 13 * * * PATH=\\$PATH:/usr/local/bin; source crowdin-bot-env-secrets.sh; crowdin-bot-pull-translations.sh > crowdin-bot-pull-translations.log 2> crowdin-bot-pull-translations.err\n4 14 * * * PATH=\\$PATH:/usr/local/bin; source crowdin-bot-env-secrets.sh; crowdin-bot-pull-incontext.sh > crowdin-bot-pull-incontext.log 2> crowdin-bot-pull-incontext.err\nEOF\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Bugfix - wrong logfile name
|
701,855 |
20.11.2017 18:14:25
| -46,800 |
31e105ce31dc3a2243c5bfddab3609ef71c1b026
|
Add ResourceParameter class and subclasses to store parameter info
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/resources/utils/resource_parameters.py",
"diff": "+from lxml import etree\n+from django.utils.translation import ugettext as _\n+\n+class ResourceParameter(object):\n+ def __init__(self, name=\"\", description=\"\"):\n+ self.name = name\n+ self.description = description\n+\n+ def html_element(self):\n+ legend = etree.Element('legend')\n+ legend.text = self.description\n+ fieldset = etree.Element('fieldset')\n+ fieldset.append(legend)\n+ return fieldset\n+\n+\n+class EnumResourceParameter(ResourceParameter):\n+ def __init__(self, values=[], default=None, **kwargs):\n+ super().__init__(**kwargs)\n+ self.values = values\n+ self.default = default\n+ if self.default not in self.values:\n+ raise Exception(self.values)\n+\n+ def html_element(self):\n+ base_elem = super().html_element()\n+ for value, value_desc in self.values.items():\n+ input_elem = etree.Element(\n+ 'input',\n+ type=\"radio\",\n+ name=self.name,\n+ id='{}_{}'.format(self.name, value),\n+ value=str(value)\n+ )\n+ if value == self.default:\n+ input_elem.set(\"checked\", \"checked\")\n+ base_elem.append(input_elem)\n+ label_elem = etree.Element(\n+ \"label\",\n+ )\n+ label_elem.set(\"for\", \"{}_{}\".format(self.name, value))\n+ label_elem.text = value_desc\n+ base_elem.append(label_elem)\n+ base_elem.append(etree.Element('br'))\n+ return base_elem\n+\n+class BoolResourceParameter(EnumResourceParameter):\n+ def __init__(self, default=True, true_text=_(\"Yes\"), false_text=_(\"No\"), **kwargs):\n+ values = {\n+ True: true_text,\n+ False: false_text\n+ }\n+ super().__init__(values=values, default=default, **kwargs)\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add ResourceParameter class and subclasses to store parameter info
|
701,855 |
20.11.2017 18:57:14
| -46,800 |
326de93b0985c4bdf71ff532212e1b322bb38962
|
Update generators to use ResourceParameter class to store param info
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BarcodeChecksumPosterResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BarcodeChecksumPosterResourceGenerator.py",
"diff": "@@ -4,13 +4,23 @@ from PIL import Image, ImageDraw\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\nfrom utils.TextBoxDrawer import TextBoxDrawer\nfrom django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter\n+BARCODE_LENGTH_VALUES = {\n+ \"12\": _(\"12 digits\"),\n+ \"13\": _(\"13 digits\")\n+}\nclass BarcodeChecksumPosterResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Grid resource generator.\"\"\"\n- additional_valid_options = {\n- \"barcode_length\": [\"12\", \"13\"]\n+ additional_options = {\n+ \"barcode_length\": EnumResourceParameter(\n+ name=\"barcode_length\",\n+ description=_(\"Barcode length\"),\n+ values=BARCODE_LENGTH_VALUES,\n+ default=\"12\"\n+ )\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryCardsResourceGenerator.py",
"diff": "import os.path\nfrom PIL import Image, ImageDraw, ImageFont\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import BoolResourceParameter\nBASE_IMAGE_PATH = \"static/img/resources/binary-cards/\"\nIMAGE_SIZE_X = 2480\n@@ -22,9 +24,19 @@ IMAGE_DATA = [\nclass BinaryCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary Cards resource generator.\"\"\"\n- additional_valid_options = {\n- \"display_numbers\": [True, False],\n- \"black_back\": [True, False],\n+ additional_options = {\n+ \"display_numbers\": BoolResourceParameter(\n+ name=\"display_numbers\",\n+ description=_(\"Display Numbers\"),\n+ default=True\n+ ),\n+ \"black_back\": BoolResourceParameter(\n+ name=\"black_back\",\n+ description=_(\"Black on Card Back\"),\n+ default=False,\n+ true_text=_(\"Yes - Uses a lot of black ink, but conveys clearer card state. Print double sided.\"),\n+ false_text=_(\"No - Print single sided.\")\n+ )\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryCardsSmallResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryCardsSmallResourceGenerator.py",
"diff": "from PIL import Image, ImageDraw, ImageFont\nimport os.path\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter, BoolResourceParameter\n+\nBASE_IMAGE_PATH = \"static/img/resources/binary-cards-small/\"\nIMAGE_SIZE_X = 2480\n@@ -13,10 +16,36 @@ IMAGE_DATA = [\n(\"binary-cards-small-3.png\", 12),\n]\n+NUMBER_BITS_VALUES = {\n+ \"4\": _(\"Four (1 to 8)\"),\n+ \"8\": _(\"Eight (1 to 128)\"),\n+ \"12\": _(\"Twelve (1 to 2048)\")\n+}\n+\nclass BinaryCardsSmallResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary Cards (small) resource generator.\"\"\"\n+ additional_options = {\n+ \"number_bits\": EnumResourceParameter(\n+ name=\"number_bits\",\n+ description=_(\"Number of Bits\"),\n+ values=NUMBER_BITS_VALUES,\n+ default=\"4\"\n+ ),\n+ \"dot_counts\": BoolResourceParameter(\n+ name=\"dot_counts\",\n+ description=_(\"Display Dot Counts\"),\n+ default=True,\n+ ),\n+ \"black_back\": BoolResourceParameter(\n+ name=\"black_back\",\n+ description=_(\"Black on Card Back\"),\n+ default=False,\n+ true_text=_(\"Yes - Uses a lot of black ink, but conveys clearer card state. Print double sided.\"),\n+ false_text=_(\"No - Print single sided.\")\n+ )\n+ }\nadditional_valid_options = {\n\"number_bits\": [\"4\", \"8\", \"12\"],\n\"dot_counts\": [True, False],\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryToAlphabetResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryToAlphabetResourceGenerator.py",
"diff": "from PIL import Image, ImageDraw, ImageFont\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter\n+WORKSHEET_VERSION_VALUES = {\n+ \"student\": _(\"Student\"),\n+ \"teacher\": _(\"Teacher (solutions)\")\n+}\n+\nclass BinaryToAlphabetResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary to Alphabet resource generator.\"\"\"\n+ additional_options = {\n+ \"worksheet_version\": EnumResourceParameter(\n+ name=\"worksheet_version\",\n+ description=_(\"Worksheet Version\"),\n+ values=WORKSHEET_VERSION_VALUES,\n+ default=\"student\"\n+ )\n+ }\n+\nadditional_valid_options = {\n\"worksheet_version\": [\"student\", \"teacher\"],\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryWindowsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryWindowsResourceGenerator.py",
"diff": "import os.path\nfrom PIL import Image, ImageDraw, ImageFont\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter, BoolResourceParameter\nBASE_IMAGE_PATH = \"static/img/resources/binary-windows/\"\nFONT_PATH = \"static/fonts/PatrickHand-Regular.ttf\"\nFONT = ImageFont.truetype(FONT_PATH, 300)\nSMALL_FONT = ImageFont.truetype(FONT_PATH, 180)\n+NUMBER_BITS_VALUES = {\n+ \"4\": _(\"Four (1 to 8)\"),\n+ \"8\": _(\"Eight (1 to 128)\")\n+}\n+\n+VALUE_TYPE_VALUES = {\n+ \"binary\": _(\"Binary (0 or 1)\"),\n+ \"lightbulb\": _(\"Lightbulb (off or on)\")\n+}\nclass BinaryWindowsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary Windows resource generator.\"\"\"\n+ additional_options = {\n+ \"number_bits\": EnumResourceParameter(\n+ name=\"number_bits\",\n+ description=_(\"Number of Bits\"),\n+ values=NUMBER_BITS_VALUES,\n+ default=\"4\"\n+ ),\n+ \"dot_counts\": BoolResourceParameter(\n+ name=\"dot_counts\",\n+ description=_(\"Display Dot Counts\"),\n+ default=True\n+ ),\n+ \"value_type\": EnumResourceParameter(\n+ name=\"value_type\",\n+ description=_(\"Value Representation\"),\n+ values=VALUE_TYPE_VALUES,\n+ default=\"binary\"\n+ ),\n- additional_valid_options = {\n- \"number_bits\": [\"4\", \"8\"],\n- \"value_type\": [\"binary\", \"lightbulb\"],\n- \"dot_counts\": [True, False],\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/ModuloClockResourceGenerator.py",
"new_path": "csunplugged/resources/generators/ModuloClockResourceGenerator.py",
"diff": "from PIL import Image, ImageDraw, ImageFont\nfrom math import pi, sin, cos\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter\n+MODULO_NUMBER_VALUES = {\n+ \"1\": \"Blank\",\n+ \"2\": \"2\",\n+ \"10\": \"10\"\n+}\nclass ModuloClockResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Modulo Clock resource generator.\"\"\"\n-\n- additional_valid_options = {\n- \"modulo_number\": [\"1\", \"2\", \"10\"],\n+ additional_options = {\n+ \"modulo_number\": EnumResourceParameter(\n+ name=\"modulo_number\",\n+ description=_(\"Modulo\"),\n+ values=MODULO_NUMBER_VALUES\n+ )\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/ParityCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/ParityCardsResourceGenerator.py",
"diff": "from PIL import Image, ImageDraw\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter\nCARDS_COLUMNS = 4\nCARDS_ROWS = 5\n@@ -11,12 +13,23 @@ IMAGE_SIZE_Y = CARD_SIZE * CARDS_ROWS\nLINE_COLOUR = \"#000000\"\nLINE_WIDTH = 3\n+BACK_COLOUR_VALUES={\n+ \"black\": _(\"Black\"),\n+ \"blue\": _(\"Blue\"),\n+ \"green\": _(\"Green\"),\n+ \"purple\": _(\"Purple\"),\n+ \"red\": _(\"Red\")\n+}\nclass ParityCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Parity Cards resource generator.\"\"\"\n-\n- additional_valid_options = {\n- \"back_colour\": [\"black\", \"blue\", \"green\", \"purple\", \"red\"],\n+ additional_options = {\n+ \"back_colour\": EnumResourceParameter(\n+ name=\"barcode_length\",\n+ description=_(\"Card back colour\"),\n+ values=BACK_COLOUR_VALUES,\n+ default=\"black\"\n+ )\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/PianoKeysResourceGenerator.py",
"new_path": "csunplugged/resources/generators/PianoKeysResourceGenerator.py",
"diff": "from PIL import Image, ImageDraw\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\nfrom utils.bool_to_yes_no import bool_to_yes_no\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter\nKEY_DATA = {\n\"A\": {\n@@ -56,12 +58,26 @@ KEY_DATA = {\n},\n}\n+HIGHLIGHT_VALUES = {\n+ False: _(\"None\"),\n+ \"A\": \"A\",\n+ \"B\": \"B\",\n+ \"C\": \"C\",\n+ \"D\": \"D\",\n+ \"E\": \"E\",\n+ \"F\": \"F\",\n+ \"G\": \"G\"\n+}\nclass PianoKeysResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Piano Keys resource generator.\"\"\"\n-\n- additional_valid_options = {\n- \"highlight\": [False, \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\"],\n+ additional_options = {\n+ \"highlight\": EnumResourceParameter(\n+ name=\"highlight\",\n+ description=_(\"Piano keys to highlight\"),\n+ values=HIGHLIGHT_VALUES,\n+ default=False\n+ )\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/PixelPainterResourceGenerator.py",
"new_path": "csunplugged/resources/generators/PixelPainterResourceGenerator.py",
"diff": "@@ -7,14 +7,37 @@ import string\nfrom shutil import copy2\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\nfrom django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter\n+METHOD_VALUES = {\n+ \"black-white\": _(\"Black and White (2 possible binary values)\"),\n+ \"run-length-encoding\": _(\"Black and White (2 possible binary values) in Run Length Encoding\"),\n+ \"greyscale\": _(\"Greyscale (4 possible binary values)\"),\n+ \"colour\": _(\"Colour (8 possible binary values)\")\n+}\n+\n+IMAGE_VALUES = {\n+ \"fish\": _(\"Fish - 6 pages\"),\n+ \"hot-air-balloon\": _(\"Hot air balloon - 8 pages\"),\n+ \"boat\": _(\"Boat - 9 pages\"),\n+ \"parrots\": _(\"Parrots - 32 pages\")\n+}\nclass PixelPainterResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Pixel Painter resource generator.\"\"\"\n-\n- additional_valid_options = {\n- \"method\": [\"black-white\", \"run-length-encoding\", \"greyscale\", \"colour\"],\n- \"image\": [\"boat\", \"fish\", \"hot-air-balloon\", \"parrots\"],\n+ additional_options = {\n+ \"method\": EnumResourceParameter(\n+ name=\"method\",\n+ description=_(\"Colouring type\"),\n+ values=METHOD_VALUES,\n+ default=\"black-white\"\n+ ),\n+ \"image\": EnumResourceParameter(\n+ name=\"image\",\n+ description=_(\"Image\"),\n+ values=IMAGE_VALUES,\n+ default=\"fish\"\n+ ),\n}\nmethods = {\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/SearchingCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/SearchingCardsResourceGenerator.py",
"diff": "@@ -5,7 +5,8 @@ from math import ceil\nfrom PIL import Image, ImageDraw, ImageFont\nfrom yattag import Doc\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n-\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter, BoolResourceParameter\nIMAGE_PATH = \"static/img/resources/searching-cards/{}-cards-{}.png\"\nX_BASE_COORD = 1803\nX_COORD_DECREMENT = 516\n@@ -13,14 +14,38 @@ Y_COORD = 240\nFONT_PATH = \"static/fonts/PatrickHand-Regular.ttf\"\nFONT = ImageFont.truetype(FONT_PATH, 200)\n+NUMBER_CARDS_VALUES = {\n+ \"15\": \"15\",\n+ \"31\": \"31\",\n+}\n+\n+MAX_NUMBER_VALUE = {\n+ \"cards\": _(\"Number of cards (15 or 31)\"),\n+ \"99\": _(\"0 to 99\"),\n+ \"999\": _(\"0 to 999\"),\n+ \"blank\": _(\"Blank\")\n+}\nclass SearchingCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Searching Cards resource generator.\"\"\"\n-\n- additional_valid_options = {\n- \"number_cards\": [\"15\", \"31\"],\n- \"max_number\": [\"cards\", \"99\", \"999\", \"blank\"],\n- \"help_sheet\": [True, False],\n+ additional_options = {\n+ \"number_cards\": EnumResourceParameter(\n+ name=\"number_cards\",\n+ description=_(\"Number of cards\"),\n+ values=NUMBER_CARDS_VALUES,\n+ default=\"15\"\n+ ),\n+ \"max_number\": EnumResourceParameter(\n+ name=\"max_number\",\n+ description=_(\"Range of numbers\"),\n+ values=MAX_NUMBER_VALUE,\n+ default=\"number\"\n+ ),\n+ \"help_sheet\": BoolResourceParameter(\n+ name=\"help_sheet\",\n+ description=_(\"Include teacher guide sheet\"),\n+ default=True\n+ ),\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/SortingNetworkResourceGenerator.py",
"new_path": "csunplugged/resources/generators/SortingNetworkResourceGenerator.py",
"diff": "from PIL import Image, ImageDraw, ImageFont\nfrom random import sample\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter\n+PREFILLED_VALUES_VALUES = {\n+ \"easy\": _(\"Easy Numbers (1 digits)\"),\n+ \"medium\": _(\"Medium Numbers (2 digits)\"),\n+ \"hard\": _(\"Hard Numbers (3 digits)\"),\n+ \"none\": _(\"None (Blank - Useful as template) \")\n+}\nclass SortingNetworkResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Sorting Network resource generator.\"\"\"\n-\n- additional_valid_options = {\n- \"prefilled_values\": [\"blank\", \"easy\", \"medium\", \"hard\"]\n+ additional_options = {\n+ \"prefilled_values\": EnumResourceParameter(\n+ name=\"prefilled_values\",\n+ description=_(\"Prefill with Numbers\"),\n+ values=PREFILLED_VALUES_VALUES,\n+ default=\"none\"\n+ ),\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/TrainStationsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/TrainStationsResourceGenerator.py",
"diff": "from PIL import Image\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from django.utils.translation import ugettext as _\n+from resources.utils.resource_parameters import EnumResourceParameter\n+TRACKS_VALUES = {\n+ \"circular\": _(\"Circular\"),\n+ \"twisted\": _(\"Twisted\")\n+}\nclass TrainStationsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Train Stations resource generator.\"\"\"\n-\n- additional_valid_options = {\n- \"tracks\": [\"circular\", \"twisted\"],\n+ additional_options = {\n+ \"tracks\": EnumResourceParameter(\n+ name=\"tracks\",\n+ description=_(\"Train track shape\"),\n+ values=TRACKS_VALUES,\n+ default=\"circular\"\n+ )\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/TreasureHuntResourceGenerator.py",
"new_path": "csunplugged/resources/generators/TreasureHuntResourceGenerator.py",
"diff": "from PIL import Image, ImageDraw, ImageFont\nfrom random import sample\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from django.utils.translation import ugettext as _\n+from collections import OrderedDict\n+from resources.utils.resource_parameters import EnumResourceParameter, BoolResourceParameter\nIMAGE_PATH = \"static/img/resources/treasure-hunt/{}.png\"\n+PREFILLED_VALUES_VALUES = {\n+ \"easy\": _(\"Easy Numbers (2 digits)\"),\n+ \"medium\": _(\"Medium Numbers (3 digits)\"),\n+ \"hard\": _(\"Hard Numbers (4 digits)\"),\n+ \"none\": _(\"None (Blank)\")\n+}\n+\n+NUMBER_ORDER_VALUES = {\n+ \"sorted\": _(\"Sorted Numbers\"),\n+ \"unsorted\": _(\"Unsorted Numbers\")\n+}\n+\n+ART_VALUES = {\n+ \"bw\": _(\"Table only - Little ink usage.\"),\n+ \"colour\": _(\"Table and artwork - Uses a lot of colour ink.\"),\n+}\n+\nclass TreasureHuntResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Treasure Hunt resource generator.\"\"\"\n-\n- additional_valid_options = {\n- \"prefilled_values\": [\"blank\", \"easy\", \"medium\", \"hard\"],\n- \"number_order\": [\"sorted\", \"unsorted\"],\n- \"instructions\": [True, False],\n- \"art\": [\"colour\", \"bw\"],\n+ additional_options = {\n+ \"prefilled_values\": EnumResourceParameter(\n+ name=\"prefilled_values\",\n+ description=_(\"Prefill with Numbers\"),\n+ values=PREFILLED_VALUES_VALUES,\n+ default=\"easy\"\n+ ),\n+ \"number_order\": EnumResourceParameter(\n+ name=\"number_order\",\n+ description=_(\"Numbers Unsorted/Sorted\"),\n+ values=NUMBER_ORDER_VALUES,\n+ default=\"sorted\"\n+ ),\n+ \"instructions\": BoolResourceParameter(\n+ name=\"instructions\",\n+ description=_(\"Include instruction sheets\"),\n+ default=True\n+ ),\n+ \"art\": EnumResourceParameter(\n+ name=\"art\",\n+ description=_(\"Printing mode\"),\n+ values=ART_VALUES,\n+ default=\"bw\"\n+ ),\n}\ndef __init__(self, requested_options=None):\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update generators to use ResourceParameter class to store param info
|
701,855 |
20.11.2017 19:03:23
| -46,800 |
8cf225cae6e3b57fa068ec56373905835f9bc64d
|
Add automatic selection of default value if not provided
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/resource_parameters.py",
"new_path": "csunplugged/resources/utils/resource_parameters.py",
"diff": "@@ -20,7 +20,7 @@ class EnumResourceParameter(ResourceParameter):\nself.values = values\nself.default = default\nif self.default not in self.values:\n- raise Exception(self.values)\n+ self.default = list(values.keys())[0] # Select first value\ndef html_element(self):\nbase_elem = super().html_element()\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add automatic selection of default value if not provided
|
701,855 |
20.11.2017 19:04:07
| -46,800 |
fbfd1a3551fe144641f874dc5f505297fae06215
|
Modify BaseResource class to use ResourceParameter class
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"new_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"diff": "@@ -12,9 +12,25 @@ from django.conf import settings\nfrom django.template.loader import render_to_string\nfrom django.contrib.staticfiles import finders\n+from resources.utils.resource_parameters import EnumResourceParameter\n+from lxml import etree\n+from django.utils.translation import ugettext as _\n+\n+PAPER_SIZE_VALUES = {\n+ \"a4\": _(\"A4\"),\n+ \"letter\": _(\"US Letter\")\n+}\nclass BaseResourceGenerator(ABC):\n\"\"\"Class for generator for a resource.\"\"\"\n+ default_options = {\n+ \"paper_size\": EnumResourceParameter(\n+ name=\"paper_size\",\n+ description=_(\"Paper Size\"),\n+ values=PAPER_SIZE_VALUES,\n+ default=\"a4\"\n+ ),\n+ }\ndefault_valid_options = {\n\"paper_size\": [\"a4\", \"letter\"]\n@@ -34,6 +50,16 @@ class BaseResourceGenerator(ABC):\nif requested_options:\nself.requested_options = self.process_requested_options(requested_options)\n+ def get_options_html(self):\n+ html = \"\"\n+ for parameter in self.additional_options.values():\n+ param_html = etree.tostring(parameter.html_element(), encoding='utf-8').decode('utf-8')\n+ html += param_html\n+ for parameter in self.default_options.values():\n+ param_html = etree.tostring(parameter.html_element(), encoding='utf-8').decode('utf-8')\n+ html += param_html\n+ return html\n+\n@abstractmethod\ndef data(self):\n\"\"\"Abstract method to be implemented by subclasses.\"\"\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Modify BaseResource class to use ResourceParameter class
|
701,855 |
20.11.2017 19:05:22
| -46,800 |
a7acd83e33ee95437f0c9c22f600f14bb30b9593
|
Update resource view to render generated options form
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/views.py",
"new_path": "csunplugged/resources/views.py",
"diff": "@@ -41,6 +41,7 @@ def resource(request, resource_slug):\n\"\"\"\nresource = get_object_or_404(Resource, slug=resource_slug)\ncontext = dict()\n+ context[\"options_html\"] = get_resource_generator(resource.generator_module).get_options_html()\ncontext[\"resource\"] = resource\ncontext[\"debug\"] = settings.DEBUG\ncontext[\"resource_thumbnail_base\"] = \"{}img/resources/{}/thumbnails/\".format(settings.STATIC_URL, resource.slug)\n@@ -48,7 +49,7 @@ def resource(request, resource_slug):\ncontext[\"copies_amount\"] = settings.RESOURCE_COPY_AMOUNT\nif resource.thumbnail_static_path:\ncontext[\"thumbnail\"] = resource.thumbnail_static_path\n- return render(request, resource.webpage_template, context)\n+ return render(request, \"resources/resource.html\", context)\ndef generate_resource(request, resource_slug):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/templates/resources/resource.html",
"new_path": "csunplugged/templates/resources/resource.html",
"diff": "{% block generation_form %}\n{% endblock generation_form %}\n- <fieldset>\n- <legend>{% trans \"Paper Size\" %}</legend>\n- <input type=\"radio\" name=\"paper_size\" id=\"size_a4\" value=\"a4\" checked=\"checked\">\n- <label for=\"size_a4\">{% trans \"A4\" %}</label>\n- <br>\n- <input type=\"radio\" name=\"paper_size\" id=\"size_letter\" value=\"letter\">\n- <label for=\"size_letter\">{% trans \"US Letter\" %}</label>\n- </fieldset>\n+ {{ options_html|safe }}\n{% if debug %}\n<hr>\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update resource view to render generated options form
|
701,855 |
21.11.2017 12:23:40
| -46,800 |
6f975b364301349bb19ea254b66f5d67008f4fdd
|
Add new exception for >1 value provided for a single valued parameter
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/utils/errors/QueryParameterMultipleValuesError.py",
"diff": "+\"\"\"Exception for missing query parameter.\"\"\"\n+\n+\n+class QueryParameterMultipleValuesError(Exception):\n+ \"\"\"Exception for missing parameter in a GET query.\"\"\"\n+\n+ def __init__(self, parameter, values):\n+ \"\"\"Initialise exception.\n+\n+ Args:\n+ parameter: The query parameter for the exception (str).\n+ \"\"\"\n+ super().__init__()\n+ self.parameter = parameter\n+ self.values = values\n+\n+ def __str__(self):\n+ \"\"\"Override default error string.\n+\n+ Returns:\n+ Error message for empty config file.\n+ \"\"\"\n+ text = \"Parameter '{}' must only have one value, but multiple were given ({}).\"\n+ return text.format(self.parameter, self.value)\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add new exception for >1 value provided for a single valued parameter
|
701,855 |
21.11.2017 12:25:23
| -46,800 |
c8d3f66527ec117dfc72b8048396db0d8eb8bfe5
|
Add classes for text/integer fields and single/multi value support
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/resource_parameters.py",
"new_path": "csunplugged/resources/utils/resource_parameters.py",
"diff": "from lxml import etree\nfrom django.utils.translation import ugettext as _\n+from utils.errors.QueryParameterMissingError import QueryParameterMissingError\n+from utils.errors.QueryParameterInvalidError import QueryParameterInvalidError\n+from utils.errors.QueryParameterMultipleValuesError import QueryParameterMultipleValuesError\n+\n+\nclass ResourceParameter(object):\n- def __init__(self, name=\"\", description=\"\"):\n+ def __init__(self, name=\"\", description=\"\", required=True):\nself.name = name\nself.description = description\n@@ -13,18 +18,49 @@ class ResourceParameter(object):\nfieldset.append(legend)\nreturn fieldset\n+ def process_value(self, value):\n+ return value\n+\n+\n+class SingleValuedParameter(ResourceParameter):\n+ def __init__(self, default=None, required=True, **kwargs):\n+ super().__init__(**kwargs)\n+ self.value = None\n+ self.single_valued = True\n+ self.default = default\n+ self.required = required\n+\n+ def process_requested_values(self, requested_values):\n+ if len(requested_values) == 0:\n+ if self.required:\n+ raise QueryParameterMissingError(self.name)\n+ if len(requested_values) > 1:\n+ raise QueryParameterMultipleValuesError(self.name, requested_values)\n+ self.value = self.process_value(requested_values[0])\n+\n+\n+class MultiValuedParameter(ResourceParameter):\n+ def __init__(self, **kwargs):\n+ self.values = []\n+ self.single_valued = False\n+\n+ def process_requested_values(self, requested_values):\n+ for value in requested_values:\n+ self.values.append(self.process_value(value))\n-class EnumResourceParameter(ResourceParameter):\n+\n+class EnumResourceParameter(SingleValuedParameter):\ndef __init__(self, values=[], default=None, **kwargs):\nsuper().__init__(**kwargs)\n- self.values = values\n+ self.valid_values = values\nself.default = default\n- if self.default not in self.values:\n- self.default = list(values.keys())[0] # Select first value\n+ if self.default not in self.valid_values:\n+ self.default = list(self.valid_values.keys())[0] # Select first value\n+ self.value = None\ndef html_element(self):\nbase_elem = super().html_element()\n- for value, value_desc in self.values.items():\n+ for value, value_desc in self.valid_values.items():\ninput_elem = etree.Element(\n'input',\ntype=\"radio\",\n@@ -44,10 +80,77 @@ class EnumResourceParameter(ResourceParameter):\nbase_elem.append(etree.Element('br'))\nreturn base_elem\n+ def process_value(self, value):\n+ if value not in self.valid_values:\n+ raise QueryParameterInvalidError(self.name, value)\n+ return value\n+\nclass BoolResourceParameter(EnumResourceParameter):\n+ TRUE_VALUE=\"true\"\n+ FALSE_VALUE=\"false\"\n+\ndef __init__(self, default=True, true_text=_(\"Yes\"), false_text=_(\"No\"), **kwargs):\nvalues = {\n- True: true_text,\n- False: false_text\n+ self.TRUE_VALUE: true_text,\n+ self.FALSE_VALUE: false_text\n}\nsuper().__init__(values=values, default=default, **kwargs)\n+\n+ def process_value(self, value):\n+ if value == self.TRUE_VALUE:\n+ return True\n+ elif value == self.FALSE_VALUE:\n+ return False\n+ else:\n+ raise QueryParameterInvalidError(self.name, value)\n+\n+\n+class TextResourceParameter(SingleValuedParameter):\n+ def __init__(self, placeholder=\"\", **kwargs):\n+ super().__init__(**kwargs)\n+ self.placeholder = placeholder\n+\n+ def html_element(self):\n+ base_elem = super().html_element()\n+ input_elem = etree.Element(\n+ \"input\",\n+ type=\"text\",\n+ name=self.name,\n+ placeholder=self.placeholder,\n+ )\n+ input_elem.set(\"class\", \"long-text-field\")\n+ base_elem.append(input_elem)\n+ return base_elem\n+\n+\n+class IntegerResourceParameter(SingleValuedParameter):\n+ def __init__(self, default=None, min_val=None, max_val=None, **kwargs):\n+ super().__init__(**kwargs)\n+ self.min_val = min_val\n+ self.max_val = max_val\n+ self.default = default\n+\n+ def html_element(self):\n+ base_elem = super().html_element()\n+ input_elem = etree.Element(\n+ \"input\",\n+ type=\"number\",\n+ name=self.name,\n+ )\n+ if self.min_val:\n+ input_elem.set(\"min\", str(self.min_val))\n+ if self.max_val:\n+ input_elem.set(\"max\", str(self.max_val))\n+ if self.default:\n+ input_elem.set(\"value\", str(self.default))\n+ base_elem.append(input_elem)\n+ return base_elem\n+\n+ def process_value(self, value):\n+ try:\n+ int_val = int(value)\n+ except:\n+ raise QueryParameterInvalidError(self.name, value)\n+ if (self.min_val and int_val < self.min_val) or (self.max_val and int_val > self.max_val):\n+ raise QueryParameterInvalidError(self.name, value)\n+ return int_val\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add classes for text/integer fields and single/multi value support
|
701,855 |
21.11.2017 12:26:28
| -46,800 |
01027bed39736470fe4a4d4bbf7e836faff1e144
|
Move parameters definitions to get_options functions, add local options
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"new_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"diff": "@@ -12,9 +12,15 @@ from django.conf import settings\nfrom django.template.loader import render_to_string\nfrom django.contrib.staticfiles import finders\n-from resources.utils.resource_parameters import EnumResourceParameter\n+from resources.utils.resource_parameters import (\n+ EnumResourceParameter,\n+ TextResourceParameter,\n+ IntegerResourceParameter,\n+)\n+\nfrom lxml import etree\nfrom django.utils.translation import ugettext as _\n+from django.urls import reverse\nPAPER_SIZE_VALUES = {\n\"a4\": _(\"A4\"),\n@@ -23,19 +29,7 @@ PAPER_SIZE_VALUES = {\nclass BaseResourceGenerator(ABC):\n\"\"\"Class for generator for a resource.\"\"\"\n- default_options = {\n- \"paper_size\": EnumResourceParameter(\n- name=\"paper_size\",\n- description=_(\"Paper Size\"),\n- values=PAPER_SIZE_VALUES,\n- default=\"a4\"\n- ),\n- }\n-\n- default_valid_options = {\n- \"paper_size\": [\"a4\", \"letter\"]\n- }\n- additional_valid_options = dict()\n+ copies = False # Default\ndef __init__(self, requested_options=None):\n\"\"\"Construct BaseResourceGenerator instance.\n@@ -43,22 +37,62 @@ class BaseResourceGenerator(ABC):\nArgs:\nrequested_options: QueryDict of requested_options (QueryDict).\n\"\"\"\n- # Use deepcopy to avoid successive generators from sharing the same\n- # valid_options dictionary.\n- self.valid_options = deepcopy(BaseResourceGenerator.default_valid_options)\n- self.valid_options.update(self.additional_valid_options)\n+ self.options = self.get_options()\n+ self.options.update(self.get_local_options())\nif requested_options:\n- self.requested_options = self.process_requested_options(requested_options)\n-\n- def get_options_html(self):\n- html = \"\"\n- for parameter in self.additional_options.values():\n- param_html = etree.tostring(parameter.html_element(), encoding='utf-8').decode('utf-8')\n- html += param_html\n- for parameter in self.default_options.values():\n- param_html = etree.tostring(parameter.html_element(), encoding='utf-8').decode('utf-8')\n- html += param_html\n- return html\n+ self.process_requested_options(requested_options)\n+\n+ def get_options(self):\n+ options = self.get_additional_options()\n+ options.update({\n+ \"paper_size\": EnumResourceParameter(\n+ name=\"paper_size\",\n+ description=_(\"Paper Size\"),\n+ values=PAPER_SIZE_VALUES,\n+ default=\"a4\"\n+ ),\n+ })\n+ return options\n+\n+ def get_local_options(self):\n+ local_options = {\n+ \"header_text\": TextResourceParameter(\n+ name=\"header_text\",\n+ description=_(\"Header Text\"),\n+ placeholder=_(\"Example School: Room Four\")\n+ ),\n+ }\n+ if self.copies:\n+ local_options.update({\n+ \"copies\": IntegerResourceParameter(\n+ name=\"copies\",\n+ description=_(\"Number of Copies\"),\n+ min_val=1,\n+ max_val=50,\n+ default=1\n+ ),\n+ })\n+ return local_options\n+\n+ def get_additional_options(self):\n+ return {}\n+\n+ def get_options_html(self, slug):\n+ html_elements = []\n+ for parameter in self.get_options().values():\n+ html_elements.append(parameter.html_element())\n+ if settings.DEBUG:\n+ html_elements.append(etree.Element(\"hr\"))\n+ h3 = etree.Element(\"h3\")\n+ h3.text = _(\"Local Generation Only\")\n+ html_elements.append(h3)\n+ for parameter in self.get_local_options().values():\n+ html_elements.append(parameter.html_element())\n+\n+ html_string = \"\"\n+ for html_elem in html_elements:\n+ html_string += etree.tostring(html_elem, encoding='utf-8').decode('utf-8')\n+ return html_string\n@abstractmethod\ndef data(self):\n@@ -75,7 +109,7 @@ class BaseResourceGenerator(ABC):\nReturns:\nText for subtitle (str).\n\"\"\"\n- return self.requested_options[\"paper_size\"]\n+ return self.options[\"paper_size\"].value\ndef process_requested_options(self, requested_options):\n\"\"\"Convert requested options to usable types.\n@@ -91,18 +125,10 @@ class BaseResourceGenerator(ABC):\nReturns:\nQueryDict of converted requested options (QueryDict).\n\"\"\"\n- requested_options = requested_options.copy()\n- for option in self.valid_options.keys():\n- values = requested_options.getlist(option)\n- if not values:\n- raise QueryParameterMissingError(option)\n- for (i, value) in enumerate(values):\n- update_value = str_to_bool(value)\n- if update_value not in self.valid_options[option]:\n- raise QueryParameterInvalidError(option, value)\n- values[i] = update_value\n- requested_options.setlist(option, values)\n- return requested_options\n+ # requested_options = requested_options.copy()\n+ for option_name, option in self.options.items():\n+ values = requested_options.getlist(option_name)\n+ option.process_requested_values(values)\ndef pdf(self, resource_name):\n\"\"\"Return PDF for resource request.\n@@ -122,17 +148,17 @@ class BaseResourceGenerator(ABC):\nfrom weasyprint import HTML, CSS\ncontext = dict()\ncontext[\"resource\"] = resource_name\n- context[\"header_text\"] = self.requested_options.get(\"header_text\", \"\")\n- context[\"paper_size\"] = self.requested_options[\"paper_size\"]\n+ context[\"header_text\"] = self.options[\"header_text\"].value\n+ context[\"paper_size\"] = self.options[\"paper_size\"].value\n- num_copies = range(0, int(self.requested_options.get(\"copies\", 1)))\n+ num_copies = range(0, int(self.options[\"copies\"].value))\ncontext[\"all_data\"] = []\nfor copy in num_copies:\ncopy_data = self.data()\nif not isinstance(copy_data, list):\ncopy_data = [copy_data]\ncopy_data = resize_encode_resource_images(\n- self.requested_options[\"paper_size\"],\n+ self.options[\"paper_size\"].value,\ncopy_data\n)\ncontext[\"all_data\"].append(copy_data)\n@@ -182,7 +208,7 @@ class BaseResourceGenerator(ABC):\nraise MoreThanOneThumbnailPageFoundError(self)\nthumbnail_data = resize_encode_resource_images(\n- self.requested_options[\"paper_size\"],\n+ self.options[\"paper_size\"].value,\nthumbnail_data\n)\nreturn thumbnail_data[0]\n@@ -200,7 +226,7 @@ class BaseResourceGenerator(ABC):\nfrom weasyprint import HTML, CSS\ncontext = dict()\ncontext[\"resource\"] = resource_name\n- context[\"paper_size\"] = self.requested_options[\"paper_size\"]\n+ context[\"paper_size\"] = self.options[\"paper_size\"].value\ncontext[\"all_data\"] = [[thumbnail_data]]\npdf_html = render_to_string(\"resources/base-resource-pdf.html\", context)\nhtml = HTML(string=pdf_html, base_url=settings.BUILD_ROOT)\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Move parameters definitions to get_options functions, add local options
|
701,855 |
21.11.2017 12:28:23
| -46,800 |
2ab4c6b1efc757b50394b71ea2257394ae8bfed3
|
Remove unrequired "slug" parameter
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"new_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"diff": "@@ -77,7 +77,7 @@ class BaseResourceGenerator(ABC):\ndef get_additional_options(self):\nreturn {}\n- def get_options_html(self, slug):\n+ def get_options_html(self):\nhtml_elements = []\nfor parameter in self.get_options().values():\nhtml_elements.append(parameter.html_element())\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Remove unrequired "slug" parameter
|
701,855 |
21.11.2017 12:28:52
| -46,800 |
4ec19556518df9de8ab37af67605d0feb0dd1c15
|
Update all generator classes
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BarcodeChecksumPosterResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BarcodeChecksumPosterResourceGenerator.py",
"diff": "@@ -14,7 +14,8 @@ BARCODE_LENGTH_VALUES = {\nclass BarcodeChecksumPosterResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Grid resource generator.\"\"\"\n- additional_options = {\n+ def get_additional_options(self):\n+ return {\n\"barcode_length\": EnumResourceParameter(\nname=\"barcode_length\",\ndescription=_(\"Barcode length\"),\n@@ -30,7 +31,7 @@ class BarcodeChecksumPosterResourceGenerator(BaseResourceGenerator):\nA dictionary of the one page for the resource.\n\"\"\"\npath = \"static/img/resources/barcode-checksum-poster/{}-digits\"\n- barcode_length = self.requested_options[\"barcode_length\"]\n+ barcode_length = self.options[\"barcode_length\"].value\npath = path.format(barcode_length)\nimage_path = \"{}.png\".format(path)\nsvg_path = \"{}.svg\".format(path)\n@@ -75,5 +76,5 @@ class BarcodeChecksumPosterResourceGenerator(BaseResourceGenerator):\nReturns:\ntext for subtitle (str).\n\"\"\"\n- barcode_length = self.requested_options[\"barcode_length\"]\n+ barcode_length = self.options[\"barcode_length\"].value\nreturn \"{} digits - {}\".format(barcode_length, super().subtitle)\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryCardsResourceGenerator.py",
"diff": "@@ -24,7 +24,8 @@ IMAGE_DATA = [\nclass BinaryCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary Cards resource generator.\"\"\"\n- additional_options = {\n+ def get_additional_options(self):\n+ return {\n\"display_numbers\": BoolResourceParameter(\nname=\"display_numbers\",\ndescription=_(\"Display Numbers\"),\n@@ -46,8 +47,8 @@ class BinaryCardsResourceGenerator(BaseResourceGenerator):\nA dictionary or list of dictionaries for each resource page.\n\"\"\"\n# Retrieve parameters\n- display_numbers = self.requested_options[\"display_numbers\"]\n- black_back = self.requested_options[\"black_back\"]\n+ display_numbers = self.options[\"display_numbers\"].value\n+ black_back = self.options[\"black_back\"].value\nimage_size_y = IMAGE_SIZE_Y\nif display_numbers:\n@@ -97,12 +98,12 @@ class BinaryCardsResourceGenerator(BaseResourceGenerator):\nReturns:\ntext for subtitle (str)\n\"\"\"\n- if self.requested_options[\"display_numbers\"]:\n+ if self.options[\"display_numbers\"].value:\ndisplay_numbers_text = \"with numbers\"\nelse:\ndisplay_numbers_text = \"without numbers\"\n- if self.requested_options[\"black_back\"]:\n+ if self.options[\"black_back\"].value:\nblack_back_text = \"with black back\"\nelse:\nblack_back_text = \"without black back\"\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryCardsSmallResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryCardsSmallResourceGenerator.py",
"diff": "@@ -26,7 +26,8 @@ NUMBER_BITS_VALUES = {\nclass BinaryCardsSmallResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary Cards (small) resource generator.\"\"\"\n- additional_options = {\n+ def get_additional_options(self):\n+ return {\n\"number_bits\": EnumResourceParameter(\nname=\"number_bits\",\ndescription=_(\"Number of Bits\"),\n@@ -46,11 +47,6 @@ class BinaryCardsSmallResourceGenerator(BaseResourceGenerator):\nfalse_text=_(\"No - Print single sided.\")\n)\n}\n- additional_valid_options = {\n- \"number_bits\": [\"4\", \"8\", \"12\"],\n- \"dot_counts\": [True, False],\n- \"black_back\": [True, False],\n- }\ndef data(self):\n\"\"\"Create a image for Binary Cards (small) resource.\n@@ -58,7 +54,7 @@ class BinaryCardsSmallResourceGenerator(BaseResourceGenerator):\nReturns:\nA dictionary or list of dictionaries for each resource page.\n\"\"\"\n- if self.requested_options[\"dot_counts\"]:\n+ if self.options[\"dot_counts\"].value:\nfont_path = \"static/fonts/PatrickHand-Regular.ttf\"\nfont = ImageFont.truetype(font_path, 200)\nTEXT_COORDS = [\n@@ -71,9 +67,9 @@ class BinaryCardsSmallResourceGenerator(BaseResourceGenerator):\npages = []\nfor (image_path, image_bits) in IMAGE_DATA:\n- if image_bits <= int(self.requested_options[\"number_bits\"]):\n+ if image_bits <= int(self.options[\"number_bits\"].value):\nimage = Image.open(os.path.join(BASE_IMAGE_PATH, image_path))\n- if self.requested_options[\"dot_counts\"]:\n+ if self.options[\"dot_counts\"].value:\ndraw = ImageDraw.Draw(image)\nfor number in range(image_bits - 4, image_bits):\ntext = str(pow(2, number))\n@@ -88,7 +84,7 @@ class BinaryCardsSmallResourceGenerator(BaseResourceGenerator):\n)\npages.append({\"type\": \"image\", \"data\": image})\n- if self.requested_options[\"black_back\"]:\n+ if self.options[\"black_back\"].value:\nblack_card = Image.new(\"1\", (IMAGE_SIZE_X, IMAGE_SIZE_Y))\npages.append({\"type\": \"image\", \"data\": black_card})\npages[0][\"thumbnail\"] = True\n@@ -104,16 +100,16 @@ class BinaryCardsSmallResourceGenerator(BaseResourceGenerator):\nReturns:\ntext for subtitle (str)\n\"\"\"\n- if self.requested_options[\"dot_counts\"]:\n+ if self.options[\"dot_counts\"].value:\ndisplay_numbers_text = \"with dot counts\"\nelse:\ndisplay_numbers_text = \"without dot counts\"\n- if self.requested_options[\"black_back\"]:\n+ if self.options[\"black_back\"].value:\nblack_back_text = \"with black back\"\nelse:\nblack_back_text = \"without black back\"\ntext = \"{} bits - {} - {} - {}\".format(\n- self.requested_options[\"number_bits\"],\n+ self.options[\"number_bits\"].value,\ndisplay_numbers_text,\nblack_back_text,\nsuper().subtitle\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryToAlphabetResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryToAlphabetResourceGenerator.py",
"diff": "@@ -14,7 +14,8 @@ WORKSHEET_VERSION_VALUES = {\nclass BinaryToAlphabetResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary to Alphabet resource generator.\"\"\"\n- additional_options = {\n+ def get_additional_options(self):\n+ return {\n\"worksheet_version\": EnumResourceParameter(\nname=\"worksheet_version\",\ndescription=_(\"Worksheet Version\"),\n@@ -23,10 +24,6 @@ class BinaryToAlphabetResourceGenerator(BaseResourceGenerator):\n)\n}\n- additional_valid_options = {\n- \"worksheet_version\": [\"student\", \"teacher\"],\n- }\n-\ndef data(self):\n\"\"\"Create a image for Binary to Alphabet resource.\n@@ -34,7 +31,7 @@ class BinaryToAlphabetResourceGenerator(BaseResourceGenerator):\nA dictionary for the resource page.\n\"\"\"\n# Retrieve relevant image\n- worksheet_version = self.requested_options[\"worksheet_version\"]\n+ worksheet_version = self.options[\"worksheet_version\"].value\nif worksheet_version == \"student\":\nimage_path = \"static/img/resources/binary-to-alphabet/table.png\"\nelse:\n@@ -110,7 +107,7 @@ class BinaryToAlphabetResourceGenerator(BaseResourceGenerator):\nText for subtitle (str).\n\"\"\"\ntext = \"{} - {}\".format(\n- self.requested_options[\"worksheet_version\"],\n+ self.options[\"worksheet_version\"].value,\nsuper().subtitle\n)\nreturn text\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryWindowsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryWindowsResourceGenerator.py",
"diff": "@@ -23,7 +23,9 @@ VALUE_TYPE_VALUES = {\nclass BinaryWindowsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary Windows resource generator.\"\"\"\n- additional_options = {\n+\n+ def get_additional_options(self):\n+ return {\n\"number_bits\": EnumResourceParameter(\nname=\"number_bits\",\ndescription=_(\"Number of Bits\"),\n@@ -51,9 +53,9 @@ class BinaryWindowsResourceGenerator(BaseResourceGenerator):\nA dictionary or list of dictionaries for each resource page.\n\"\"\"\n# Retrieve parameters\n- number_of_bits = self.requested_options[\"number_bits\"]\n- value_type = self.requested_options[\"value_type\"]\n- dot_counts = self.requested_options[\"dot_counts\"]\n+ number_of_bits = self.options[\"number_bits\"].value\n+ value_type = self.options[\"value_type\"].value\n+ dot_counts = self.options[\"dot_counts\"].value\npages = []\npage_sets = [(\"binary-windows-1-to-8.png\", 8)]\n@@ -183,15 +185,15 @@ class BinaryWindowsResourceGenerator(BaseResourceGenerator):\nReturns:\ntext for subtitle (str).\n\"\"\"\n- dot_counts = self.requested_options[\"dot_counts\"]\n+ dot_counts = self.options[\"dot_counts\"].value\nif dot_counts:\ncount_text = \"with dot counts\"\nelse:\ncount_text = \"without dot counts\"\nTEMPLATE = \"{} bits - {} - {} - {}\"\ntext = TEMPLATE.format(\n- self.requested_options[\"number_bits\"],\n- self.requested_options[\"value_type\"],\n+ self.options[\"number_bits\"].value,\n+ self.options[\"value_type\"].value,\ncount_text,\nsuper().subtitle\n)\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/ModuloClockResourceGenerator.py",
"new_path": "csunplugged/resources/generators/ModuloClockResourceGenerator.py",
"diff": "@@ -14,7 +14,9 @@ MODULO_NUMBER_VALUES = {\nclass ModuloClockResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Modulo Clock resource generator.\"\"\"\n- additional_options = {\n+\n+ def get_additional_options(self):\n+ return {\n\"modulo_number\": EnumResourceParameter(\nname=\"modulo_number\",\ndescription=_(\"Modulo\"),\n@@ -30,7 +32,7 @@ class ModuloClockResourceGenerator(BaseResourceGenerator):\n\"\"\"\nimage_path = \"static/img/resources/modulo-clock/modulo-clock-{}.png\"\n- modulo_number = int(self.requested_options[\"modulo_number\"])\n+ modulo_number = int(self.options[\"modulo_number\"].value)\nimage = Image.open(image_path.format(modulo_number))\ndraw = ImageDraw.Draw(image)\n@@ -72,7 +74,7 @@ class ModuloClockResourceGenerator(BaseResourceGenerator):\nReturns:\nText for subtitle (str).\n\"\"\"\n- modulo_number = self.requested_options[\"modulo_number\"]\n+ modulo_number = self.options[\"modulo_number\"].value\nif modulo_number == \"1\":\nmodulo_text = \"blank\"\nelse:\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/ParityCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/ParityCardsResourceGenerator.py",
"diff": "@@ -23,7 +23,9 @@ BACK_COLOUR_VALUES={\nclass ParityCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Parity Cards resource generator.\"\"\"\n- additional_options = {\n+\n+ def get_additional_options(self):\n+ return {\n\"back_colour\": EnumResourceParameter(\nname=\"barcode_length\",\ndescription=_(\"Card back colour\"),\n@@ -63,7 +65,7 @@ class ParityCardsResourceGenerator(BaseResourceGenerator):\nwidth=LINE_WIDTH\n)\n- back_colour = self.requested_options[\"back_colour\"]\n+ back_colour = self.options[\"back_colour\"].value\nif back_colour == \"black\":\nback_colour_hex = \"#000000\"\n@@ -99,7 +101,7 @@ class ParityCardsResourceGenerator(BaseResourceGenerator):\ntext for subtitle (str).\n\"\"\"\ntext = \"{} back - {}\".format(\n- self.requested_options[\"back_colour\"],\n+ self.options[\"back_colour\"].value,\nsuper().subtitle\n)\nreturn text\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/PianoKeysResourceGenerator.py",
"new_path": "csunplugged/resources/generators/PianoKeysResourceGenerator.py",
"diff": "@@ -71,7 +71,9 @@ HIGHLIGHT_VALUES = {\nclass PianoKeysResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Piano Keys resource generator.\"\"\"\n- additional_options = {\n+\n+ def get_additional_options(self):\n+ return {\n\"highlight\": EnumResourceParameter(\nname=\"highlight\",\ndescription=_(\"Piano keys to highlight\"),\n@@ -86,7 +88,7 @@ class PianoKeysResourceGenerator(BaseResourceGenerator):\nReturns:\nA list of dictionaries for each resource page.\n\"\"\"\n- highlight = self.requested_options[\"highlight\"]\n+ highlight = self.options[\"highlight\"].value\nimage_path = \"static/img/resources/piano-keys/keyboard.png\"\nimage = Image.open(image_path)\npage = Image.new(\"RGB\", image.size, \"#FFF\")\n@@ -122,6 +124,6 @@ class PianoKeysResourceGenerator(BaseResourceGenerator):\ntext for subtitle (str).\n\"\"\"\nreturn \"{} highlight - {}\".format(\n- bool_to_yes_no(self.requested_options[\"highlight\"]),\n+ bool_to_yes_no(self.options[\"highlight\"].value),\nsuper().subtitle\n)\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/PixelPainterResourceGenerator.py",
"new_path": "csunplugged/resources/generators/PixelPainterResourceGenerator.py",
"diff": "@@ -25,20 +25,6 @@ IMAGE_VALUES = {\nclass PixelPainterResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Pixel Painter resource generator.\"\"\"\n- additional_options = {\n- \"method\": EnumResourceParameter(\n- name=\"method\",\n- description=_(\"Colouring type\"),\n- values=METHOD_VALUES,\n- default=\"black-white\"\n- ),\n- \"image\": EnumResourceParameter(\n- name=\"image\",\n- description=_(\"Image\"),\n- values=IMAGE_VALUES,\n- default=\"fish\"\n- ),\n- }\nmethods = {\n\"black-white\": {\n@@ -99,14 +85,30 @@ class PixelPainterResourceGenerator(BaseResourceGenerator):\nLINE_COLOUR = \"#666\"\nLINE_WIDTH = 1\n+ def get_additional_options(self):\n+ return {\n+ \"method\": EnumResourceParameter(\n+ name=\"method\",\n+ description=_(\"Colouring type\"),\n+ values=METHOD_VALUES,\n+ default=\"black-white\"\n+ ),\n+ \"image\": EnumResourceParameter(\n+ name=\"image\",\n+ description=_(\"Image\"),\n+ values=IMAGE_VALUES,\n+ default=\"fish\"\n+ ),\n+ }\n+\ndef data(self):\n\"\"\"Create data for a copy of the Pixel Painter resource.\nReturns:\nA dictionary of the one page for the resource.\n\"\"\"\n- method = self.requested_options[\"method\"]\n- image_name = self.requested_options[\"image\"]\n+ method = self.options[\"method\"].value\n+ image_name = self.options[\"image\"].value\nif method == \"run-length-encoding\":\nimage_filename = \"{}-black-white.png\".format(image_name)\n@@ -411,7 +413,7 @@ class PixelPainterResourceGenerator(BaseResourceGenerator):\ntext(\"Pixel legend\")\nwith tag(\"table\", id=\"pixel-legend\", style=\"padding-top:1rem;\"):\nwith tag(\"tbody\"):\n- for (values, label) in self.methods[self.requested_options[\"method\"]][\"labels\"].items():\n+ for (values, label) in self.methods[self.options[\"method\"].value][\"labels\"].items():\nwith tag(\"tr\"):\nif isinstance(values, tuple):\nline(\"td\", \" \", style=\"background-color:rgb{};width:3em;\".format(values))\n@@ -455,8 +457,8 @@ class PixelPainterResourceGenerator(BaseResourceGenerator):\ntext for subtitle (str).\n\"\"\"\ntext = \"{} - {} - {}\".format(\n- self.image_strings[self.requested_options[\"image\"]],\n- self.methods[self.requested_options[\"method\"]][\"name\"],\n+ self.image_strings[self.options[\"image\"].value],\n+ self.methods[self.options[\"method\"].value][\"name\"],\nsuper().subtitle\n)\nreturn text\n@@ -470,8 +472,8 @@ class PixelPainterResourceGenerator(BaseResourceGenerator):\nThe images are not resized as the images used are small already.\n\"\"\"\n- method = self.requested_options[\"method\"]\n- image_name = self.requested_options[\"image\"]\n+ method = self.options[\"method\"].value\n+ image_name = self.options[\"image\"].value\nif method == \"run-length-encoding\":\nimage_filename = \"{}-black-white.png\".format(image_name)\nelse:\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/SearchingCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/SearchingCardsResourceGenerator.py",
"diff": "@@ -28,7 +28,9 @@ MAX_NUMBER_VALUE = {\nclass SearchingCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Searching Cards resource generator.\"\"\"\n- additional_options = {\n+\n+ def get_additional_options(self):\n+ return {\n\"number_cards\": EnumResourceParameter(\nname=\"number_cards\",\ndescription=_(\"Number of cards\"),\n@@ -55,9 +57,9 @@ class SearchingCardsResourceGenerator(BaseResourceGenerator):\nA list of dictionaries for each resource page.\n\"\"\"\npages = []\n- number_cards = int(self.requested_options[\"number_cards\"])\n- max_number = self.requested_options[\"max_number\"]\n- help_sheet = self.requested_options[\"help_sheet\"]\n+ number_cards = int(self.options[\"number_cards\"].value)\n+ max_number = self.options[\"max_number\"].value\n+ help_sheet = self.options[\"help_sheet\"].value\nif max_number == \"cards\":\nnumbers = list(range(1, number_cards + 1))\n@@ -156,9 +158,9 @@ class SearchingCardsResourceGenerator(BaseResourceGenerator):\nReturns:\ntext for subtitle (str).\n\"\"\"\n- max_number = self.requested_options[\"max_number\"]\n- help_sheet = self.requested_options[\"help_sheet\"]\n- number_cards = self.requested_options[\"number_cards\"]\n+ max_number = self.options[\"max_number\"].value\n+ help_sheet = self.options[\"help_sheet\"].value\n+ number_cards = self.options[\"number_cards\"].value\nif max_number == \"blank\":\nrange_text = \"blank\"\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/SortingNetworkCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/SortingNetworkCardsResourceGenerator.py",
"diff": "@@ -26,7 +26,9 @@ TYPE_VALUES = {\nclass SortingNetworkCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Sorting Network Cards resource generator.\"\"\"\n- additional_options = {\n+\n+ def get_additional_options(self):\n+ return {\n\"type\": EnumResourceParameter(\nname=\"type\",\ndescription=_(\"Card Type\"),\n@@ -42,7 +44,7 @@ class SortingNetworkCardsResourceGenerator(BaseResourceGenerator):\nA list of dictionaries for each resource page.\n\"\"\"\nfont_path = \"static/fonts/PatrickHand-Regular.ttf\"\n- card_type = self.requested_options[\"type\"]\n+ card_type = self.options[\"type\"].value\n# Create card outlines\ncard_outlines = Image.new(\"RGB\", (IMAGE_SIZE_X, IMAGE_SIZE_Y), \"#fff\")\n@@ -177,6 +179,6 @@ class SortingNetworkCardsResourceGenerator(BaseResourceGenerator):\ntext for subtitle (str).\n\"\"\"\nreturn \"{} - {}\".format(\n- self.requested_options[\"type\"].replace(\"_\", \" \"),\n+ self.options[\"type\"].value.replace(\"_\", \" \"),\nsuper().subtitle\n)\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/SortingNetworkResourceGenerator.py",
"new_path": "csunplugged/resources/generators/SortingNetworkResourceGenerator.py",
"diff": "@@ -15,7 +15,10 @@ PREFILLED_VALUES_VALUES = {\nclass SortingNetworkResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Sorting Network resource generator.\"\"\"\n- additional_options = {\n+ copies = True\n+\n+ def get_additional_options(self):\n+ return {\n\"prefilled_values\": EnumResourceParameter(\nname=\"prefilled_values\",\ndescription=_(\"Prefill with Numbers\"),\n@@ -36,7 +39,7 @@ class SortingNetworkResourceGenerator(BaseResourceGenerator):\ndraw = ImageDraw.Draw(image)\n(range_min, range_max, font_size) = self.number_range()\n- if self.requested_options[\"prefilled_values\"] != \"blank\":\n+ if self.options[\"prefilled_values\"].value != \"blank\":\nfont = ImageFont.truetype(font_path, font_size)\nnumbers = sample(range(range_min, range_max), 6)\nbase_coord_x = 70\n@@ -66,7 +69,7 @@ class SortingNetworkResourceGenerator(BaseResourceGenerator):\nReturns:\ntext for subtitle (str).\n\"\"\"\n- if self.requested_options[\"prefilled_values\"] == \"blank\":\n+ if self.options[\"prefilled_values\"].value == \"blank\":\nrange_text = \"blank\"\nelse:\nSUBTITLE_TEMPLATE = \"{} to {}\"\n@@ -80,7 +83,7 @@ class SortingNetworkResourceGenerator(BaseResourceGenerator):\nReturns:\nTuple of (range_min, range_max, font_size).\n\"\"\"\n- prefilled_values = self.requested_options[\"prefilled_values\"]\n+ prefilled_values = self.options[\"prefilled_values\"].value\nrange_min = 0\nrange_max = 0\nfont_size = 150\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/TrainStationsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/TrainStationsResourceGenerator.py",
"diff": "@@ -12,7 +12,9 @@ TRACKS_VALUES = {\nclass TrainStationsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Train Stations resource generator.\"\"\"\n- additional_options = {\n+\n+ def get_additional_options(self):\n+ return {\n\"tracks\": EnumResourceParameter(\nname=\"tracks\",\ndescription=_(\"Train track shape\"),\n@@ -28,7 +30,7 @@ class TrainStationsResourceGenerator(BaseResourceGenerator):\nA list of dictionaries for each resource page.\n\"\"\"\nimage_path = \"static/img/resources/train-stations/train-stations-tracks-{}.png\"\n- image = Image.open(image_path.format(self.requested_options[\"tracks\"]))\n+ image = Image.open(image_path.format(self.options[\"tracks\"].value))\nimage = image.rotate(90, expand=True)\nreturn {\"type\": \"image\", \"data\": image}\n@@ -43,6 +45,6 @@ class TrainStationsResourceGenerator(BaseResourceGenerator):\ntext for subtitle (str).\n\"\"\"\nreturn \"{} tracks - {}\".format(\n- self.requested_options[\"tracks\"],\n+ self.options[\"tracks\"].value,\nsuper().subtitle\n)\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/TreasureHuntResourceGenerator.py",
"new_path": "csunplugged/resources/generators/TreasureHuntResourceGenerator.py",
"diff": "@@ -29,7 +29,10 @@ ART_VALUES = {\nclass TreasureHuntResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Treasure Hunt resource generator.\"\"\"\n- additional_options = {\n+ copies = True\n+\n+ def get_additional_options(self):\n+ return {\n\"prefilled_values\": EnumResourceParameter(\nname=\"prefilled_values\",\ndescription=_(\"Prefill with Numbers\"),\n@@ -74,10 +77,10 @@ class TreasureHuntResourceGenerator(BaseResourceGenerator):\npages = []\nfont_path = \"static/fonts/PatrickHand-Regular.ttf\"\n- prefilled_values = self.requested_options[\"prefilled_values\"]\n- number_order = self.requested_options[\"number_order\"]\n- instructions = self.requested_options[\"instructions\"]\n- art_style = self.requested_options[\"art\"]\n+ prefilled_values = self.options[\"prefilled_values\"].value\n+ number_order = self.options[\"number_order\"].value\n+ instructions = self.options[\"instructions\"].value\n+ art_style = self.options[\"art\"].value\nif instructions:\nimage = Image.open(IMAGE_PATH.format(\"instructions\"))\n@@ -139,10 +142,10 @@ class TreasureHuntResourceGenerator(BaseResourceGenerator):\nReturns:\ntext for subtitle (str)\n\"\"\"\n- prefilled_values = self.requested_options[\"prefilled_values\"]\n- number_order = self.requested_options[\"number_order\"]\n- instructions = self.requested_options[\"instructions\"]\n- art_style = self.requested_options[\"art\"]\n+ prefilled_values = self.options[\"prefilled_values\"].value\n+ number_order = self.options[\"number_order\"].value\n+ instructions = self.options[\"instructions\"].value\n+ art_style = self.options[\"art\"].value\nif prefilled_values == \"blank\":\nrange_text = \"blank\"\n@@ -169,7 +172,7 @@ class TreasureHuntResourceGenerator(BaseResourceGenerator):\nReturns:\nTuple of (range_min, range_max, font_size)\n\"\"\"\n- prefilled_values = self.requested_options.get(\"prefilled_values\", None)\n+ prefilled_values = self.options[\"prefilled_values\"].value\nself.range_min = 0\nif prefilled_values == \"easy\":\nself.range_max = 100\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update all generator classes
|
701,855 |
21.11.2017 12:30:21
| -46,800 |
658389af2822349cd845dd3a37233b8385fbac1e
|
Update resource template to remove local generation options
These are now defined in the generator class
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/templates/resources/resource.html",
"new_path": "csunplugged/templates/resources/resource.html",
"diff": "{{ options_html|safe }}\n- {% if debug %}\n<hr>\n- <h3>{% trans \"Local Generation Only\" %}</h3>\n-\n- <fieldset>\n- <legend>{% trans \"Header Text\" %}</legend>\n- <input type=\"text\" name=\"header_text\" placeholder=\"Example School: Room Four\" class=\"long-text-field\">\n- </fieldset>\n-\n- {% if resource.copies %}\n- <fieldset>\n- <legend>{% trans \"Number of Copies\" %}</legend>\n- <input type=\"number\" name=\"copies\" value=1 min=1 max=50>\n- </fieldset>\n- {% endif %}\n- <hr>\n+ {% if debug %}\n<input type=\"submit\" value=\"{% trans \"Generate Resource\" %}\" class=\"btn btn-outline-primary mb-3\" />\n{% else %}\n{% if resource.copies %}\n{% endblocktrans %}\n</div>\n{% endif %}\n-\n<input type=\"submit\" value=\"Download Resource\" class=\"btn btn-outline-primary mb-3\"/>\n{% endif %}\n</form>\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update resource template to remove local generation options
These are now defined in the generator class
|
701,855 |
21.11.2017 19:20:49
| -46,800 |
9d91666b0ac2a7255c83d32038bea95c271a41d9
|
Minor improvements as part of resource option restructure
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"new_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"diff": "@@ -59,7 +59,8 @@ class BaseResourceGenerator(ABC):\n\"header_text\": TextResourceParameter(\nname=\"header_text\",\ndescription=_(\"Header Text\"),\n- placeholder=_(\"Example School: Room Four\")\n+ placeholder=_(\"Example School: Room Four\"),\n+ required=False\n),\n}\nif self.copies:\n@@ -69,7 +70,8 @@ class BaseResourceGenerator(ABC):\ndescription=_(\"Number of Copies\"),\nmin_val=1,\nmax_val=50,\n- default=1\n+ default=1,\n+ required=False\n),\n})\nreturn local_options\n@@ -91,7 +93,7 @@ class BaseResourceGenerator(ABC):\nhtml_string = \"\"\nfor html_elem in html_elements:\n- html_string += etree.tostring(html_elem, encoding='utf-8').decode('utf-8')\n+ html_string += etree.tostring(html_elem, pretty_print=True, encoding='utf-8').decode('utf-8')\nreturn html_string\n@abstractmethod\n@@ -151,9 +153,12 @@ class BaseResourceGenerator(ABC):\ncontext[\"header_text\"] = self.options[\"header_text\"].value\ncontext[\"paper_size\"] = self.options[\"paper_size\"].value\n- num_copies = range(0, int(self.options[\"copies\"].value))\n+ if self.copies:\n+ num_copies = self.options[\"copies\"].value\n+ else:\n+ num_copies = 1\ncontext[\"all_data\"] = []\n- for copy in num_copies:\n+ for copy in range(num_copies):\ncopy_data = self.data()\nif not isinstance(copy_data, list):\ncopy_data = [copy_data]\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/resource_parameters.py",
"new_path": "csunplugged/resources/utils/resource_parameters.py",
"diff": "@@ -31,11 +31,15 @@ class SingleValuedParameter(ResourceParameter):\nself.required = required\ndef process_requested_values(self, requested_values):\n+\n+ if len(requested_values) > 1:\n+ raise QueryParameterMultipleValuesError(self.name, requested_values)\nif len(requested_values) == 0:\nif self.required:\nraise QueryParameterMissingError(self.name)\n- if len(requested_values) > 1:\n- raise QueryParameterMultipleValuesError(self.name, requested_values)\n+ else:\n+ self.value = self.default\n+ else:\nself.value = self.process_value(requested_values[0])\n@@ -50,9 +54,10 @@ class MultiValuedParameter(ResourceParameter):\nclass EnumResourceParameter(SingleValuedParameter):\n- def __init__(self, values=[], default=None, **kwargs):\n+ def __init__(self, values=dict(), default=None, **kwargs):\nsuper().__init__(**kwargs)\nself.valid_values = values\n+ self.indices = {value: i for i, value in enumerate(values.keys())}\nself.default = default\nif self.default not in self.valid_values:\nself.default = list(self.valid_values.keys())[0] # Select first value\n@@ -80,14 +85,17 @@ class EnumResourceParameter(SingleValuedParameter):\nbase_elem.append(etree.Element('br'))\nreturn base_elem\n+ def index(self, value):\n+ return self.indices[value]\n+\ndef process_value(self, value):\nif value not in self.valid_values:\nraise QueryParameterInvalidError(self.name, value)\nreturn value\nclass BoolResourceParameter(EnumResourceParameter):\n- TRUE_VALUE=\"true\"\n- FALSE_VALUE=\"false\"\n+ TRUE_VALUE=\"yes\"\n+ FALSE_VALUE=\"no\"\ndef __init__(self, default=True, true_text=_(\"Yes\"), false_text=_(\"No\"), **kwargs):\nvalues = {\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Minor improvements as part of resource option restructure
|
701,855 |
21.11.2017 19:24:23
| -46,800 |
30611917acc7c9f11334646194fb804a62cc2c47
|
Remove references to resource webpage templates
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/content/structure/resources.yaml",
"new_path": "csunplugged/resources/content/structure/resources.yaml",
"diff": "sorting-network:\nname: Sorting Network\n- webpage-template: resources/sorting-network.html\ngenerator-module: SortingNetworkResourceGenerator\nthumbnail-static-path: img/resources/resource-sorting-network-thumbnail-example.png\ncopies: true\nsorting-network-cards:\nname: Sorting Network Cards\n- webpage-template: resources/sorting-network-cards.html\ngenerator-module: SortingNetworkCardsResourceGenerator\nthumbnail-static-path: img/resources/sorting-network-cards/thumbnail.png\ncopies: false\ntreasure-hunt:\nname: Treasure Hunt\n- webpage-template: resources/treasure-hunt.html\ngenerator-module: TreasureHuntResourceGenerator\nthumbnail-static-path: img/resources/treasure-hunt/thumbnail.png\ncopies: true\nbinary-cards:\nname: Binary Cards\n- webpage-template: resources/binary-cards.html\ngenerator-module: BinaryCardsResourceGenerator\nthumbnail-static-path: img/resources/binary-cards/thumbnail.png\ncopies: false\nbinary-cards-small:\nname: Binary Cards (Small)\n- webpage-template: resources/binary-cards-small.html\ngenerator-module: BinaryCardsSmallResourceGenerator\nthumbnail-static-path: img/resources/binary-cards-small/thumbnail.png\ncopies: false\nbinary-windows:\nname: Binary Windows\n- webpage-template: resources/binary-windows.html\ngenerator-module: BinaryWindowsResourceGenerator\nthumbnail-static-path: img/resources/binary-windows/thumbnail.png\ncopies: false\nmodulo-clock:\nname: Modulo Clock\n- webpage-template: resources/modulo-clock.html\ngenerator-module: ModuloClockResourceGenerator\nthumbnail-static-path: img/resources/modulo-clock/thumbnail.png\ncopies: false\nbinary-to-alphabet:\nname: Binary to Alphabet\n- webpage-template: resources/binary-to-alphabet.html\ngenerator-module: BinaryToAlphabetResourceGenerator\nthumbnail-static-path: img/resources/binary-to-alphabet/thumbnail.png\ncopies: false\nparity-cards:\nname: Parity Cards\n- webpage-template: resources/parity-cards.html\ngenerator-module: ParityCardsResourceGenerator\nthumbnail-static-path: img/resources/parity-cards/thumbnail.png\ncopies: false\npiano-keys:\nname: Piano Keys\n- webpage-template: resources/piano-keys.html\ngenerator-module: PianoKeysResourceGenerator\nthumbnail-static-path: img/resources/piano-keys/thumbnail.png\ncopies: false\ntrain-stations:\nname: Train Stations\n- webpage-template: resources/train-stations.html\ngenerator-module: TrainStationsResourceGenerator\nthumbnail-static-path: img/resources/train-stations/thumbnail.png\ncopies: false\njob-badges:\nname: Job Badges\n- webpage-template: resources/job-badges.html\ngenerator-module: JobBadgesResourceGenerator\nthumbnail-static-path: img/resources/job-badges/thumbnail.png\ncopies: false\narrows:\nname: Arrows\n- webpage-template: resources/arrows.html\ngenerator-module: ArrowsResourceGenerator\nthumbnail-static-path: img/resources/arrows/thumbnail.png\ncopies: false\nleft-right-cards:\nname: Left and Right Cards\n- webpage-template: resources/left-right-cards.html\ngenerator-module: LeftRightCardsResourceGenerator\nthumbnail-static-path: img/resources/left-right-cards/thumbnail.png\ncopies: false\ngrid:\nname: Grid\n- webpage-template: resources/grid.html\ngenerator-module: GridResourceGenerator\nthumbnail-static-path: img/resources/grid/thumbnail.png\ncopies: false\nsearching-cards:\nname: Searching Cards\n- webpage-template: resources/searching-cards.html\ngenerator-module: SearchingCardsResourceGenerator\nthumbnail-static-path: img/resources/searching-cards/thumbnail.png\ncopies: false\nbarcode-checksum-poster:\nname: Barcode Checksum Poster\n- webpage-template: resources/barcode-checksum-poster.html\ngenerator-module: BarcodeChecksumPosterResourceGenerator\nthumbnail-static-path: img/resources/barcode-checksum-poster/thumbnail.gif\ncopies: false\npixel-painter:\nname: Pixel Painter\n- webpage-template: resources/pixel-painter.html\ngenerator-module: PixelPainterResourceGenerator\nthumbnail-static-path: img/resources/pixel-painter/thumbnail.png\ncopies: false\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/management/commands/_ResourcesLoader.py",
"new_path": "csunplugged/resources/management/commands/_ResourcesLoader.py",
"diff": "@@ -27,7 +27,6 @@ class ResourcesLoader(BaseLoader):\nfor (resource_slug, resource_structure) in resources_structure.items():\ntry:\nresource_name = resource_structure[\"name\"]\n- resource_template = resource_structure[\"webpage-template\"]\ngenerator_module = resource_structure[\"generator-module\"]\nresource_thumbnail = resource_structure[\"thumbnail-static-path\"]\nresource_copies = resource_structure[\"copies\"]\n@@ -36,7 +35,6 @@ class ResourcesLoader(BaseLoader):\nself.structure_file_path,\n[\n\"name\",\n- \"webpage-template\",\n\"generator-module\",\n\"thumbnail-static-path\",\n\"copies\"\n@@ -70,7 +68,6 @@ class ResourcesLoader(BaseLoader):\nresource = Resource(\nslug=resource_slug,\nname=resource_name,\n- webpage_template=resource_template,\ngenerator_module=generator_module,\nthumbnail_static_path=resource_thumbnail,\ncopies=resource_copies,\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/models.py",
"new_path": "csunplugged/resources/models.py",
"diff": "from django.db import models\n-\nclass Resource(models.Model):\n\"\"\"Model for resource in database.\"\"\"\n# Auto-incrementing 'id' field is automatically set by Django\nslug = models.SlugField(unique=True)\nname = models.CharField(max_length=200)\n- webpage_template = models.CharField(max_length=200)\ngenerator_module = models.CharField(max_length=200)\nthumbnail_static_path = models.CharField(max_length=200)\ncopies = models.BooleanField()\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Remove references to resource webpage templates
|
701,855 |
21.11.2017 19:25:44
| -46,800 |
4abc9bca085414369aee6c4543a98fcf55cb5bc6
|
Ongoing changes to resource generators as part of options restructure
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BarcodeChecksumPosterResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BarcodeChecksumPosterResourceGenerator.py",
"diff": "@@ -8,7 +8,7 @@ from resources.utils.resource_parameters import EnumResourceParameter\nBARCODE_LENGTH_VALUES = {\n\"12\": _(\"12 digits\"),\n- \"13\": _(\"13 digits\")\n+ \"13\": _(\"13 digits\"),\n}\nclass BarcodeChecksumPosterResourceGenerator(BaseResourceGenerator):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryToAlphabetResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryToAlphabetResourceGenerator.py",
"diff": "@@ -8,7 +8,7 @@ from resources.utils.resource_parameters import EnumResourceParameter\nWORKSHEET_VERSION_VALUES = {\n\"student\": _(\"Student\"),\n- \"teacher\": _(\"Teacher (solutions)\")\n+ \"teacher\": _(\"Teacher (solutions)\"),\n}\nclass BinaryToAlphabetResourceGenerator(BaseResourceGenerator):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryWindowsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryWindowsResourceGenerator.py",
"diff": "@@ -13,12 +13,12 @@ SMALL_FONT = ImageFont.truetype(FONT_PATH, 180)\nNUMBER_BITS_VALUES = {\n\"4\": _(\"Four (1 to 8)\"),\n- \"8\": _(\"Eight (1 to 128)\")\n+ \"8\": _(\"Eight (1 to 128)\"),\n}\nVALUE_TYPE_VALUES = {\n\"binary\": _(\"Binary (0 or 1)\"),\n- \"lightbulb\": _(\"Lightbulb (off or on)\")\n+ \"lightbulb\": _(\"Lightbulb (off or on)\"),\n}\nclass BinaryWindowsResourceGenerator(BaseResourceGenerator):\n@@ -43,7 +43,6 @@ class BinaryWindowsResourceGenerator(BaseResourceGenerator):\nvalues=VALUE_TYPE_VALUES,\ndefault=\"binary\"\n),\n-\n}\ndef data(self):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/ModuloClockResourceGenerator.py",
"new_path": "csunplugged/resources/generators/ModuloClockResourceGenerator.py",
"diff": "@@ -9,7 +9,7 @@ from resources.utils.resource_parameters import EnumResourceParameter\nMODULO_NUMBER_VALUES = {\n\"1\": \"Blank\",\n\"2\": \"2\",\n- \"10\": \"10\"\n+ \"10\": \"10\",\n}\nclass ModuloClockResourceGenerator(BaseResourceGenerator):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/ParityCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/ParityCardsResourceGenerator.py",
"diff": "@@ -18,7 +18,7 @@ BACK_COLOUR_VALUES={\n\"blue\": _(\"Blue\"),\n\"green\": _(\"Green\"),\n\"purple\": _(\"Purple\"),\n- \"red\": _(\"Red\")\n+ \"red\": _(\"Red\"),\n}\nclass ParityCardsResourceGenerator(BaseResourceGenerator):\n@@ -27,7 +27,7 @@ class ParityCardsResourceGenerator(BaseResourceGenerator):\ndef get_additional_options(self):\nreturn {\n\"back_colour\": EnumResourceParameter(\n- name=\"barcode_length\",\n+ name=\"back_colour\",\ndescription=_(\"Card back colour\"),\nvalues=BACK_COLOUR_VALUES,\ndefault=\"black\"\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/PianoKeysResourceGenerator.py",
"new_path": "csunplugged/resources/generators/PianoKeysResourceGenerator.py",
"diff": "@@ -59,7 +59,7 @@ KEY_DATA = {\n}\nHIGHLIGHT_VALUES = {\n- False: _(\"None\"),\n+ \"no\": _(\"None\"),\n\"A\": \"A\",\n\"B\": \"B\",\n\"C\": \"C\",\n@@ -93,7 +93,7 @@ class PianoKeysResourceGenerator(BaseResourceGenerator):\nimage = Image.open(image_path)\npage = Image.new(\"RGB\", image.size, \"#FFF\")\n- if highlight:\n+ if highlight != \"no\":\nself.highlight_key_areas(page, KEY_DATA.get(highlight))\n# Add piano keys overlay\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/PixelPainterResourceGenerator.py",
"new_path": "csunplugged/resources/generators/PixelPainterResourceGenerator.py",
"diff": "@@ -372,7 +372,7 @@ class PixelPainterResourceGenerator(BaseResourceGenerator):\nReturns:\nA 2D list containing page grid references as strings (list).\n\"\"\"\n- image_number = self.additional_valid_options[\"image\"].index(image)\n+ image_number = self.options[\"image\"].index(image)\nLETTERS = string.ascii_uppercase\npage_grid_coords = [[\"\"] * columns for i in range(rows)]\nfor row in range(0, rows):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/SortingNetworkResourceGenerator.py",
"new_path": "csunplugged/resources/generators/SortingNetworkResourceGenerator.py",
"diff": "@@ -10,7 +10,7 @@ PREFILLED_VALUES_VALUES = {\n\"easy\": _(\"Easy Numbers (1 digits)\"),\n\"medium\": _(\"Medium Numbers (2 digits)\"),\n\"hard\": _(\"Hard Numbers (3 digits)\"),\n- \"none\": _(\"None (Blank - Useful as template) \")\n+ \"blank\": _(\"None (Blank - Useful as template) \")\n}\nclass SortingNetworkResourceGenerator(BaseResourceGenerator):\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/TreasureHuntResourceGenerator.py",
"new_path": "csunplugged/resources/generators/TreasureHuntResourceGenerator.py",
"diff": "@@ -13,7 +13,7 @@ PREFILLED_VALUES_VALUES = {\n\"easy\": _(\"Easy Numbers (2 digits)\"),\n\"medium\": _(\"Medium Numbers (3 digits)\"),\n\"hard\": _(\"Hard Numbers (4 digits)\"),\n- \"none\": _(\"None (Blank)\")\n+ \"blank\": _(\"None (Blank)\")\n}\nNUMBER_ORDER_VALUES = {\n@@ -58,22 +58,13 @@ class TreasureHuntResourceGenerator(BaseResourceGenerator):\n),\n}\n- def __init__(self, requested_options=None):\n- \"\"\"Construct TreasureHuntResourceGenerator instance.\n-\n- Args:\n- requested_options: QueryDict of requested_options (QueryDict).\n- \"\"\"\n- super().__init__(requested_options)\n- if requested_options:\n- self.set_number_range()\n-\ndef data(self):\n\"\"\"Create data for a copy of the Treasure Hunt resource.\nReturns:\nA dictionary of the two pages for the resource.\n\"\"\"\n+\npages = []\nfont_path = \"static/fonts/PatrickHand-Regular.ttf\"\n@@ -92,10 +83,11 @@ class TreasureHuntResourceGenerator(BaseResourceGenerator):\n# Add numbers to image if required\nif prefilled_values != \"blank\":\n- font = ImageFont.truetype(font_path, self.font_size)\n+ range_min, range_max, font_size = self.get_number_range(prefilled_values)\n+ font = ImageFont.truetype(font_path, font_size)\ntotal_numbers = 26\n- numbers = sample(range(self.range_min, self.range_max), total_numbers)\n+ numbers = sample(range(range_min, range_max), total_numbers)\nif number_order == \"sorted\":\nnumbers.sort()\n@@ -118,7 +110,7 @@ class TreasureHuntResourceGenerator(BaseResourceGenerator):\nfill=\"#000\"\n)\n- text = \"{} - {} to {}\".format(number_order.title(), self.range_min, self.range_max - 1)\n+ text = \"{} - {} to {}\".format(number_order.title(), range_min, range_max - 1)\nfont = ImageFont.truetype(font_path, 75)\ntext_width, text_height = draw.textsize(text, font=font)\ncoord_x = 1220 - (text_width / 2)\n@@ -150,9 +142,10 @@ class TreasureHuntResourceGenerator(BaseResourceGenerator):\nif prefilled_values == \"blank\":\nrange_text = \"blank\"\nelse:\n+ range_min, range_max, font_size = self.get_number_range(prefilled_values)\ntemplate = \"{} - {} to {}\"\nnumber_order_text = number_order.title()\n- range_text = template.format(number_order_text, self.range_min, self.range_max - 1)\n+ range_text = template.format(number_order_text, range_min, range_max - 1)\nif art_style == \"colour\":\nart_style_text = \"full colour\"\n@@ -166,20 +159,23 @@ class TreasureHuntResourceGenerator(BaseResourceGenerator):\nreturn \"{} - {} - {} - {}\".format(range_text, art_style_text, instructions_text, super().subtitle)\n- def set_number_range(self):\n+ def get_number_range(self, range_descriptor):\n\"\"\"Return number range tuple for resource.\nReturns:\nTuple of (range_min, range_max, font_size)\n\"\"\"\n- prefilled_values = self.options[\"prefilled_values\"].value\n- self.range_min = 0\n- if prefilled_values == \"easy\":\n- self.range_max = 100\n- self.font_size = 55\n- elif prefilled_values == \"medium\":\n- self.range_max = 1000\n- self.font_size = 50\n- elif prefilled_values == \"hard\":\n- self.range_max = 10000\n- self.font_size = 45\n+ # prefilled_values = self.options[\"prefilled_values\"].value\n+ range_min = 0\n+ if range_descriptor == \"easy\":\n+ range_max = 100\n+ font_size = 55\n+ elif range_descriptor == \"medium\":\n+ range_max = 1000\n+ font_size = 50\n+ elif range_descriptor == \"hard\":\n+ range_max = 10000\n+ font_size = 45\n+ else:\n+ raise Exception(\"Unknown number range descriptor {}, wanted one of [easy, medium, hard\".format(range_descriptor))\n+ return (range_min, range_max, font_size)\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Ongoing changes to resource generators as part of options restructure
|
701,855 |
21.11.2017 19:26:34
| -46,800 |
f8073fd72c6d0ba8d56bd2f244e9c7da34f0737c
|
Add handling of QueryParameterMultipleValueError in views.py
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/views.py",
"new_path": "csunplugged/resources/views.py",
"diff": "@@ -71,6 +71,8 @@ def generate_resource(request, resource_slug):\nraise Http404(e) from e\nexcept QueryParameterInvalidError as e:\nraise Http404(e) from e\n+ except QueryParameterMultipleValuesError as e:\n+ raise Http404(e) from e\n# TODO: Weasyprint handling in production\n# TODO: Add creation of PDF as job to job queue\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add handling of QueryParameterMultipleValueError in views.py
|
701,855 |
21.11.2017 19:27:38
| -46,800 |
526355c263bf7d2834fd8591c9e6337dded038ba
|
Add test utils module with run_parameter_smoke_tests function
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/resources/generators/utils.py",
"diff": "+import sys\n+\n+from resources.utils.resource_parameters import (\n+ EnumResourceParameter,\n+ TextResourceParameter,\n+ IntegerResourceParameter,\n+ BoolResourceParameter,\n+)\n+\n+def run_parameter_smoke_tests(generator, option_name):\n+ option = generator.options[option_name]\n+ if isinstance(option, EnumResourceParameter):\n+ test_values = option.valid_values\n+ elif isinstance(option, TextResourceParameter):\n+ test_values = [\"\", \"test value\"]\n+ elif isinstance(option, IntegerResourceParameter):\n+ test_values = [\n+ option.min_val or -sys.maxsize,\n+ option.max_val or sys.maxsize\n+ ]\n+ elif isinstance(option, BoolResourceParameter):\n+ test_values = [True, False]\n+\n+ for value in test_values:\n+ generator.options[option_name].value = value\n+ try:\n+ generator.data() # Smoke test\n+ except Exception as e:\n+ raise Exception(\"Smoke test of option {} failed for value {}\".format(option_name, value)) from e\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add test utils module with run_parameter_smoke_tests function
|
701,855 |
21.11.2017 19:29:40
| -46,800 |
589e1c4cbc95f04f3056b1b8d93ec5ce57bf5f17
|
Add generator unit-tests to run smoke tests for all parameter values
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_barcode_checksum_poster.py",
"new_path": "csunplugged/tests/resources/generators/test_barcode_checksum_poster.py",
"diff": "@@ -2,7 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.BarcodeChecksumPosterResourceGenerator import BarcodeChecksumPosterResourceGenerator\n-\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\nclass BarcodeChecksumPosterResourceGeneratorTest(BaseTestWithDB):\n@@ -10,6 +10,11 @@ class BarcodeChecksumPosterResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"barcode_length=12&paper_size=a4\")\n+\n+ def test_barcode_length_values(self):\n+ generator = BarcodeChecksumPosterResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"barcode_length\")\ndef test_subtitle_12_a4(self):\nquery = QueryDict(\"barcode_length=12&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_binary_cards.py",
"new_path": "csunplugged/tests/resources/generators/test_binary_cards.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.BinaryCardsResourceGenerator import BinaryCardsResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,15 @@ class BinaryCardsResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"display_numbers=yes&black_back=yes&paper_size=a4\")\n+\n+ def test_black_back_values(self):\n+ generator = BinaryCardsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"black_back\")\n+\n+ def test_display_numbers_values(self):\n+ generator = BinaryCardsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"display_numbers\")\ndef test_subtitle_numbers_black_a4(self):\nquery = QueryDict(\"display_numbers=yes&black_back=yes&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_binary_cards_small.py",
"new_path": "csunplugged/tests/resources/generators/test_binary_cards_small.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.BinaryCardsSmallResourceGenerator import BinaryCardsSmallResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,19 @@ class BinaryCardsSmallResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"number_bits=4&dot_counts=yes&black_back=yes&paper_size=a4\")\n+\n+ def test_number_bits_values(self):\n+ generator = BinaryCardsSmallResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"number_bits\")\n+\n+ def test_black_back_values(self):\n+ generator = BinaryCardsSmallResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"black_back\")\n+\n+ def test_dot_counts(self):\n+ generator = BinaryCardsSmallResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"dot_counts\")\ndef test_subtitle_4_dots_black_a4(self):\nquery = QueryDict(\"number_bits=4&dot_counts=yes&black_back=yes&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_binary_to_alphabet.py",
"new_path": "csunplugged/tests/resources/generators/test_binary_to_alphabet.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.BinaryToAlphabetResourceGenerator import BinaryToAlphabetResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,11 @@ class BinaryToAlphabetResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"worksheet_version=student&paper_size=a4\")\n+\n+ def test_worksheet_version_values(self):\n+ generator = BinaryToAlphabetResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"worksheet_version\")\ndef test_subtitle_student_a4(self):\nquery = QueryDict(\"worksheet_version=student&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_binary_windows.py",
"new_path": "csunplugged/tests/resources/generators/test_binary_windows.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.BinaryWindowsResourceGenerator import BinaryWindowsResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,19 @@ class BinaryWindowsResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"number_bits=4&value_type=binary&dot_counts=yes&paper_size=a4\")\n+\n+ def test_number_bits_values(self):\n+ generator = BinaryWindowsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"number_bits\")\n+\n+ def test_value_type_values(self):\n+ generator = BinaryWindowsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"value_type\")\n+\n+ def test_dot_counts_values(self):\n+ generator = BinaryWindowsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"dot_counts\")\ndef test_subtitle_4_binary_dots_a4(self):\nquery = QueryDict(\"number_bits=4&value_type=binary&dot_counts=yes&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_modulo_clock.py",
"new_path": "csunplugged/tests/resources/generators/test_modulo_clock.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.ModuloClockResourceGenerator import ModuloClockResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,11 @@ class ModuloClockResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"modulo_number=1&paper_size=a4\")\n+\n+ def test_modulo_number_values(self):\n+ generator = ModuloClockResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"modulo_number\")\ndef test_subtitle_1_a4(self):\nquery = QueryDict(\"modulo_number=1&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_parity_cards.py",
"new_path": "csunplugged/tests/resources/generators/test_parity_cards.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.ParityCardsResourceGenerator import ParityCardsResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,11 @@ class ParityCardsResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"back_colour=black&paper_size=a4\")\n+\n+ def test_back_colour_values(self):\n+ generator = ParityCardsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"back_colour\")\ndef test_subtitle_black_a4(self):\nquery = QueryDict(\"back_colour=black&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_piano_keys.py",
"new_path": "csunplugged/tests/resources/generators/test_piano_keys.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.PianoKeysResourceGenerator import PianoKeysResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,11 @@ class PianoKeysResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"highlight=no&paper_size=a4\")\n+\n+ def test_highlight_values(self):\n+ generator = PianoKeysResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"highlight\")\ndef test_subtitle_no_a4(self):\nquery = QueryDict(\"highlight=no&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_pixel_painter.py",
"new_path": "csunplugged/tests/resources/generators/test_pixel_painter.py",
"diff": "@@ -4,7 +4,9 @@ from tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.PixelPainterResourceGenerator import PixelPainterResourceGenerator\nfrom filecmp import cmp\nfrom copy import deepcopy\n+from utils.errors.QueryParameterInvalidError import QueryParameterInvalidError\nimport os\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -15,45 +17,39 @@ class PixelPainterResourceGeneratorTest(BaseTestWithDB):\nself.language = \"en\"\nself.test_output_path = \"tests/output/\"\nos.makedirs(os.path.dirname(self.test_output_path), exist_ok=True)\n+ self.base_valid_query = QueryDict(\"image=boat&method=black-white&paper_size=a4\")\n+\n+ def test_image_values(self):\n+ generator = PixelPainterResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"image\")\n+\n+ def test_method_values(self):\n+ generator = PixelPainterResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"method\")\ndef test_pixel_painter_resource_generator_invalid_pixel_black_white(self):\n+ options = QueryDict(\"image=invalid&method=black-white&paper_size=a4\")\ngenerator = PixelPainterResourceGenerator()\n- generator.STATIC_PATH = \"tests/resources/generators/assets/pixel-painter/{}\"\n- generator.additional_valid_options = deepcopy(generator.additional_valid_options)\n- generator.additional_valid_options[\"image\"].append(\"invalid\")\n- generator.requested_options = QueryDict(\"image=invalid&method=black-white&paper_size=a4\")\n- self.assertRaises(\n- ValueError,\n- generator.data,\n- )\n+ with self.assertRaises(QueryParameterInvalidError):\n+ generator.process_requested_options(options)\ndef test_pixel_painter_resource_generator_invalid_pixel_greyscale(self):\n+ options = QueryDict(\"image=invalid&method=greyscale&paper_size=a4\")\ngenerator = PixelPainterResourceGenerator()\n- generator.STATIC_PATH = \"tests/resources/generators/assets/pixel-painter/{}\"\n- generator.additional_valid_options = deepcopy(generator.additional_valid_options)\n- generator.additional_valid_options[\"image\"].append(\"invalid\")\n- generator.requested_options = QueryDict(\"image=invalid&method=greyscale&paper_size=a4\")\n- self.assertRaises(\n- ValueError,\n- generator.data,\n- )\n+ with self.assertRaises(QueryParameterInvalidError):\n+ generator.process_requested_options(options)\ndef test_pixel_painter_resource_generator_invalid_pixel_colour(self):\n+ options = QueryDict(\"image=invalid&method=colour&paper_size=a4\")\ngenerator = PixelPainterResourceGenerator()\n- generator.STATIC_PATH = \"tests/resources/generators/assets/pixel-painter/{}\"\n- generator.additional_valid_options = deepcopy(generator.additional_valid_options)\n- generator.additional_valid_options[\"image\"].append(\"invalid\")\n- generator.requested_options = QueryDict(\"image=invalid&method=colour&paper_size=a4\")\n- self.assertRaises(\n- ValueError,\n- generator.data,\n- )\n+ with self.assertRaises(QueryParameterInvalidError):\n+ generator.process_requested_options(options)\ndef test_pixel_painter_resource_generator_thumbnail(self):\ntest_output_path = os.path.join(self.test_output_path, \"pixel-painter-thumbnail-test-1.png\")\n- generator = PixelPainterResourceGenerator()\n+ options = QueryDict(\"image=boat&method=black-white&paper_size=a4\")\n+ generator = PixelPainterResourceGenerator(options)\ngenerator.STATIC_PATH = \"tests/resources/generators/assets/pixel-painter/{}\"\n- generator.requested_options = QueryDict(\"image=boat&method=black-white&paper_size=a4\")\ngenerator.save_thumbnail(\"Test\", test_output_path)\ncompare_result = cmp(\ntest_output_path,\n@@ -64,9 +60,9 @@ class PixelPainterResourceGeneratorTest(BaseTestWithDB):\ndef test_pixel_painter_resource_generator_thumbnail_run_length(self):\ntest_output_path = os.path.join(self.test_output_path, \"pixel-painter-thumbnail-test-2.png\")\n- generator = PixelPainterResourceGenerator()\n+ options = QueryDict(\"image=boat&method=run-length-encoding&paper_size=a4\")\n+ generator = PixelPainterResourceGenerator(options)\ngenerator.STATIC_PATH = \"tests/resources/generators/assets/pixel-painter/{}\"\n- generator.requested_options = QueryDict(\"image=boat&method=run-length-encoding&paper_size=a4\")\ngenerator.save_thumbnail(\"Test\", test_output_path)\ncompare_result = cmp(\ntest_output_path,\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_searching_cards.py",
"new_path": "csunplugged/tests/resources/generators/test_searching_cards.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.SearchingCardsResourceGenerator import SearchingCardsResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,19 @@ class SearchingCardsResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"number_cards=15&max_number=cards&help_sheet=yes&paper_size=a4\")\n+\n+ def test_number_cards_values(self):\n+ generator = SearchingCardsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"number_cards\")\n+\n+ def test_max_number_values(self):\n+ generator = SearchingCardsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"max_number\")\n+\n+ def test_help_sheet_values(self):\n+ generator = SearchingCardsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"help_sheet\")\ndef test_subtitle_15_cards_sheet_a4(self):\nquery = QueryDict(\"number_cards=15&max_number=cards&help_sheet=yes&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_sorting_network.py",
"new_path": "csunplugged/tests/resources/generators/test_sorting_network.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.SortingNetworkResourceGenerator import SortingNetworkResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,11 @@ class SortingNetworkResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"prefilled_values=blank&paper_size=a4\")\n+\n+ def test_prefilled_values_values(self):\n+ generator = SortingNetworkResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"prefilled_values\")\ndef test_subtitle_blank_a4(self):\nquery = QueryDict(\"prefilled_values=blank&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_sorting_network_cards.py",
"new_path": "csunplugged/tests/resources/generators/test_sorting_network_cards.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.SortingNetworkCardsResourceGenerator import SortingNetworkCardsResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,11 @@ class SortingNetworkCardsResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"type=letters&paper_size=a4\")\n+\n+ def test_type_values(self):\n+ generator = SortingNetworkCardsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"type\")\ndef test_subtitle_letters_a4(self):\nquery = QueryDict(\"type=letters&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_train_stations.py",
"new_path": "csunplugged/tests/resources/generators/test_train_stations.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.TrainStationsResourceGenerator import TrainStationsResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,11 @@ class TrainStationsResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\"tracks=circular&paper_size=a4\")\n+\n+ def test_tracks_values(self):\n+ generator = TrainStationsResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"tracks\")\ndef test_subtitle_circular_a4(self):\nquery = QueryDict(\"tracks=circular&paper_size=a4\")\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/generators/test_treasure_hunt.py",
"new_path": "csunplugged/tests/resources/generators/test_treasure_hunt.py",
"diff": "@@ -2,6 +2,7 @@ from django.http import QueryDict\nfrom django.test import tag\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom resources.generators.TreasureHuntResourceGenerator import TreasureHuntResourceGenerator\n+from tests.resources.generators.utils import run_parameter_smoke_tests\n@tag(\"resource\")\n@@ -10,6 +11,25 @@ class TreasureHuntResourceGeneratorTest(BaseTestWithDB):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\nself.language = \"en\"\n+ self.base_valid_query = QueryDict(\n+ \"prefilled_values=blank&number_order=sorted&instructions=yes&art=colour&paper_size=a4\"\n+ )\n+\n+ def test_prefilled_values_values(self):\n+ generator = TreasureHuntResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"prefilled_values\")\n+\n+ def test_number_order_values(self):\n+ generator = TreasureHuntResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"number_order\")\n+\n+ def test_instructions_values(self):\n+ generator = TreasureHuntResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"instructions\")\n+\n+ def test_art_values(self):\n+ generator = TreasureHuntResourceGenerator(self.base_valid_query)\n+ run_parameter_smoke_tests(generator, \"art\")\ndef test_subtitle_blank_sorted_instructions_colour_a4(self):\nquery = QueryDict(\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add generator unit-tests to run smoke tests for all parameter values
|
701,855 |
21.11.2017 19:33:59
| -46,800 |
b777658988f7471a85364fe21ae1d5af3081135a
|
Remove unrequired kwarg header_text from resource_valid_configurations
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/management/commands/makeresources.py",
"new_path": "csunplugged/resources/management/commands/makeresources.py",
"diff": "@@ -10,6 +10,7 @@ from django.conf import settings\nfrom resources.models import Resource\nfrom resources.utils.get_resource_generator import get_resource_generator\nfrom resources.utils.resource_valid_configurations import resource_valid_configurations\n+from resources.utils.resource_parameters import EnumResourceParameter\nclass Command(BaseCommand):\n@@ -42,10 +43,10 @@ class Command(BaseCommand):\n# TODO: Import repeated in next for loop, check alternatives\nempty_generator = get_resource_generator(resource.generator_module)\n- combinations = resource_valid_configurations(\n- empty_generator.valid_options,\n- header_text=False\n- )\n+ if not all([isinstance(option, EnumResourceParameter) for option in empty_generator.get_options().values()]):\n+ raise Exception(\"Only EnumResourceParameters are supported for pre-generation\")\n+ valid_options = {option.name: list(option.valid_values.keys()) for option in empty_generator.get_options().values()}\n+ combinations = resource_valid_configurations(valid_options)\nprogress_bar = tqdm(combinations, ascii=True)\n# Create PDF for all possible combinations\nfor combination in progress_bar:\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/management/commands/makeresourcethumbnails.py",
"new_path": "csunplugged/resources/management/commands/makeresourcethumbnails.py",
"diff": "@@ -10,6 +10,7 @@ from resources.models import Resource\nfrom resources.utils.get_resource_generator import get_resource_generator\nfrom resources.utils.resource_valid_configurations import resource_valid_configurations\nfrom utils.bool_to_yes_no import bool_to_yes_no\n+from resources.utils.resource_parameters import EnumResourceParameter\nBASE_PATH_TEMPLATE = \"build/img/resources/{resource}/thumbnails/\"\n@@ -30,10 +31,11 @@ class Command(BaseCommand):\n# TODO: Import repeated in next for loop, check alternatives\nempty_generator = get_resource_generator(resource.generator_module)\n- combinations = resource_valid_configurations(\n- empty_generator.valid_options,\n- header_text=False\n- )\n+\n+ if not all([isinstance(option, EnumResourceParameter) for option in empty_generator.get_options().values()]):\n+ raise Exception(\"Only EnumResourceParameters are supported for pre-generation\")\n+ valid_options = {option.name: list(option.valid_values.keys()) for option in empty_generator.get_options().values()}\n+ combinations = resource_valid_configurations(valid_options)\n# Create thumbnail for all possible combinations\nprint(\"Creating thumbnails for {}\".format(resource.name))\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/resource_valid_configurations.py",
"new_path": "csunplugged/resources/utils/resource_valid_configurations.py",
"diff": "@@ -4,20 +4,17 @@ import itertools\nfrom copy import deepcopy\n-def resource_valid_configurations(valid_options, header_text=True):\n+def resource_valid_configurations(valid_options):\n\"\"\"Return list of all possible valid resource combinations.\nArgs:\nvalid_options: A dictionary containing all valid resource generation\noptions (dict).\n- header_text: If true, add in valid options for header text (bool).\nReturns:\nList of dictionaries of valid combinations (list).\n\"\"\"\nvalid_options = deepcopy(valid_options)\n- if header_text:\n- valid_options[\"header_text\"] = [\"\", \"Example header\"]\nvalid_option_keys = sorted(valid_options)\nreturn [dict(zip(valid_option_keys, product)) for product in itertools.product(\n*(valid_options[valid_option_key] for valid_option_key in valid_option_keys)\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/utils/test_resource_valid_configurations.py",
"new_path": "csunplugged/tests/resources/utils/test_resource_valid_configurations.py",
"diff": "@@ -13,8 +13,7 @@ class ResourceValidConfigurationsTest(SimpleTestCase):\nself.assertEqual(\nresource_valid_configurations(options),\n[\n- {\"header_text\": \"\", \"key1\": \"value1\"},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\"},\n+ {\"key1\": \"value1\"}\n]\n)\n@@ -25,10 +24,8 @@ class ResourceValidConfigurationsTest(SimpleTestCase):\nself.assertEqual(\nresource_valid_configurations(options),\n[\n- {\"header_text\": \"\", \"key1\": \"value1\"},\n- {\"header_text\": \"\", \"key1\": \"value2\"},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\"},\n- {\"header_text\": \"Example header\", \"key1\": \"value2\"},\n+ {\"key1\": \"value1\"},\n+ {\"key1\": \"value2\"}\n]\n)\n@@ -40,8 +37,7 @@ class ResourceValidConfigurationsTest(SimpleTestCase):\nself.assertEqual(\nresource_valid_configurations(options),\n[\n- {\"header_text\": \"\", \"key1\": \"value1\", \"key2\": \"value5\"},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\", \"key2\": \"value5\"},\n+ {\"key1\": \"value1\", \"key2\": \"value5\"}\n]\n)\n@@ -52,106 +48,20 @@ class ResourceValidConfigurationsTest(SimpleTestCase):\n}\nself.assertEqual(\nresource_valid_configurations(options),\n- [\n- {\"header_text\": \"\", \"key1\": \"value1\", \"key2\": \"value5\"},\n- {\"header_text\": \"\", \"key1\": \"value2\", \"key2\": \"value5\"},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\", \"key2\": \"value5\"},\n- {\"header_text\": \"Example header\", \"key1\": \"value2\", \"key2\": \"value5\"},\n- ]\n- )\n-\n- def test_dictionary_three_keys_many_values(self):\n- options = {\n- \"key1\": [\"value1\", \"value2\"],\n- \"key2\": [\"value5\", \"value6\", \"value7\"],\n- \"key3\": [True, False],\n- }\n- self.assertEqual(\n- resource_valid_configurations(options),\n- [\n- {\"header_text\": \"\", \"key1\": \"value1\", \"key2\": \"value5\", \"key3\": True},\n- {\"header_text\": \"\", \"key1\": \"value1\", \"key2\": \"value5\", \"key3\": False},\n- {\"header_text\": \"\", \"key1\": \"value1\", \"key2\": \"value6\", \"key3\": True},\n- {\"header_text\": \"\", \"key1\": \"value1\", \"key2\": \"value6\", \"key3\": False},\n- {\"header_text\": \"\", \"key1\": \"value1\", \"key2\": \"value7\", \"key3\": True},\n- {\"header_text\": \"\", \"key1\": \"value1\", \"key2\": \"value7\", \"key3\": False},\n- {\"header_text\": \"\", \"key1\": \"value2\", \"key2\": \"value5\", \"key3\": True},\n- {\"header_text\": \"\", \"key1\": \"value2\", \"key2\": \"value5\", \"key3\": False},\n- {\"header_text\": \"\", \"key1\": \"value2\", \"key2\": \"value6\", \"key3\": True},\n- {\"header_text\": \"\", \"key1\": \"value2\", \"key2\": \"value6\", \"key3\": False},\n- {\"header_text\": \"\", \"key1\": \"value2\", \"key2\": \"value7\", \"key3\": True},\n- {\"header_text\": \"\", \"key1\": \"value2\", \"key2\": \"value7\", \"key3\": False},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\", \"key2\": \"value5\", \"key3\": True},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\", \"key2\": \"value5\", \"key3\": False},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\", \"key2\": \"value6\", \"key3\": True},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\", \"key2\": \"value6\", \"key3\": False},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\", \"key2\": \"value7\", \"key3\": True},\n- {\"header_text\": \"Example header\", \"key1\": \"value1\", \"key2\": \"value7\", \"key3\": False},\n- {\"header_text\": \"Example header\", \"key1\": \"value2\", \"key2\": \"value5\", \"key3\": True},\n- {\"header_text\": \"Example header\", \"key1\": \"value2\", \"key2\": \"value5\", \"key3\": False},\n- {\"header_text\": \"Example header\", \"key1\": \"value2\", \"key2\": \"value6\", \"key3\": True},\n- {\"header_text\": \"Example header\", \"key1\": \"value2\", \"key2\": \"value6\", \"key3\": False},\n- {\"header_text\": \"Example header\", \"key1\": \"value2\", \"key2\": \"value7\", \"key3\": True},\n- {\"header_text\": \"Example header\", \"key1\": \"value2\", \"key2\": \"value7\", \"key3\": False},\n- ]\n- )\n-\n- def test_dictionary_one_key_one_value_no_header_text(self):\n- options = {\n- \"key1\": [\"value1\"]\n- }\n- self.assertEqual(\n- resource_valid_configurations(options, header_text=False),\n- [\n- {\"key1\": \"value1\"}\n- ]\n- )\n-\n- def test_dictionary_one_key_two_values_no_header_text(self):\n- options = {\n- \"key1\": [\"value1\", \"value2\"]\n- }\n- self.assertEqual(\n- resource_valid_configurations(options, header_text=False),\n- [\n- {\"key1\": \"value1\"},\n- {\"key1\": \"value2\"}\n- ]\n- )\n-\n- def test_dictionary_two_keys_two_values_no_header_text(self):\n- options = {\n- \"key1\": [\"value1\"],\n- \"key2\": [\"value5\"]\n- }\n- self.assertEqual(\n- resource_valid_configurations(options, header_text=False),\n- [\n- {\"key1\": \"value1\", \"key2\": \"value5\"}\n- ]\n- )\n-\n- def test_dictionary_two_keys_three_values_no_header_text(self):\n- options = {\n- \"key1\": [\"value1\", \"value2\"],\n- \"key2\": [\"value5\"],\n- }\n- self.assertEqual(\n- resource_valid_configurations(options, header_text=False),\n[\n{\"key1\": \"value1\", \"key2\": \"value5\"},\n{\"key1\": \"value2\", \"key2\": \"value5\"}\n]\n)\n- def test_dictionary_three_keys_many_values_no_header_text(self):\n+ def test_dictionary_three_keys_many_values(self):\noptions = {\n\"key1\": [\"value1\", \"value2\"],\n\"key2\": [\"value5\", \"value6\", \"value7\"],\n\"key3\": [True, False],\n}\nself.assertEqual(\n- resource_valid_configurations(options, header_text=False),\n+ resource_valid_configurations(options),\n[\n{\"key1\": \"value1\", \"key2\": \"value5\", \"key3\": True},\n{\"key1\": \"value1\", \"key2\": \"value5\", \"key3\": False},\n@@ -176,7 +86,7 @@ class ResourceValidConfigurationsTest(SimpleTestCase):\n\"d\": [\"d\"]\n}\nself.assertEqual(\n- resource_valid_configurations(options, header_text=False),\n+ resource_valid_configurations(options),\n[\n{\"a\": \"a\", \"b\": \"b\", \"c\": \"c\", \"d\": \"d\"}\n]\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Remove unrequired kwarg header_text from resource_valid_configurations
|
701,855 |
22.11.2017 09:49:41
| -46,800 |
1aad072b2c9ee66ecf99095bd6ee62296f0d6fd0
|
Add HTML info box to match original formatting in binary-windows.md
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/content/en/binary-windows.md",
"new_path": "csunplugged/resources/content/en/binary-windows.md",
"diff": "This resource contains printouts for binary numbers activities.\n-Note: This resource should be printed double sided on short edge.\n+<div class=\"alert alert-info\" role=\"alert\">\n+ <p class=\"mb-1\">Note: This resource should be printed double sided on short edge.</p>\n+</div>\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add HTML info box to match original formatting in binary-windows.md
|
701,855 |
22.11.2017 10:03:51
| -46,800 |
f7c4cfe36c392ca3d26741a6443b911a4e34dfcd
|
Update resource view tests for new resource structure
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/ResourcesTestDataGenerator.py",
"new_path": "csunplugged/tests/resources/ResourcesTestDataGenerator.py",
"diff": "@@ -6,7 +6,7 @@ from resources.models import Resource\nclass ResourcesTestDataGenerator:\n\"\"\"Class for generating test data for resource tests.\"\"\"\n- def create_resource(self, slug, name, webpage_template, generator_module, thumbnail=True, copies=False):\n+ def create_resource(self, slug, name, content, generator_module, thumbnail=True, copies=False):\n\"\"\"Create resource object.\nArgs:\n@@ -21,7 +21,7 @@ class ResourcesTestDataGenerator:\nresource = Resource(\nslug=\"resource-{}\".format(slug),\nname=\"Resource {}\".format(name),\n- webpage_template=webpage_template,\n+ content=content,\ngenerator_module=generator_module,\ncopies=copies,\n)\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/views/test_index_view.py",
"new_path": "csunplugged/tests/resources/views/test_index_view.py",
"diff": "@@ -23,7 +23,7 @@ class IndexViewTest(BaseTestWithDB):\nself.test_data.create_resource(\n\"binary-cards\",\n\"Binary Cards\",\n- \"resources/binary-cards.html\",\n+ \"Description of binary cards\",\n\"BinaryCardsResourceGenerator\",\n)\nurl = reverse(\"resources:index\")\n@@ -38,13 +38,13 @@ class IndexViewTest(BaseTestWithDB):\nself.test_data.create_resource(\n\"binary-cards\",\n\"Binary Cards\",\n- \"resources/binary-cards.html\",\n+ \"Description of binary cards\",\n\"BinaryCardsResourceGenerator\",\n)\nself.test_data.create_resource(\n\"sorting-network\",\n\"Sorting Network\",\n- \"resources/sorting-network.html\",\n+ \"Description of sorting network\",\n\"SortingNetworkResourceGenerator.py\",\n)\nurl = reverse(\"resources:index\")\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update resource view tests for new resource structure
|
701,855 |
22.11.2017 11:02:21
| -46,800 |
8f141763821063dbd9fcfaa9bf8fbf4ce49e2831
|
Move get_options_html function to utils module
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"new_path": "csunplugged/resources/utils/BaseResourceGenerator.py",
"diff": "@@ -42,8 +42,9 @@ class BaseResourceGenerator(ABC):\nif requested_options:\nself.process_requested_options(requested_options)\n- def get_options(self):\n- options = self.get_additional_options()\n+ @classmethod\n+ def get_options(cls):\n+ options = cls.get_additional_options()\noptions.update({\n\"paper_size\": EnumResourceParameter(\nname=\"paper_size\",\n@@ -54,7 +55,9 @@ class BaseResourceGenerator(ABC):\n})\nreturn options\n- def get_local_options(self):\n+ @classmethod\n+ def get_local_options(cls):\n+ local_options = cls.get_additional_local_options()\nlocal_options = {\n\"header_text\": TextResourceParameter(\nname=\"header_text\",\n@@ -63,7 +66,7 @@ class BaseResourceGenerator(ABC):\nrequired=False\n),\n}\n- if self.copies:\n+ if cls.copies:\nlocal_options.update({\n\"copies\": IntegerResourceParameter(\nname=\"copies\",\n@@ -76,25 +79,13 @@ class BaseResourceGenerator(ABC):\n})\nreturn local_options\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {}\n- def get_options_html(self):\n- html_elements = []\n- for parameter in self.get_options().values():\n- html_elements.append(parameter.html_element())\n- if settings.DEBUG:\n- html_elements.append(etree.Element(\"hr\"))\n- h3 = etree.Element(\"h3\")\n- h3.text = _(\"Local Generation Only\")\n- html_elements.append(h3)\n- for parameter in self.get_local_options().values():\n- html_elements.append(parameter.html_element())\n-\n- html_string = \"\"\n- for html_elem in html_elements:\n- html_string += etree.tostring(html_elem, pretty_print=True, encoding='utf-8').decode('utf-8')\n- return html_string\n+ @classmethod\n+ def get_additional_local_options(cls):\n+ return {}\n@abstractmethod\ndef data(self):\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/resources/utils/get_options_html.py",
"diff": "+from django.conf import settings\n+from lxml import etree\n+from django.utils.translation import ugettext as _\n+\n+def get_options_html(options, local_options):\n+ html_elements = []\n+ for parameter in options.values():\n+ html_elements.append(parameter.html_element())\n+ if settings.DEBUG:\n+ html_elements.append(etree.Element(\"hr\"))\n+ h3 = etree.Element(\"h3\")\n+ h3.text = _(\"Local Generation Only\")\n+ html_elements.append(h3)\n+ for parameter in local_options.values():\n+ html_elements.append(parameter.html_element())\n+\n+ html_string = \"\"\n+ for html_elem in html_elements:\n+ html_string += etree.tostring(html_elem, pretty_print=True, encoding='utf-8').decode('utf-8')\n+ return html_string\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/views.py",
"new_path": "csunplugged/resources/views.py",
"diff": "@@ -6,6 +6,7 @@ from django.shortcuts import get_object_or_404, render\nfrom django.views import generic\nfrom resources.models import Resource\nfrom resources.utils.resource_pdf_cache import resource_pdf_cache\n+from resources.utils.get_options_html import get_options_html\nfrom utils.group_lessons_by_age import group_lessons_by_age\nfrom resources.utils.get_resource_generator import get_resource_generator\nfrom utils.errors.QueryParameterMissingError import QueryParameterMissingError\n@@ -41,7 +42,8 @@ def resource(request, resource_slug):\n\"\"\"\nresource = get_object_or_404(Resource, slug=resource_slug)\ncontext = dict()\n- context[\"options_html\"] = get_resource_generator(resource.generator_module).get_options_html()\n+ generator = get_resource_generator(resource.generator_module)\n+ context[\"options_html\"] = get_options_html(generator.get_options(), generator.get_local_options())\ncontext[\"resource\"] = resource\ncontext[\"debug\"] = settings.DEBUG\ncontext[\"resource_thumbnail_base\"] = \"{}img/resources/{}/thumbnails/\".format(settings.STATIC_URL, resource.slug)\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Move get_options_html function to utils module
|
701,855 |
22.11.2017 11:03:31
| -46,800 |
72597f21d643502c5b0752ef66f8caa0ef1d435d
|
Change get_options() etc. to be class methods
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BarcodeChecksumPosterResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BarcodeChecksumPosterResourceGenerator.py",
"diff": "@@ -14,7 +14,8 @@ BARCODE_LENGTH_VALUES = {\nclass BarcodeChecksumPosterResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Grid resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"barcode_length\": EnumResourceParameter(\nname=\"barcode_length\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryCardsResourceGenerator.py",
"diff": "@@ -24,7 +24,8 @@ IMAGE_DATA = [\nclass BinaryCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary Cards resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"display_numbers\": BoolResourceParameter(\nname=\"display_numbers\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryCardsSmallResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryCardsSmallResourceGenerator.py",
"diff": "@@ -26,7 +26,8 @@ NUMBER_BITS_VALUES = {\nclass BinaryCardsSmallResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary Cards (small) resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"number_bits\": EnumResourceParameter(\nname=\"number_bits\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryToAlphabetResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryToAlphabetResourceGenerator.py",
"diff": "@@ -14,7 +14,8 @@ WORKSHEET_VERSION_VALUES = {\nclass BinaryToAlphabetResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary to Alphabet resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"worksheet_version\": EnumResourceParameter(\nname=\"worksheet_version\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/BinaryWindowsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/BinaryWindowsResourceGenerator.py",
"diff": "@@ -24,7 +24,8 @@ VALUE_TYPE_VALUES = {\nclass BinaryWindowsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Binary Windows resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"number_bits\": EnumResourceParameter(\nname=\"number_bits\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/ModuloClockResourceGenerator.py",
"new_path": "csunplugged/resources/generators/ModuloClockResourceGenerator.py",
"diff": "@@ -15,7 +15,8 @@ MODULO_NUMBER_VALUES = {\nclass ModuloClockResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Modulo Clock resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"modulo_number\": EnumResourceParameter(\nname=\"modulo_number\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/ParityCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/ParityCardsResourceGenerator.py",
"diff": "@@ -24,7 +24,8 @@ BACK_COLOUR_VALUES={\nclass ParityCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Parity Cards resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"back_colour\": EnumResourceParameter(\nname=\"back_colour\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/PianoKeysResourceGenerator.py",
"new_path": "csunplugged/resources/generators/PianoKeysResourceGenerator.py",
"diff": "@@ -72,7 +72,8 @@ HIGHLIGHT_VALUES = {\nclass PianoKeysResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Piano Keys resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"highlight\": EnumResourceParameter(\nname=\"highlight\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/PixelPainterResourceGenerator.py",
"new_path": "csunplugged/resources/generators/PixelPainterResourceGenerator.py",
"diff": "@@ -85,7 +85,8 @@ class PixelPainterResourceGenerator(BaseResourceGenerator):\nLINE_COLOUR = \"#666\"\nLINE_WIDTH = 1\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"method\": EnumResourceParameter(\nname=\"method\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/SearchingCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/SearchingCardsResourceGenerator.py",
"diff": "@@ -29,7 +29,8 @@ MAX_NUMBER_VALUE = {\nclass SearchingCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Searching Cards resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"number_cards\": EnumResourceParameter(\nname=\"number_cards\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/SortingNetworkCardsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/SortingNetworkCardsResourceGenerator.py",
"diff": "@@ -27,7 +27,8 @@ TYPE_VALUES = {\nclass SortingNetworkCardsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Sorting Network Cards resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"type\": EnumResourceParameter(\nname=\"type\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/SortingNetworkResourceGenerator.py",
"new_path": "csunplugged/resources/generators/SortingNetworkResourceGenerator.py",
"diff": "@@ -17,7 +17,8 @@ class SortingNetworkResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Sorting Network resource generator.\"\"\"\ncopies = True\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"prefilled_values\": EnumResourceParameter(\nname=\"prefilled_values\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/TrainStationsResourceGenerator.py",
"new_path": "csunplugged/resources/generators/TrainStationsResourceGenerator.py",
"diff": "@@ -13,7 +13,8 @@ TRACKS_VALUES = {\nclass TrainStationsResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Train Stations resource generator.\"\"\"\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"tracks\": EnumResourceParameter(\nname=\"tracks\",\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/generators/TreasureHuntResourceGenerator.py",
"new_path": "csunplugged/resources/generators/TreasureHuntResourceGenerator.py",
"diff": "@@ -31,7 +31,8 @@ class TreasureHuntResourceGenerator(BaseResourceGenerator):\n\"\"\"Class for Treasure Hunt resource generator.\"\"\"\ncopies = True\n- def get_additional_options(self):\n+ @classmethod\n+ def get_additional_options(cls):\nreturn {\n\"prefilled_values\": EnumResourceParameter(\nname=\"prefilled_values\",\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Change get_options() etc. to be class methods
|
701,855 |
22.11.2017 11:04:57
| -46,800 |
ff27db7002c843f9bbed01e8bb950379d2dd7505
|
Add/update unit tests for BaseResourceGenerator
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/BareResourceGenerator.py",
"new_path": "csunplugged/tests/resources/BareResourceGenerator.py",
"diff": "@@ -24,3 +24,7 @@ class BareResourceGenerator(BaseResourceGenerator):\nA dictionary of the one page for the resource.\n\"\"\"\nreturn {\"type\": \"html\", \"data\": \"Page 1\"}\n+\n+\n+class BareResourceGeneratorWithCopies(BareResourceGenerator):\n+ copies = True\n"
},
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/utils/test_BaseResourceGenerator.py",
"new_path": "csunplugged/tests/resources/utils/test_BaseResourceGenerator.py",
"diff": "@@ -2,11 +2,12 @@ from django.test import tag\nfrom django.http import QueryDict\nfrom tests.BaseTestWithDB import BaseTestWithDB\nfrom tests.resources.ResourcesTestDataGenerator import ResourcesTestDataGenerator\n-from tests.resources.BareResourceGenerator import BareResourceGenerator\n+from tests.resources.BareResourceGenerator import BareResourceGenerator, BareResourceGeneratorWithCopies\nfrom unittest.mock import MagicMock\nfrom utils.errors.ThumbnailPageNotFoundError import ThumbnailPageNotFoundError\nfrom utils.errors.MoreThanOneThumbnailPageFoundError import MoreThanOneThumbnailPageFoundError\nfrom resources.utils.BaseResourceGenerator import BaseResourceGenerator\n+from resources.utils.resource_parameters import ResourceParameter, EnumResourceParameter\nfrom io import BytesIO\nfrom PyPDF2 import PdfFileReader\n@@ -25,7 +26,7 @@ class BaseResourceGeneratorTest(BaseTestWithDB):\nself.assertEqual(pdf.getNumPages(), 1)\ndef test_pdf_single_page_copies(self):\n- generator = BareResourceGenerator(QueryDict(\"paper_size=a4&copies=8\"))\n+ generator = BareResourceGeneratorWithCopies(QueryDict(\"paper_size=a4&copies=8\"))\n(pdf_file, filename) = generator.pdf(\"Test\")\npdf = PdfFileReader(BytesIO(pdf_file))\nself.assertEqual(pdf.getNumPages(), 8)\n@@ -43,7 +44,7 @@ class BaseResourceGeneratorTest(BaseTestWithDB):\nself.assertEqual(pdf.getNumPages(), 2)\ndef test_pdf_multiple_pages_copies(self):\n- generator = BareResourceGenerator(QueryDict(\"paper_size=a4&copies=8\"))\n+ generator = BareResourceGeneratorWithCopies(QueryDict(\"paper_size=a4&copies=8\"))\ngenerator.data = MagicMock(\nreturn_value=[\n{\"type\": \"html\", \"data\": \"Page 1\"},\n@@ -103,3 +104,92 @@ class BaseResourceGeneratorTest(BaseTestWithDB):\nwith self.assertRaises(TypeError):\nInvalidGenerator()\n+\n+\n+ def test_get_options(self):\n+ options = BaseResourceGenerator.get_options()\n+ options_order = [\"paper_size\"]\n+ # check options are correct, including ordering\n+ self.assertListEqual(options_order, list(options))\n+ for option in options.values():\n+ self.assertIsInstance(option, ResourceParameter)\n+\n+ def test_get_local_options(self):\n+ local_options = BaseResourceGenerator.get_local_options()\n+ options_order = [\"header_text\"]\n+ self.assertListEqual(options_order, list(local_options))\n+ for option in local_options.values():\n+ self.assertIsInstance(option, ResourceParameter)\n+\n+ def test_get_local_options_with_copies(self):\n+ class SubclassWithCopies(BaseResourceGenerator):\n+ copies = True\n+ local_options = SubclassWithCopies.get_local_options()\n+ options_order = [\"header_text\", \"copies\"]\n+ self.assertListEqual(options_order, list(local_options))\n+ for option in local_options.values():\n+ self.assertIsInstance(option, ResourceParameter)\n+\n+ def test_all_options(self):\n+ generator = BareResourceGenerator()\n+ normal_options = generator.get_options()\n+ local_options = generator.get_local_options()\n+ # Order should be normal options, then local options\n+ options_order = list(normal_options) + list(local_options)\n+ self.assertListEqual(options_order, list(generator.options))\n+ for option in local_options.values():\n+ self.assertIsInstance(option, ResourceParameter)\n+\n+\n+ def test_get_options_subclass_additional_options(self):\n+ class GeneratorSubclass(BaseResourceGenerator):\n+\n+ @classmethod\n+ def get_additional_options(cls):\n+ return {\n+ \"subclass_option\": EnumResourceParameter(\n+ name=\"subclass_option\",\n+ description=\"Description\",\n+ values={\"value1\": \"Value 1\"}\n+ ),\n+ }\n+\n+ options = GeneratorSubclass.get_options()\n+ # Subclass options before base class options\n+ options_order = [\"subclass_option\", \"paper_size\"]\n+ self.assertListEqual(options_order, list(options))\n+ for option in options.values():\n+ self.assertIsInstance(option, ResourceParameter)\n+\n+ def test_get_local_options_subclass_additional_local_options(self):\n+ class GeneratorSubclass(BaseResourceGenerator):\n+\n+ @classmethod\n+ def get_additional_options(cls):\n+ return {\n+ \"subclass_local_option\": EnumResourceParameter(\n+ name=\"subclass_local_option\",\n+ description=\"Description\",\n+ values={\"value1\": \"Value 1\"}\n+ ),\n+ }\n+\n+ local_options = GeneratorSubclass.get_options()\n+ # Subclass options before base class options\n+ options_order = [\"subclass_local_option\", \"paper_size\"]\n+ self.assertListEqual(options_order, list(local_options))\n+ for option in local_options.values():\n+ self.assertIsInstance(option, ResourceParameter)\n+\n+\n+ def test_process_requested_options_valid(self):\n+ pass\n+\n+ def test_process_requested_options_invalid(self):\n+ pass\n+\n+ def test_process_requested_options_missing_required(self):\n+ pass\n+\n+ def test_process_requested_options_subclass_additional_options(self):\n+ pass\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add/update unit tests for BaseResourceGenerator
|
701,855 |
22.11.2017 12:03:37
| -46,800 |
12915a19cc860d29e80ce33be4fb318b4536f2ed
|
Add unit tests for get_options_html.py
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/resources/utils/test_get_options_html.py",
"diff": "+from tests.BaseTest import BaseTest\n+from resources.utils.get_options_html import get_options_html\n+from resources.utils.resource_parameters import EnumResourceParameter\n+from lxml import etree\n+from django.test import override_settings\n+\n+class GetOptionsHTMLTest(BaseTest):\n+\n+ def test_get_options_html_no_local(self):\n+ options = {\n+ \"option1\": EnumResourceParameter(\n+ name=\"option1\",\n+ description=\"Option 1\",\n+ values={\"value1\": \"Value 1\"},\n+ ),\n+ \"option2\": EnumResourceParameter(\n+ name=\"option2\",\n+ description=\"Option 2\",\n+ values={\"value2\": \"Value 2\"},\n+ )\n+ }\n+ html = \"<form>{}</form>\".format(get_options_html(options, None))\n+ form = etree.fromstring(html)\n+ option1_elems = form.xpath(\"fieldset/input[@name='option1']\")\n+ self.assertEqual(1, len(option1_elems))\n+ option2_elems = option1_elems[0].xpath(\"../following-sibling::fieldset/input[@name='option2']\")\n+ self.assertEqual(1, len(option2_elems))\n+\n+ # Check local generation heading is not included\n+ self.assertNotIn(\"Local Generation Only\", html)\n+\n+\n+ def test_get_options_html_with_local_no_debug(self):\n+ options = {\n+ \"option1\": EnumResourceParameter(\n+ name=\"option1\",\n+ description=\"Option 1\",\n+ values={\"value1\": \"Value 1\"},\n+ ),\n+ \"option2\": EnumResourceParameter(\n+ name=\"option2\",\n+ description=\"Option 2\",\n+ values={\"value2\": \"Value 2\"},\n+ )\n+ }\n+ local_options = {\n+ \"local1\": EnumResourceParameter(\n+ name=\"local1\",\n+ description=\"Option 1\",\n+ values={\"value1\": \"Value 1\"},\n+ ),\n+ \"local2\": EnumResourceParameter(\n+ name=\"local2\",\n+ description=\"Option 2\",\n+ values={\"value2\": \"Value 2\"},\n+ )\n+ }\n+ html = \"<form>{}</form>\".format(get_options_html(options, local_options))\n+ form = etree.fromstring(html)\n+ option1_elems = form.xpath(\"fieldset/input[@name='option1']\")\n+ self.assertEqual(1, len(option1_elems))\n+ # Option 2 after Option 1\n+ option2_elems = option1_elems[0].xpath(\"../following-sibling::fieldset/input[@name='option2']\")\n+ self.assertEqual(1, len(option2_elems))\n+\n+ # Debug is not True, so local settings should not be included\n+ self.assertNotIn(\"local1\", html)\n+ self.assertNotIn(\"local2\", html)\n+ self.assertNotIn(\"Local Generation Only\", html)\n+\n+ @override_settings(DEBUG=True)\n+ def test_get_options_html_with_local_and_debug(self):\n+ options = {\n+ \"option1\": EnumResourceParameter(\n+ name=\"option1\",\n+ description=\"Option 1\",\n+ values={\"value1\": \"Value 1\"},\n+ ),\n+ \"option2\": EnumResourceParameter(\n+ name=\"option2\",\n+ description=\"Option 2\",\n+ values={\"value2\": \"Value 2\"},\n+ )\n+ }\n+ local_options = {\n+ \"local1\": EnumResourceParameter(\n+ name=\"local1\",\n+ description=\"Option 1\",\n+ values={\"value1\": \"Value 1\"},\n+ ),\n+ \"local2\": EnumResourceParameter(\n+ name=\"local2\",\n+ description=\"Option 2\",\n+ values={\"value2\": \"Value 2\"},\n+ )\n+ }\n+ html = \"<form>{}</form>\".format(get_options_html(options, local_options))\n+ form = etree.fromstring(html)\n+ option1_elems = form.xpath(\"fieldset/input[@name='option1']\")\n+ self.assertEqual(1, len(option1_elems))\n+ option2_elems = option1_elems[0].xpath(\"../following-sibling::fieldset/input[@name='option2']\")\n+ self.assertEqual(1, len(option2_elems))\n+\n+ # Debug is True, so local settings should be included\n+ self.assertIn(\"local1\", html)\n+ self.assertIn(\"local2\", html)\n+ self.assertIn(\"Local Generation Only\", html)\n+\n+ # Local options heading should follow other options\n+ local_options_headings = option2_elems[0].xpath(\"../following-sibling::h3[text()='Local Generation Only']\")\n+ self.assertEqual(1, len(local_options_headings))\n+\n+ # Local options should follow heading\n+ local1_elems = local_options_headings[0].xpath(\"following-sibling::fieldset/input[@name='local1']\")\n+ self.assertEqual(1, len(local1_elems))\n+ local2_elems = local1_elems[0].xpath(\"../following-sibling::fieldset/input[@name='local2']\")\n+ self.assertEqual(1, len(local1_elems))\n+\n+ def test_get_options_html_no_options(self):\n+ result = get_options_html({}, {})\n+ self.assertEqual(\"\", result)\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add unit tests for get_options_html.py
|
701,855 |
22.11.2017 12:13:14
| -46,800 |
0336f446393618ba6ab30f4d6ee8f8295e97a87e
|
Update Resource migrations to reflect model changes
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/resources/migrations/0010_auto_20171121_2304.py",
"diff": "+# -*- coding: utf-8 -*-\n+# Generated by Django 1.11.5 on 2017-11-21 23:04\n+from __future__ import unicode_literals\n+\n+import django.contrib.postgres.fields\n+from django.db import migrations, models\n+\n+\n+class Migration(migrations.Migration):\n+\n+ dependencies = [\n+ ('resources', '0009_auto_20171020_1005'),\n+ ]\n+\n+ operations = [\n+ migrations.RemoveField(\n+ model_name='resource',\n+ name='webpage_template',\n+ ),\n+ migrations.AddField(\n+ model_name='resource',\n+ name='content',\n+ field=models.TextField(default=''),\n+ ),\n+ migrations.AddField(\n+ model_name='resource',\n+ name='content_en',\n+ field=models.TextField(default='', null=True),\n+ ),\n+ migrations.AddField(\n+ model_name='resource',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=5), default=[], size=None),\n+ ),\n+ migrations.AddField(\n+ model_name='resource',\n+ name='name_en',\n+ field=models.CharField(default='', max_length=200, null=True),\n+ ),\n+ migrations.AlterField(\n+ model_name='resource',\n+ name='name',\n+ field=models.CharField(default='', max_length=200),\n+ ),\n+ ]\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update Resource migrations to reflect model changes
|
701,855 |
22.11.2017 13:49:51
| -46,800 |
0c7840525611e85af131a1b1d43d7d02dda76f27
|
Add base class process_requested_values, raises NotImplementedError
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/resource_parameters.py",
"new_path": "csunplugged/resources/utils/resource_parameters.py",
"diff": "@@ -18,6 +18,9 @@ class ResourceParameter(object):\nfieldset.append(legend)\nreturn fieldset\n+ def process_requested_values(self):\n+ raise NotImplementedError(\"process_requested_values must be implemented on all ResourceParameter subclasses\")\n+\ndef process_value(self, value):\nreturn value\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add base class process_requested_values, raises NotImplementedError
|
701,855 |
22.11.2017 13:50:56
| -46,800 |
415a6eed4aeb53c0400326e5a6258ddb2ff39402
|
Add test skeleton for resource_parameters unit tests
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/tests/resources/utils/test_resource_parameters.py",
"diff": "+class ResourceParametersTest(BaseTest):\n+\n+ def test_resource_parameter_base_process_requested_values(self):\n+ pass\n+\n+ def test_resource_parameter_base_process_value(self):\n+ pass\n+\n+ def test_resource_parameter_base_html_element(self):\n+ pass\n+\n+ def test_single_valued_parameter_process_requested_values_required_present(self):\n+ pass\n+\n+ def test_single_valued_parameter_process_requested_values_required_missing(self):\n+ pass\n+\n+ def test_single_valued_parameter_process_requested_values_not_required_missing(self):\n+ pass\n+\n+ def test_single_valued_parameter_process_requested_values_multiple_values(self):\n+ pass\n+\n+ def test_multi_valued_parameter_process_requested_values_single_value(self):\n+ pass\n+\n+ def test_multi_valued_parameter_process_requested_values_multiple_values(self):\n+ pass\n+\n+ def test_enum_resource_parameter_html_element(self):\n+ pass\n+\n+ def test_enum_resource_parameter_process_valid_value(self):\n+ pass\n+\n+ def test_enum_resource_parameter_process_invalid_value(self):\n+ pass\n+\n+ def test_enum_resource_parameter_process_missing_value_with_default(self):\n+ pass\n+\n+ def test_enum_resource_parameter_process_missing_value_without_default(self):\n+ pass\n+\n+ def test_enum_resource_parameter_index(self):\n+ pass\n+\n+ def test_bool_resource_parameter_default_text(self):\n+ pass\n+\n+ def test_bool_resource_parameter_custom_text(self):\n+ pass\n+\n+ def test_bool_resource_parameter_process_value_valid(self):\n+ pass\n+\n+ def test_bool_resource_parameter_process_value_invalid(self):\n+ pass\n+\n+ def test_text_resource_parameter_html_element(self):\n+ pass\n+\n+ def test_text_resource_parameter_html_element_with_placeholder(self):\n+ pass\n+\n+ def test_integer_resource_parameter_html_element(self):\n+ pass\n+\n+ def test_integer_resource_parameter_html_element_with_min_max_default(self):\n+ pass\n+\n+ def test_integer_resource_parameter_process_value(self):\n+ pass\n+\n+ def test_integer_resource_parameter_process_value_invalid_value_type(self):\n+ pass\n+\n+ def test_integer_resource_parameter_process_value_out_of_range(self):\n+ pass\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add test skeleton for resource_parameters unit tests
|
701,855 |
22.11.2017 15:06:35
| -46,800 |
43b94adc33cef099cd25b05481b8455b7f3ad28f
|
Fix process_requested_values function signature on base class
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/resources/utils/resource_parameters.py",
"new_path": "csunplugged/resources/utils/resource_parameters.py",
"diff": "@@ -18,7 +18,7 @@ class ResourceParameter(object):\nfieldset.append(legend)\nreturn fieldset\n- def process_requested_values(self):\n+ def process_requested_values(self, requested_values):\nraise NotImplementedError(\"process_requested_values must be implemented on all ResourceParameter subclasses\")\ndef process_value(self, value):\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Fix process_requested_values function signature on base class
|
701,855 |
22.11.2017 15:07:07
| -46,800 |
dfc24cd3214b8b417882536bc96b1c94ff90dfbb
|
Implement unit tests for resource_parameters.py
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/utils/test_resource_parameters.py",
"new_path": "csunplugged/tests/resources/utils/test_resource_parameters.py",
"diff": "+from tests.BaseTest import BaseTest\n+from lxml import etree\n+from utils.errors.QueryParameterMissingError import QueryParameterMissingError\n+from utils.errors.QueryParameterInvalidError import QueryParameterInvalidError\n+from utils.errors.QueryParameterMultipleValuesError import QueryParameterMultipleValuesError\n+\n+from resources.utils.resource_parameters import (\n+ ResourceParameter,\n+ SingleValuedParameter,\n+ MultiValuedParameter,\n+ EnumResourceParameter,\n+ BoolResourceParameter,\n+ TextResourceParameter,\n+ IntegerResourceParameter\n+)\n+\nclass ResourceParametersTest(BaseTest):\ndef test_resource_parameter_base_process_requested_values(self):\n- pass\n+ param = ResourceParameter()\n+ with self.assertRaises(NotImplementedError):\n+ param.process_requested_values(None)\ndef test_resource_parameter_base_process_value(self):\n- pass\n+ param = ResourceParameter()\n+ processed = param.process_value(\"value\")\n+ # Parameter should be unchanged\n+ self.assertEqual(\"value\", processed)\ndef test_resource_parameter_base_html_element(self):\n- pass\n+ param = ResourceParameter(\"param1\", \"param1 description\")\n+ html = param.html_element()\n+ self.assertIsInstance(html, etree._Element)\n+ self.assertEqual(\"fieldset\", html.tag)\n+ self.assertEqual(1, len(html)) # Should only have 1 child, the\n+ self.assertEqual(\"legend\", html[0].tag)\n+ self.assertEqual(\"param1 description\", html[0].text)\ndef test_single_valued_parameter_process_requested_values_required_present(self):\n- pass\n+ param = SingleValuedParameter()\n+ param.process_requested_values([1])\n+ self.assertEqual(1, param.value)\ndef test_single_valued_parameter_process_requested_values_required_missing(self):\n- pass\n+ param = SingleValuedParameter()\n+ with self.assertRaises(QueryParameterMissingError):\n+ param.process_requested_values([])\ndef test_single_valued_parameter_process_requested_values_not_required_missing(self):\n- pass\n+ param = SingleValuedParameter(default=\"default value\", required=False)\n+ param.process_requested_values([])\n+ self.assertEqual(\"default value\", param.value)\n+\ndef test_single_valued_parameter_process_requested_values_multiple_values(self):\n- pass\n+ param = SingleValuedParameter()\n+ with self.assertRaises(QueryParameterMultipleValuesError):\n+ param.process_requested_values([\"value1\", \"value2\"])\ndef test_multi_valued_parameter_process_requested_values_single_value(self):\n- pass\n+ param = MultiValuedParameter()\n+ param.process_requested_values([\"value1\"])\n+ self.assertEqual([\"value1\"], param.values)\ndef test_multi_valued_parameter_process_requested_values_multiple_values(self):\n- pass\n+ param = MultiValuedParameter()\n+ param.process_requested_values([\"value1\", \"value2\"])\n+ self.assertEqual([\"value1\", \"value2\"], param.values)\ndef test_enum_resource_parameter_html_element(self):\n- pass\n-\n- def test_enum_resource_parameter_process_valid_value(self):\n- pass\n-\n- def test_enum_resource_parameter_process_invalid_value(self):\n- pass\n-\n- def test_enum_resource_parameter_process_missing_value_with_default(self):\n- pass\n-\n- def test_enum_resource_parameter_process_missing_value_without_default(self):\n- pass\n+ values = {\"value1\": \"Value 1\", \"value2\": \"Value 2\"}\n+ param = EnumResourceParameter(\n+ name=\"option1\",\n+ values=values,\n+ default=\"value2\",\n+ description=\"option1 description\"\n+ )\n+ html = param.html_element()\n+ self.assertIsInstance(html, etree._Element)\n+ self.assertEqual(\"fieldset\", html.tag)\n+ self.assertEqual(7, len(html)) # legend, (input, label, br) X 2\n+\n+ self.assertEqual(\"legend\", html[0].tag)\n+ self.assertEqual(\"option1 description\", html[0].text)\n+\n+ self.assertEqual(\"input\", html[1].tag)\n+ self.assertEqual(\"option1\", html[1].get(\"name\"))\n+ self.assertEqual(\"value1\", html[1].get(\"value\"))\n+ self.assertEqual(\"radio\", html[1].get(\"type\"))\n+ self.assertEqual(None, html[1].get(\"checked\")) # Not the default\n+\n+ self.assertEqual(\"label\", html[2].tag)\n+ self.assertEqual(\"Value 1\", html[2].text)\n+\n+ self.assertEqual(\"br\", html[3].tag)\n+\n+ self.assertEqual(\"input\", html[4].tag)\n+ self.assertEqual(\"option1\", html[1].get(\"name\"))\n+ self.assertEqual(\"value2\", html[4].get(\"value\"))\n+ self.assertEqual(\"radio\", html[4].get(\"type\"))\n+ self.assertEqual(\"checked\", html[4].get(\"checked\")) # default\n+\n+ self.assertEqual(\"label\", html[5].tag)\n+ self.assertEqual(\"Value 2\", html[5].text)\n+\n+ self.assertEqual(\"br\", html[6].tag)\n+\n+ def test_enum_resource_parameter_process_value_valid_value(self):\n+ param = EnumResourceParameter(values={\"value1\": \"Value 1\"})\n+ processed = param.process_value(\"value1\")\n+ self.assertEqual(\"value1\", processed) # Returned unchanged\n+\n+ def test_enum_resource_parameter_process_value_invalid_value(self):\n+ param = EnumResourceParameter(values={\"value1\": \"Value 1\"})\n+ with self.assertRaises(QueryParameterInvalidError):\n+ param.process_value(\"invalid\")\ndef test_enum_resource_parameter_index(self):\n- pass\n+ param = EnumResourceParameter(values={\"1\":\"One\", \"2\":\"Two\", \"3\":\"Three\"})\n+ self.assertEqual(1, param.index(\"2\")) # Index of value 2 in the dict\ndef test_bool_resource_parameter_default_text(self):\n- pass\n+ param = BoolResourceParameter()\n+ self.assertEqual({\"yes\": \"Yes\", \"no\": \"No\"}, param.valid_values)\ndef test_bool_resource_parameter_custom_text(self):\n- pass\n+ param = BoolResourceParameter(true_text=\"Custom1\", false_text=\"Custom2\")\n+ self.assertEqual({\"yes\": \"Custom1\", \"no\": \"Custom2\"}, param.valid_values)\ndef test_bool_resource_parameter_process_value_valid(self):\n- pass\n+ param = BoolResourceParameter()\n+ self.assertEqual(True, param.process_value(\"yes\"))\n+ self.assertEqual(False, param.process_value(\"no\"))\ndef test_bool_resource_parameter_process_value_invalid(self):\n- pass\n+ param = BoolResourceParameter()\n+ with self.assertRaises(QueryParameterInvalidError):\n+ param.process_value(\"invalid\")\ndef test_text_resource_parameter_html_element(self):\n- pass\n+ param = TextResourceParameter(name=\"option1\")\n+ html = param.html_element()\n+ self.assertIsInstance(html, etree._Element)\n+\n+ self.assertEqual(\"fieldset\", html.tag)\n+ self.assertEqual(2, len(html)) # legend and input\n+ self.assertEqual(\"legend\", html[0].tag)\n+\n+ self.assertEqual(\"input\", html[1].tag)\n+ self.assertEqual(\"option1\", html[1].get(\"name\"))\n+ self.assertEqual(\"\", html[1].get(\"placeholder\"))\n+ self.assertEqual(\"text\", html[1].get(\"type\"))\ndef test_text_resource_parameter_html_element_with_placeholder(self):\n- pass\n+ param = TextResourceParameter(name=\"option1\", placeholder=\"placeholder text\")\n+ html = param.html_element()\n+ self.assertIsInstance(html, etree._Element)\n+\n+ self.assertEqual(\"fieldset\", html.tag)\n+ self.assertEqual(2, len(html)) # legend and input\n+ self.assertEqual(\"legend\", html[0].tag)\n+\n+ self.assertEqual(\"input\", html[1].tag)\n+ self.assertEqual(\"option1\", html[1].get(\"name\"))\n+ self.assertEqual(\"placeholder text\", html[1].get(\"placeholder\"))\n+ self.assertEqual(\"text\", html[1].get(\"type\"))\ndef test_integer_resource_parameter_html_element(self):\n- pass\n+ param = IntegerResourceParameter(name=\"option1\")\n+ html = param.html_element()\n+ self.assertIsInstance(html, etree._Element)\n- def test_integer_resource_parameter_html_element_with_min_max_default(self):\n- pass\n+ self.assertEqual(\"fieldset\", html.tag)\n+ self.assertEqual(2, len(html)) # legend and input\n+ self.assertEqual(\"legend\", html[0].tag)\n- def test_integer_resource_parameter_process_value(self):\n- pass\n+ self.assertEqual(\"input\", html[1].tag)\n+ self.assertEqual(\"option1\", html[1].get(\"name\"))\n+ self.assertEqual(\"number\", html[1].get(\"type\"))\n+ self.assertEqual(None, html[1].get(\"min\"))\n+ self.assertEqual(None, html[1].get(\"max\"))\n+ self.assertEqual(None, html[1].get(\"value\"))\n- def test_integer_resource_parameter_process_value_invalid_value_type(self):\n- pass\n+ def test_integer_resource_parameter_html_element_with_min_max_default(self):\n+ param = IntegerResourceParameter(\n+ name=\"option1\",\n+ default=20,\n+ min_val=10,\n+ max_val=30\n+ )\n+ html = param.html_element()\n+ self.assertIsInstance(html, etree._Element)\n+\n+ self.assertEqual(\"fieldset\", html.tag)\n+ self.assertEqual(2, len(html)) # legend and input\n+ self.assertEqual(\"legend\", html[0].tag)\n+\n+ self.assertEqual(\"input\", html[1].tag)\n+ self.assertEqual(\"option1\", html[1].get(\"name\"))\n+ self.assertEqual(\"number\", html[1].get(\"type\"))\n+ self.assertEqual(\"10\", html[1].get(\"min\"))\n+ self.assertEqual(\"30\", html[1].get(\"max\"))\n+ self.assertEqual(\"20\", html[1].get(\"value\"))\n+\n+ def test_integer_resource_parameter_process_value_no_range(self):\n+ param = IntegerResourceParameter(name=\"option1\")\n+ self.assertEqual(10, param.process_value(\"10\"))\n+ self.assertEqual(0, param.process_value(\"0\"))\n+ self.assertEqual(-10, param.process_value(\"-10\"))\n+\n+ def test_integer_resource_parameter_process_value_in_range(self):\n+ param = IntegerResourceParameter(name=\"option1\", min_val=-20, max_val=20)\n+ self.assertEqual(10, param.process_value(\"10\"))\n+ self.assertEqual(0, param.process_value(\"0\"))\n+ self.assertEqual(-10, param.process_value(\"-10\"))\ndef test_integer_resource_parameter_process_value_out_of_range(self):\n- pass\n+ param = IntegerResourceParameter(name=\"option1\", min_val=-20, max_val=20)\n+ with self.assertRaises(QueryParameterInvalidError):\n+ param.process_value(\"-30\")\n+ with self.assertRaises(QueryParameterInvalidError):\n+ param.process_value(\"30\")\n+\n+ def test_integer_resource_parameter_process_value_invalid_value_type(self):\n+ param = IntegerResourceParameter(name=\"option1\")\n+ with self.assertRaises(QueryParameterInvalidError):\n+ param.process_value(\"notaninteger\")\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Implement unit tests for resource_parameters.py
|
701,855 |
22.11.2017 16:25:08
| -46,800 |
b68887f025eed37ab2e27bdfdf321933e63d1c77
|
Increase language field max len to 10 (some codes are not xx-yy format)
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/utils/TranslatableModel.py",
"new_path": "csunplugged/utils/TranslatableModel.py",
"diff": "@@ -29,7 +29,7 @@ class UntranslatedModelManager(models.Manager):\nclass TranslatableModel(models.Model):\n\"\"\"Abstract base class for models needing to store list of available languages.\"\"\"\n- languages = ArrayField(models.CharField(max_length=5), default=[])\n+ languages = ArrayField(models.CharField(max_length=10), default=[])\nobjects = models.Manager()\ntranslated_objects = TranslatedModelManager()\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Increase language field max len to 10 (some codes are not xx-yy format)
|
701,855 |
22.11.2017 16:26:16
| -46,800 |
730074b8b0d00e65e6e3f1e58212b0185995822e
|
Add missing topics migration to remove de/fr columns
|
[
{
"change_type": "ADD",
"old_path": null,
"new_path": "csunplugged/topics/migrations/0087_auto_20171122_0324.py",
"diff": "+# -*- coding: utf-8 -*-\n+# Generated by Django 1.11.5 on 2017-11-22 03:24\n+from __future__ import unicode_literals\n+\n+import django.contrib.postgres.fields\n+from django.db import migrations, models\n+\n+\n+class Migration(migrations.Migration):\n+\n+ dependencies = [\n+ ('topics', '0086_auto_20171108_0840'),\n+ ]\n+\n+ operations = [\n+ migrations.RemoveField(\n+ model_name='agegroup',\n+ name='description_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='agegroup',\n+ name='description_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='classroomresource',\n+ name='description_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='classroomresource',\n+ name='description_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumarea',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumarea',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumintegration',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumintegration',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumintegration',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='curriculumintegration',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='glossaryterm',\n+ name='definition_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='glossaryterm',\n+ name='definition_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='glossaryterm',\n+ name='term_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='glossaryterm',\n+ name='term_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='learningoutcome',\n+ name='text_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='learningoutcome',\n+ name='text_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='computational_thinking_links_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='computational_thinking_links_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='heading_tree_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='heading_tree_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='programming_challenges_description_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='lesson',\n+ name='programming_challenges_description_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='extra_challenge_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='extra_challenge_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallenge',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengedifficulty',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengedifficulty',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='expected_result_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='expected_result_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='hints_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='hints_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='solution_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengeimplementation',\n+ name='solution_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengelanguage',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='programmingchallengelanguage',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='resourcedescription',\n+ name='description_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='resourcedescription',\n+ name='description_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='name_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='other_resources_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='topic',\n+ name='other_resources_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='computational_thinking_links_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='computational_thinking_links_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='content_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='content_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='heading_tree_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='heading_tree_fr',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='name_de',\n+ ),\n+ migrations.RemoveField(\n+ model_name='unitplan',\n+ name='name_fr',\n+ ),\n+ migrations.AlterField(\n+ model_name='agegroup',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='classroomresource',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='curriculumarea',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='curriculumintegration',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='glossaryterm',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='learningoutcome',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='lesson',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='programmingchallenge',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='programmingchallengedifficulty',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='programmingchallengeimplementation',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='programmingchallengelanguage',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='resourcedescription',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='topic',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ migrations.AlterField(\n+ model_name='unitplan',\n+ name='languages',\n+ field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=10), default=[], size=None),\n+ ),\n+ ]\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Add missing topics migration to remove de/fr columns
|
701,855 |
22.11.2017 16:27:46
| -46,800 |
bdf307f82ffba032c3b8834dbade8a077fba901b
|
Run unit tests without migrations; add smoke test for loading content
|
[
{
"change_type": "MODIFY",
"old_path": ".travis.yml",
"new_path": ".travis.yml",
"diff": "@@ -15,6 +15,7 @@ install:\njobs:\ninclude:\n- stage: test\n+ script: ./csu ci load_content\nscript: ./csu ci test_general\n- script: ./csu ci test_resources\n- script: ./csu ci test_management\n"
},
{
"change_type": "MODIFY",
"old_path": "csu",
"new_path": "csu",
"diff": "@@ -64,11 +64,9 @@ cmd_start() {\necho \"Creating systems...\"\ndocker-compose up -d\necho \"\"\n- # Run helper functions\n- cmd_update\n# Alert user that system is ready\n- echo -e \"\\n${GREEN}Systems are ready!${NC}\"\n- echo \"Open your preferred web browser to the URL 'localhost'\"\n+ echo -e \"\\n${GREEN}System is up!${NC}\"\n+ echo \"Run the command ./csu update to load content.\"\n}\ndefhelp start 'Start development environment (this also runs the update command).'\n@@ -106,6 +104,9 @@ cmd_update() {\necho \"\"\ndev_makeresourcethumbnails\ndev_collect_static\n+ echo \"\"\n+ echo -e \"\\n${GREEN}Content is loaded!${NC}\"\n+ echo \"Open your preferred web browser to the URL 'localhost'\"\n}\ndefhelp update 'Run Django migrate and updatedata commands and build static files.'\n@@ -236,11 +237,7 @@ defhelp -dev style 'Run style checks.'\n# Run test suite\ndev_test_suite() {\necho \"Running test suite...\"\n- if [ \"$CONTINUOUS_INTEGRATION\" == \"true\" ]; then\n- docker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3\n- else\ndocker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --nomigrations\n- fi\n}\ndefhelp -dev test_suite 'Run test suite with code coverage.'\n@@ -262,7 +259,7 @@ defhelp -dev test_coverage 'Display code coverage report.'\n# Run test suite backwards for CI testing\ndev_test_backwards() {\necho \"Running test suite backwards...\"\n- docker-compose exec django /docker_venv/bin/python3 ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" --reverse -v 0\n+ docker-compose exec django /docker_venv/bin/python3 ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" --reverse -v 0 --nomigrations\n}\ndefhelp -dev test_backwards 'Run test suite backwards.'\n@@ -319,7 +316,7 @@ cmd_logs() {\ndefhelp logs 'View logs.'\nci_test_general() {\n- docker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --exclude-tag=resource --exclude-tag=management\n+ docker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --exclude-tag=resource --exclude-tag=management --nomigrations\ntest_status=$?\ndev_test_coverage\ncoverage_status=$?\n@@ -328,7 +325,7 @@ ci_test_general() {\n}\nci_test_resources() {\n- docker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --tag=resource\n+ docker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --tag=resource --nomigrations\ntest_status=$?\ndev_test_coverage\ncoverage_status=$?\n@@ -337,7 +334,7 @@ ci_test_resources() {\n}\nci_test_management() {\n- docker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --tag=management\n+ docker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --tag=management --nomigrations\ntest_status=$?\ndev_test_coverage\ncoverage_status=$?\n@@ -357,6 +354,10 @@ ci_docs() {\ndev_docs\n}\n+ci_load_content() {\n+ cmd_update\n+}\n+\ncmd_ci() {\ncmd_start\nlocal cmd=\"$1\"\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Run unit tests without migrations; add smoke test for loading content
|
701,855 |
22.11.2017 16:39:26
| -46,800 |
20a0ee7026bf3cb6fa6586b51072f7c6dd68791b
|
Update docs to reflect separating ./csu start and ./csu update
|
[
{
"change_type": "MODIFY",
"old_path": "docs/source/getting_started/helper_commands.rst",
"new_path": "docs/source/getting_started/helper_commands.rst",
"diff": "@@ -259,7 +259,14 @@ More details for each command can be found on this page.\n``start``\n==============================================================================\n-Running ``./csu start`` starts the development environment.\n+Running ``./csu start`` starts the development environment. It performs the\n+following tasks:\n+\n+- Build system Docker images if required (see below)\n+- Start the Django website system\n+- Start the Nginx server to display the website and static files\n+- Start the database server\n+\nWhen you run this command for the first time on a computer it will also run\n``./csu build`` to build the system Docker images.\nThis can take some time, roughly 15 to 30 minutes, depending on your computer\n@@ -268,19 +275,10 @@ Images are only required to be built once, unless the image specifications\nchange (you can rebuild the images with ``./csu build``).\nOnce the images are built, the script will run these images in containers.\n-Once the development environment is operational, the script will perform the\n-following tasks:\n+Once the development environment is operational, run the ``./csu update``\n+command to load the CS Unplugged content.\n-- Start the Django website system\n-- Start the Nginx server to display the website and static files\n-- Start the database server\n-- Update the database with the required structure (known as the schema)\n-- Load the CS Unplugged content into the database\n-- Create the required static files\n-Once the script has performed all these tasks, the script will let you know\n-the website is ready.\n-Open your preferred web browser to the URL ``localhost`` to view the website.\n-----------------------------------------------------------------------------\n@@ -289,7 +287,17 @@ Open your preferred web browser to the URL ``localhost`` to view the website.\n``update``\n==============================================================================\n-Running ``./csu update`` runs the Django ``makemigratations`` and ``migrate``\n+Running ``./csu update`` performs the following tasks:\n+\n+- Update the database with the required structure (known as the schema)\n+- Load the CS Unplugged content into the database\n+- Create the required static files\n+\n+Once the script has performed all these tasks, the script will let you know\n+the website is ready.\n+Open your preferred web browser to the URL ``localhost`` to view the website.\n+\n+In more detail, ``./csu update`` runs the Django ``makemigratations`` and ``migrate``\ncommands for updating the database schema, and then runs the custom\n``updatedata`` command to load the topics content into the database.\nIt also runs the ``static`` command to generate static files.\n"
},
{
"change_type": "MODIFY",
"old_path": "docs/source/getting_started/installation.rst",
"new_path": "docs/source/getting_started/installation.rst",
"diff": "@@ -224,12 +224,13 @@ To check the project works, open a terminal in the project root directory,\nwhich is the ``cs-unplugged/`` directory (should contain a file called\n``csu``).\n-Type the following command into the terminal (we will cover this command\n+Type the following commands into the terminal (we will cover these commands\nin more detail on the next page):\n.. code-block:: bash\n$ ./csu start\n+ $ ./csu update\nIf this is the first time you're running this script, it will need to build\nsystem images.\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Update docs to reflect separating ./csu start and ./csu update
|
701,855 |
22.11.2017 17:42:47
| -46,800 |
b49d516f007c508c6fd2ea42efc7c74d54e08464
|
Fix failing makeresourcethumbnail tests (previously failing silently)
|
[
{
"change_type": "MODIFY",
"old_path": "csunplugged/tests/resources/management/test_makeresourcethumbnails_command.py",
"new_path": "csunplugged/tests/resources/management/test_makeresourcethumbnails_command.py",
"diff": "@@ -13,7 +13,7 @@ class MakeResourceThumnbailsCommandTest(BaseTestWithDB):\nsuper().__init__(*args, **kwargs)\nself.test_data = ResourcesTestDataGenerator()\nself.language = \"en\"\n- self.THUMBNAIL_PATH = \"staticfiles/img/resources/{}/thumbnails/{}\"\n+ self.THUMBNAIL_PATH = \"build/img/resources/{}/thumbnails/{}\"\ndef test_makeresourcethumbnails_command_single_resource(self):\nself.test_data.create_resource(\n@@ -22,9 +22,11 @@ class MakeResourceThumnbailsCommandTest(BaseTestWithDB):\n\"resources/grid.html\",\n\"GridResourceGenerator\",\n)\n+ # TODO: Fix these tests, they shouldn't be writing files into the build directory\nmanagement.call_command(\"makeresourcethumbnails\")\n- open(self.THUMBNAIL_PATH.format(\"grid\", \"grid-paper_size-a4.png\"))\n- open(self.THUMBNAIL_PATH.format(\"grid\", \"grid-paper_size-letter.png\"))\n+ open(self.THUMBNAIL_PATH.format(\"resource-grid\", \"resource-grid-paper_size-a4.png\"))\n+ open(self.THUMBNAIL_PATH.format(\"resource-grid\", \"resource-grid-paper_size-letter.png\"))\n+\ndef test_makeresourcethumbnails_command_multiple_resources(self):\nself.test_data.create_resource(\n@@ -39,8 +41,9 @@ class MakeResourceThumnbailsCommandTest(BaseTestWithDB):\n\"resources/arrows.html\",\n\"ArrowsResourceGenerator\",\n)\n+ # TODO: Fix these tests, they shouldn't be writing files into the build directory\nmanagement.call_command(\"makeresourcethumbnails\")\n- open(self.THUMBNAIL_PATH.format(\"grid\", \"grid-paper_size-a4.png\"))\n- open(self.THUMBNAIL_PATH.format(\"grid\", \"grid-paper_size-letter.png\"))\n- open(self.THUMBNAIL_PATH.format(\"arrows\", \"arrows-paper_size-a4.png\"))\n- open(self.THUMBNAIL_PATH.format(\"arrows\", \"arrows-paper_size-letter.png\"))\n+ open(self.THUMBNAIL_PATH.format(\"resource-grid\", \"resource-grid-paper_size-a4.png\"))\n+ open(self.THUMBNAIL_PATH.format(\"resource-grid\", \"resource-grid-paper_size-letter.png\"))\n+ open(self.THUMBNAIL_PATH.format(\"resource-arrows\", \"resource-arrows-paper_size-a4.png\"))\n+ open(self.THUMBNAIL_PATH.format(\"resource-arrows\", \"resource-arrows-paper_size-letter.png\"))\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Fix failing makeresourcethumbnail tests (previously failing silently)
|
701,855 |
22.11.2017 17:55:50
| -46,800 |
c59062e96ba50f02f2023dd7a62f7e15f6803f34
|
Modify deployment scripts to call ./csu update after ./csu start
|
[
{
"change_type": "MODIFY",
"old_path": "infrastructure/dev-deploy/deploy-resources-1.sh",
"new_path": "infrastructure/dev-deploy/deploy-resources-1.sh",
"diff": "# Deploy generated resource files to the development static file server.\n./csu start\n+./csu update\n# Generate static PDF resources for deployment.\ndocker-compose exec django /docker_venv/bin/python3 ./manage.py makeresources \"Arrows\"\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/dev-deploy/deploy-resources-2.sh",
"new_path": "infrastructure/dev-deploy/deploy-resources-2.sh",
"diff": "# Deploy generated resource files to the development static file server.\n./csu start\n+./csu update\n# Generate static PDF resources for deployment.\ndocker-compose exec django /docker_venv/bin/python3 ./manage.py makeresources \"Modulo Clock\"\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/dev-deploy/deploy-resources-3.sh",
"new_path": "infrastructure/dev-deploy/deploy-resources-3.sh",
"diff": "# Deploy generated resource files to the development static file server.\n./csu start\n+./csu update\n# Generate static PDF resources for deployment.\ndocker-compose exec django /docker_venv/bin/python3 ./manage.py makeresources \"Treasure Hunt\"\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/dev-deploy/deploy-static-files.sh",
"new_path": "infrastructure/dev-deploy/deploy-static-files.sh",
"diff": "# Deploy static files to the development static file server.\n./csu start\n+./csu update\n# Generate production static files\nrm -r build/\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/prod-deploy/deploy-resources-1.sh",
"new_path": "infrastructure/prod-deploy/deploy-resources-1.sh",
"diff": "# Deploy generated resource files to the development static file server.\n./csu start\n+./csu update\n# Generate static PDF resources for deployment.\ndocker-compose exec django /docker_venv/bin/python3 ./manage.py makeresources \"Arrows\"\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/prod-deploy/deploy-resources-2.sh",
"new_path": "infrastructure/prod-deploy/deploy-resources-2.sh",
"diff": "# Deploy generated resource files to the development static file server.\n./csu start\n+./csu update\n# Generate static PDF resources for deployment.\ndocker-compose exec django /docker_venv/bin/python3 ./manage.py makeresources \"Modulo Clock\"\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/prod-deploy/deploy-resources-3.sh",
"new_path": "infrastructure/prod-deploy/deploy-resources-3.sh",
"diff": "# Deploy generated resource files to the development static file server.\n./csu start\n+./csu update\n# Generate static PDF resources for deployment.\ndocker-compose exec django /docker_venv/bin/python3 ./manage.py makeresources \"Treasure Hunt\"\n"
},
{
"change_type": "MODIFY",
"old_path": "infrastructure/prod-deploy/deploy-static-files.sh",
"new_path": "infrastructure/prod-deploy/deploy-static-files.sh",
"diff": "# Deploy static files to the development static file server.\n./csu start\n+./csu update\n# Generate production static files\nrm -r build/\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Modify deployment scripts to call ./csu update after ./csu start
|
701,855 |
22.11.2017 18:12:41
| -46,800 |
72e8a3be78aee6be37266071aa32bb52dba8fdb2
|
Move static/collectstatic calls to specific ci commands
|
[
{
"change_type": "MODIFY",
"old_path": "csu",
"new_path": "csu",
"diff": "@@ -316,6 +316,8 @@ cmd_logs() {\ndefhelp logs 'View logs.'\nci_test_general() {\n+ dev_static\n+ dev_collect_static\ndocker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --exclude-tag=resource --exclude-tag=management --nomigrations\ntest_status=$?\ndev_test_coverage\n@@ -325,6 +327,8 @@ ci_test_general() {\n}\nci_test_resources() {\n+ dev_static\n+ dev_collect_static\ndocker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --tag=resource --nomigrations\ntest_status=$?\ndev_test_coverage\n@@ -334,6 +338,8 @@ ci_test_resources() {\n}\nci_test_management() {\n+ dev_static\n+ dev_collect_static\ndocker-compose exec django /docker_venv/bin/coverage run --rcfile=/cs-unplugged/.coveragerc ./manage.py test --settings=config.settings.testing --pattern \"test_*.py\" -v 3 --tag=management --nomigrations\ntest_status=$?\ndev_test_coverage\n@@ -347,6 +353,8 @@ ci_style() {\n}\nci_test_backwards() {\n+ dev_static\n+ dev_collect_static\ndev_test_backwards\n}\n@@ -360,8 +368,6 @@ ci_load_content() {\ncmd_ci() {\ncmd_start\n- dev_static\n- dev_collect_static\nlocal cmd=\"$1\"\nshift\nif [ -z \"$cmd\" ]; then\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Move static/collectstatic calls to specific ci commands
|
701,855 |
22.11.2017 18:21:14
| -46,800 |
498d0f1446fb98ba3ed406202857e896702f71dc
|
Fix typo in travis.yaml
|
[
{
"change_type": "MODIFY",
"old_path": ".travis.yml",
"new_path": ".travis.yml",
"diff": "@@ -16,7 +16,7 @@ jobs:\ninclude:\n- stage: test\nscript: ./csu ci load_content\n- script: ./csu ci test_general\n+ - script: ./csu ci test_general\n- script: ./csu ci test_resources\n- script: ./csu ci test_management\n- script: ./csu ci test_backwards\n"
}
] |
Python
|
MIT License
|
uccser/cs-unplugged
|
Fix typo in travis.yaml
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.