Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8683949
Switch to poetry for dependency management.
j127 Apr 10, 2022
aeb1f2b
Update notes
j127 Apr 10, 2022
410e1eb
Update node version
j127 Apr 10, 2022
8115435
Switch to yarn and update all the packages.
j127 Apr 11, 2022
193bdd7
Add test script
j127 Apr 11, 2022
77741cb
Update README
j127 Apr 11, 2022
e76b8ea
Begin restructure
j127 Apr 11, 2022
f02e0b8
Start a users app
j127 Apr 11, 2022
293e973
Add the initial user model
j127 Apr 11, 2022
678197a
Update deps
j127 Apr 11, 2022
c557700
Add some needed dirs
j127 Apr 11, 2022
dc2ff60
More setup
j127 Apr 11, 2022
833c639
Update .env-example
j127 Apr 11, 2022
5e082a0
Add pages app
j127 Apr 11, 2022
c9e9064
Wire things up enough for it to run in the browser
j127 Apr 11, 2022
5d7e97f
Merge branch 'main' into django-4
j127 Apr 11, 2022
fc8d493
Format with black.
j127 Apr 11, 2022
59e8aad
Add note to helpers.py
j127 Apr 11, 2022
8a1ad99
Add skeletons for the 4 old Django apps
j127 Apr 11, 2022
e3764f8
Update the discourse app with the old code
j127 Apr 11, 2022
7002124
Add code for the `languages` app
j127 Apr 11, 2022
3b15d60
Update the `languages` fixtures to work with the new model.
j127 Apr 11, 2022
8457596
Update helper files
j127 Apr 11, 2022
48dc3f7
Get the puzzles app working
j127 Apr 11, 2022
e44ed92
Add the last of the app code from old version
j127 Apr 11, 2022
9c36ab1
Fix import
j127 Apr 11, 2022
04a230b
Work on frontend build
j127 Apr 11, 2022
9c24275
Rearrange the static files.
j127 Apr 11, 2022
586726b
Rearrange static assets
j127 Apr 11, 2022
c2a82b9
Add formatting command
j127 Apr 11, 2022
37a59a2
Move old CSS out of the way.
j127 Apr 11, 2022
b417a4a
Update helper files and README
j127 Apr 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{rb,ru,ex,exs,yml,yaml,cabal,purs,md,mdx}]
indent_size = 2

[Gemfile]
indent_size = 2

[Makefile]
indent_style = tab

[*.{yml,yaml}]
indent_size = 2
[*.go]
indent_style = tab
3 changes: 3 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# TODO: check the README.md file.
# For Django to work, I think this mainly needs SECRET_KEY, DATABASE_URL (postgres)

# Copy this file to `.env` and add your settings. Delete the DEBUG line in production.
DEBUG=True
NODE_ENV=development
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
deploy.sh
newrelic.ini
.parcel-cache/

# tmp files
TMP/
TANK/
NOTES_TMP.md
TMP_NOTES/
*_PENDING_DELETION
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
16
9 changes: 9 additions & 0 deletions .parcelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": [
"@parcel/config-default"
],
"reporters": [
"...",
"parcel-reporter-static-files-copy"
]
}
15 changes: 15 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
.github/
.cache/
.parcel-cache/
.mypy_cache/
.venv/
dist/
assets/dist/
TANK/
TMP_NOTES/
.env
node_modules/
.git/
tags
tags.*
dist/
build/
_site/
__pycache__/
.vim/
.vscode/
.idea/
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
"singleQuote": false,
"tabWidth": 4,
"trailingComma": "es5",
"arrowParens": "always"
"arrowParens": "always",
"overrides": [
{
"files": ["*.md", "*.mdx", "*.yaml", "*.yml"],
"options": {
"tabWidth": 2
}
}
]
}
8 changes: 0 additions & 8 deletions .vscode/settings.json

This file was deleted.

26 changes: 8 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
.PHONY: clean test start
.PHONY: clean format

help:
@echo "clean - remove junk files"
@echo "test - run pytest"
@echo "start - start gunicorn in production"
@echo "clean - remove junk files and caches"
@echo "format - format all the files"

