Skip to content

Commit 8351bf5

Browse files
committed
Merge branch 'main' into swfarnsworth/resources
2 parents 28fbcbf + 4c6993f commit 8351bf5

File tree

99 files changed

+2291
-547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2291
-547
lines changed

.github/ISSUE_TEMPLATE/resource_suggestion.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/PULL_REQUEST_TEMPLATE/pull_request.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,3 @@
1111
- [ ] Joined the [Python Discord community](discord.gg/python)
1212
- [ ] Read the [Code of Conduct](https://www.pydis.com/pages/code-of-conduct) and agree to it
1313
- [ ] I have discussed implementing this feature on the relevant service (Discord, GitHub, etc.)
14-
15-
16-
### I have changed API models and I ensure I have:
17-
<!-- Please remove this section if you haven't edited files under pydis_site/apps/api/models -->
18-
- [ ] Opened a PR updating the model on the [API GitHub Repository](https://github.com/python-discord/api)
19-
20-
**OR**
21-
22-
- [ ] Opened an issue on the [API GitHub Repository](https://github.com/python-discord/api) explaining what changes need to be made

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,6 @@ log.*
129129

130130
# Local Netlify folder
131131
.netlify
132+
133+
# Mac/OSX
134+
.DS_Store

pydis_site/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# `pydis_site` project directory
2+
3+
This directory hosts the root of our **Django project**[^1], and is responsible
4+
for all logic powering our website. Let's go over the directories in detail:
5+
6+
- [`apps`](./apps) contains our **Django apps**, which are the building blocks
7+
that make up our Django project. A Django project must always consist of one
8+
or more apps, and these apps can be made completely modular and reusable
9+
across any Django project. In our project, each app controls a distinct part
10+
of our website, such as the API or our resources system.
11+
12+
For more information on reusable apps, see the official Django tutorial,
13+
[which has a section on reusable
14+
apps](https://docs.djangoproject.com/en/dev/intro/reusable-apps/). To learn
15+
more about our specific apps, see the README inside the app folder itself.
16+
17+
- [`static`](./static) contains our **static files**, such as CSS, JavaScript,
18+
images, and anything else that isn't either content or Python code. Static
19+
files relevant for a specific application are put into subdirectories named
20+
after the application. For example, static files used by the `resources` app go in `static/resources`.
21+
22+
- [`templates`](./templates) contains our **[Django
23+
templates](https://docs.djangoproject.com/en/dev/topics/templates/)**. Like
24+
with static files, templates specific to a single application are stored in a
25+
subdirectory named after that application. We also have two special templates
26+
here:
27+
28+
- `404.html`, which is our error page shown when a site was not found.
29+
30+
- `500.html`, which is our error page shown in the astronomically rare case
31+
that we encounter an internal server error.
32+
33+
34+
Note that for both `static` and `templates`, we are not using the default Django
35+
directory structure which puts these directories in a directory per app (in our
36+
case, this would for example be ``pydis_site/apps/content/static/``).
37+
38+
We also have a few files in here that are relevant or useful in large parts of
39+
the website:
40+
41+
- [`context_processors.py`](./context_processors.py), which contains custom
42+
*context processors* that add variables to the Django template context. To
43+
read more, see the [`RequestContext` documentation from
44+
Django](https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.RequestContext)
45+
46+
- [`settings.py`](./settings.py), our Django settings file. This controls all
47+
manner of crucial things, for instance, we use it to configure logging, our
48+
connection to the database, which applications are run by the project, which
49+
middleware we are using, and variables for `django-simple-bulma` (which
50+
determines frontend colours & extensions for our pages).
51+
52+
- [`urls.py`](./urls.py), the URL configuration for the project itself. Here we
53+
can forward certain URL paths to our different apps, which have their own
54+
`urls.py` files to configure where their subpaths will lead. These files
55+
determine _which URLs will lead to which Django views_.
56+
57+
- [`wsgi.py`](./wsgi.py), which serves as an adapter for
58+
[`gunicorn`](https://github.com/benoitc/gunicorn),
59+
[`uwsgi`](https://github.com/unbit/uwsgi), or other application servers to run
60+
our application in production. Unless you want to test an interaction between
61+
our application and those servers, you probably won't need to touch this.
62+
63+
64+
For more information about contributing to our projects, please see our
65+
[Contributing
66+
page](https://www.pythondiscord.com/pages/guides/pydis-guides/contributing/).
67+
68+
[^1]: See [Django Glossary: project](https://docs.djangoproject.com/en/dev/glossary/#term-project)

pydis_site/apps/admin/__init__.py

Whitespace-only changes.

pydis_site/apps/admin/urls.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

pydis_site/apps/api/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# The "api" app
2+
3+
This application takes care of most of the heavy lifting in the site, that is,
4+
allowing our bot to manipulate and query information stored in the site's
5+
database.
6+
7+
We make heavy use of [Django REST
8+
Framework](https://www.django-rest-framework.org) here, which builds on top of
9+
Django to allow us to easily build out the
10+
[REST](https://en.wikipedia.org/wiki/Representational_state_transfer) API
11+
consumed by our bot. Working with the API app requires basic knowledge of DRF -
12+
the [quickstart
13+
guide](https://www.django-rest-framework.org/tutorial/quickstart/) is a great
14+
resource to get started.
15+
16+
## Directory structure
17+
18+
Let's look over each of the subdirectories here:
19+
20+
- `migrations` is the standard Django migrations folder. You usually won't need
21+
to edit this manually, as `python manage.py makemigrations` handles this for
22+
you in case you change our models. (Note that when generating migrations and
23+
Django doesn't generate a human-readable name for you, please supply one
24+
manually using `-n add_this_field`.)
25+
26+
- `models` contains our Django model definitions. We put models into subfolders
27+
relevant as to where they are used - in our case, the `bot` folder contains
28+
models used by our bot when working with the API. Each model is contained
29+
within its own module, such as `api/models/bot/message_deletion_context.py`,
30+
which contains the `MessageDeletionContext` model.
31+
32+
- `tests` contains tests for our API. If you're unfamilar with Django testing,
33+
the [Django tutorial introducing automated
34+
testing](https://docs.djangoproject.com/en/dev/intro/tutorial05/) is a great
35+
resource, and you can also check out code in there to see how we test it.
36+
37+
- `viewsets` contains our [DRF
38+
viewsets](https://www.django-rest-framework.org/api-guide/viewsets/), and is
39+
structured similarly to the `models` folder: The `bot` subfolder contains
40+
viewsets relevant to the Python Bot, and each viewset is contained within its
41+
own module.
42+
43+
The remaining modules mostly do what their name suggests:
44+
45+
- `admin.py`, which hooks up our models to the [Django admin
46+
site](https://docs.djangoproject.com/en/dev/ref/contrib/admin/).
47+
48+
- `apps.py` contains the Django [application
49+
config](https://docs.djangoproject.com/en/dev/ref/applications/) for the `api`
50+
app, and is used to run any code that should run when the app is loaded.
51+
52+
- `pagination.py` contains custom
53+
[paginators](https://www.django-rest-framework.org/api-guide/pagination/) used
54+
within our DRF viewsets.
55+
56+
- `serializers.py` contains [DRF
57+
serializers](https://www.django-rest-framework.org/api-guide/serializers/) for
58+
our models, and also includes validation logic for the models.
59+
60+
- `signals.py` contains [Django
61+
Signals](https://docs.djangoproject.com/en/dev/topics/signals/) for running
62+
custom functionality in response to events such as deletion of a model
63+
instance.
64+
65+
- `urls.py` configures Django's [URL
66+
dispatcher](https://docs.djangoproject.com/en/dev/topics/http/urls/) for our
67+
API endpoints.
68+
69+
- `views.py` is for any standard Django views that don't make sense to be put
70+
into DRF viewsets as they provide static data or other functionality that
71+
doesn't interact with our models.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generated by Django 3.1.14 on 2022-03-06 16:07
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
import pydis_site.apps.api.models.mixins
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('api', '0079_merge_20220125_2022'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='AocAccountLink',
17+
fields=[
18+
('user', models.OneToOneField(help_text='The user that is blocked from getting the AoC Completionist Role', on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='api.user')),
19+
('aoc_username', models.CharField(help_text='The AoC username associated with the Discord User.', max_length=120)),
20+
],
21+
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
22+
),
23+
migrations.CreateModel(
24+
name='AocCompletionistBlock',
25+
fields=[
26+
('user', models.OneToOneField(help_text='The user that is blocked from getting the AoC Completionist Role', on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='api.user')),
27+
('is_blocked', models.BooleanField(default=True, help_text='Whether this user is actively being blocked from getting the AoC Completionist Role', verbose_name='Blocked')),
28+
('reason', models.TextField(help_text='The reason for the AoC Completionist Role Block.', null=True)),
29+
],
30+
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
31+
),
32+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 3.1.14 on 2022-02-19 16:26
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
import pydis_site.apps.api.models.mixins
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('api', '0080_add_aoc_tables'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='BumpedThread',
17+
fields=[
18+
('thread_id', models.BigIntegerField(help_text='The thread ID that should be bumped.', primary_key=True, serialize=False, validators=[django.core.validators.MinValueValidator(limit_value=0, message='Thread IDs cannot be negative.')], verbose_name='Thread ID')),
19+
],
20+
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
21+
),
22+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.1.14 on 2022-04-21 23:29
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('api', '0081_bumpedthread'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='offtopicchannelname',
16+
name='name',
17+
field=models.CharField(help_text='The actual channel name that will be used on our Discord server.', max_length=96, primary_key=True, serialize=False, validators=[django.core.validators.RegexValidator(regex="^[a-z0-9\\U0001d5a0-\\U0001d5b9-ǃ?’'<>⧹⧸]+$")]),
18+
),
19+
]

0 commit comments

Comments
 (0)