clean:
rm -rf ./assets/dist/
rm -rf ./.mypy_cache/
rm -rf ./.parcel-cache/
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -rf {} +

# -n 3 means run in parallel on three cores
# -x means stop after first test fail
# --lf means run only the last failing test
# --ff means run the fail tests first
# pytest -n 3 --cov-config=.coveragerc -x --lf
test:
# Python tests
pytest -n 2 -x --lf
# Raku tests
cd apps/slack/command_parser/ && raku t/test-command-parser.t

start:
make clean
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program supervisord -c supervisord.conf
format:
yarn format
59 changes: 38 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,53 @@ Puzzle server.

### Python

Create a Python virtual environment:
The Python version is in the `pyproject.toml` file. You can use something like `pyenv` or Docker to manage multiple Python versions.

Use Poetry to manage dependencies and the virtual environment.

Examples:

Run a command in the virtualenv:

```text
$ python3 -m venv .venv
$ poetry run python manage.py runserver
```

Activate the virtual environment:
Install a package:

```text
$ source .venv/bin/activate
$ poetry add django
```

Install the dependencies into the virtual environment:
Install a dev dependency:

```text
$ pip install -r requirements/development.txt
$ poetry add -D pytest
```

Generate a secret key, and copy the example environment file for editing:
Enter a shell in the virtualenv:

```text
$ python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
$ cp .env-example .env
$ poetry shell
```

Open the .env file and add the secret key to the `DJANGO_SECRET_KEY` line, and fill in the `DATABASE_NAME` you want to use, and any database credentials needed.

When you are finished working on the site, you can deactivate the virtual environment with:
Generate a secret key, and copy the example environment file for editing:

```text
$ deactivate
$ poetry run python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
```

For convenience, you can add this to your `.zshenv`, `.bashrc`, or `.aliases` file:
Create the `.env` file if you don't have one:

```bash
alias m='python manage.py'
```text
$ cp .env-example .env
```

If you do that, wherever you see `python manage.py` in this document, you can type `m` instead.
Open the .env file and add the secret key to the `DJANGO_SECRET_KEY` line, and fill in the `DATABASE_NAME` you want to use, and any database credentials needed.

### Node.js

Make sure you're using Node 12, and then install the dependencies. The `nvm use` command will automatically switch to Node 12 by reading the `.nvmrc` file, if you installed Node with `nvm`.
Make sure you're using Node 16, and then install the dependencies. The `nvm use` command will automatically switch to Node 12 by reading the `.nvmrc` file, if you installed Node with `nvm`.

```text
$ nvm use
Expand All @@ -60,6 +63,8 @@ $ npm install

### Database

**NOTE:** this section might be outdated.

If you don't have Postgres installed on your computer, you can run it from within a Docker container. See the [README.md](./server_development/docker/README.md) file in the `./server_development/docker/` directory.

After Postgres is running, create a database using the name you chose in your `.env` file, then migrate the database:
Expand All @@ -70,7 +75,7 @@ $ python manage.py migrate

### Raku

[`TODO:` make sure this section of the setup instructions works. This first draft is written from memory.]
[`TODO:` remove Raku and rewrite the parser in Python.]

The slash-command parser is written in a language called [Raku](https://raku.guide/#_introduction). You can install Raku with [rakubrew](https://rakubrew.org/):

Expand All @@ -96,6 +101,8 @@ It uses pytest. There is an intro to pytest [here](https://djangostars.com/blog/

To run the tests, type:

**NOTE:** this section is probably outdated.

```text
$ make test
```
Expand All @@ -111,15 +118,15 @@ $ npm start
Run the backend server by typing this in another terminal:

```text
$ python manage.py runserver
$ poetry run python manage.py runserver
```

Then visit `localhost:8000`.

To create a user account, run this command:

```text
$ python manage.py createsuperuser
$ poetry run python manage.py createsuperuser
```

Then log in at `localhost:8000/admin/`.
Expand All @@ -135,3 +142,13 @@ If you're using VS Code and the formatting doesn't work automatically, try addin
If you're using VS Code, it should automatically give you formatting hints. If the Python linting rules are too strict, open a Github issue with the problem and we can modify the settings. (See the `tox.ini` file.)

If you use VS Code, you can also add [this extension](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig), and it will automatically follow this project's `.editorconfig` guidelines.

The Python code is formatted with Black.

```
$ poetry run black .
```

Or just run `make format` to format all the file types.

TODO: automate all the code formatting.
3 changes: 2 additions & 1 deletion apps/discourse/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@


class DiscourseConfig(AppConfig):
name = 'discourse'
default_auto_field = "django.db.models.BigAutoField"
name = "discourse"
22 changes: 11 additions & 11 deletions apps/discourse/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
DISCOURSE_PUZZLES_CATEGORY = os.getenv("DISCOURSE_PUZZLES_CATEGORY")
print("puzzles category", DISCOURSE_PUZZLES_CATEGORY)


def format_codewars_puzzle_message(puzzle):
"""This formats a codewars puzzle for Slack."""
print("helper got puzzle", puzzle)
Expand All @@ -18,10 +19,9 @@ def format_codewars_puzzle_message(puzzle):
lines = [
"Try solving this puzzle on codewars:\n",
f"*{puzzle['name']}* ({puzzle['kyu']} kyu)",
f"{puzzle['url']}"
"\n",
f"{puzzle['url']}" "\n",
f"> *available in:* {languages}",
f"> *category:* {puzzle['category']}"
f"> *category:* {puzzle['category']}",
]
return "\n".join(lines)

Expand All @@ -33,8 +33,10 @@ def format_codewars_puzzle_for_discourse(puzzle):
return None

title = f"Puzzle: {puzzle['name']} [{puzzle['category']}]"
languages = "{}, and {}".format(", ".join(puzzle["languages"][:-1]), puzzle["languages"][-1])
tags = ", ".join(puzzle['tags'])
languages = "{}, and {}".format(
", ".join(puzzle["languages"][:-1]), puzzle["languages"][-1]
)
tags = ", ".join(puzzle["tags"])

description = puzzle.get("description", None)
if description:
Expand Down Expand Up @@ -64,13 +66,11 @@ def format_codewars_puzzle_for_discourse(puzzle):
This puzzle was posted by a Slackbot via a slash command. If you want to help work on the app, send a message to @Josh.

If you don't want to see the coding puzzles when you visit the forum, you can go into [your settings](https://forum.codeselfstudy.com/my/preferences/categories) and mute the puzzles category.
""".split("\n")
""".split(
"\n"
)

cleaned_lines = [line.strip() for line in lines]
raw = "\n".join(cleaned_lines)

return {
"title": title,
"raw": raw,
"category": DISCOURSE_PUZZLES_CATEGORY
}
return {"title": title, "raw": raw, "category": DISCOURSE_PUZZLES_CATEGORY}
10 changes: 8 additions & 2 deletions apps/languages/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# TODO: This old code doesn't work, so it needs to be updated.

# SystemCheckError: System check identified some issues:
# ERRORS:
# <class 'languages.admin.LanguageAdmin'>: (admin.E035) The value of 'readonly_fields[0]' is not a callable, an attribute of 'LanguageAdmin', or an attribute of 'languages.Language'.
# <class 'languages.admin.LanguageAdmin'>: (admin.E035) The value of 'readonly_fields[1]' is not a callable, an attribute of 'LanguageAdmin', or an attribute of 'languages.Language'.

from django.contrib import admin

from .models import Language, LanguageVariantName
Expand All @@ -9,10 +16,9 @@ class LanguageVariantNameInline(admin.StackedInline):


class LanguageAdmin(admin.ModelAdmin):
readonly_fields = ("created_at", "updated_at")
fieldsets = [
(None, {"fields": ["name", "description"]}),
("Meta Data", {"fields": ["created_at", "updated_at"]}),
("Meta Data", {"fields": ["created", "updated"]}),
]
inlines = [LanguageVariantNameInline]
list_display = ("name", "variant_names")
Expand Down
3 changes: 2 additions & 1 deletion apps/languages/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@


class LanguagesConfig(AppConfig):
name = 'languages'
default_auto_field = "django.db.models.BigAutoField"
name = "languages"
Loading