From 96272cab8f52ce8f4fbc4506e1de5efb5e81ac01 Mon Sep 17 00:00:00 2001 From: etrotta Date: Sat, 15 Apr 2023 18:46:51 -0300 Subject: Add Python Graph Gallery to the Resources --- .../apps/resources/resources/python_graph_gallery.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pydis_site/apps/resources/resources/python_graph_gallery.yaml (limited to 'pydis_site') diff --git a/pydis_site/apps/resources/resources/python_graph_gallery.yaml b/pydis_site/apps/resources/resources/python_graph_gallery.yaml new file mode 100644 index 00000000..b8aaeb4d --- /dev/null +++ b/pydis_site/apps/resources/resources/python_graph_gallery.yaml @@ -0,0 +1,17 @@ +description: A collection of hundreds of charts made with Python with their associated reproducible code. +name: Python Graph Gallery +title_url: https://www.python-graph-gallery.com/ +urls: + - icon: branding/github + url: https://github.com/holtzy/The-Python-Graph-Gallery + color: black +tags: + topics: + - data science + payment_tiers: + - free + difficulty: + - beginner + - intermediate + type: + - tutorial -- cgit v1.2.3 From 762763cf00651526b798e70995eaf320d4275e97 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sun, 16 Apr 2023 01:00:32 +0200 Subject: Add a README to the staff app Plus minor refactorings --- pydis_site/apps/staff/README.md | 19 +++++++++++++++++++ .../apps/staff/templatetags/deletedmessage_filters.py | 2 +- pydis_site/apps/staff/urls.py | 2 +- pydis_site/apps/staff/views.py | 11 +++++++++++ pydis_site/apps/staff/viewsets/__init__.py | 3 --- pydis_site/apps/staff/viewsets/logs.py | 11 ----------- 6 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 pydis_site/apps/staff/README.md create mode 100644 pydis_site/apps/staff/views.py delete mode 100644 pydis_site/apps/staff/viewsets/__init__.py delete mode 100644 pydis_site/apps/staff/viewsets/logs.py (limited to 'pydis_site') diff --git a/pydis_site/apps/staff/README.md b/pydis_site/apps/staff/README.md new file mode 100644 index 00000000..db263e5e --- /dev/null +++ b/pydis_site/apps/staff/README.md @@ -0,0 +1,19 @@ +# The "staff" app + +This Django application hosts any staff-internal tooling, which, at time of +writing, only is an endpoint to view logs uploaded by the Python bot. + +This app mainly interacts with a single model from the `api` app, and has no +models on its own. The following files and directories are of interest: + +- [`templatetags`](./templatetags) contains custom template tags that help with + formatting the HTML templates of this app (these can be found in the template + root direcetory). + +- [`tests`](./tests) contains standard Django unit tests that validate both the + template tags and functionality of the log viewer itself. + +- [`urls.py`](./urls.py) contains the regular Django URL routing logic. + +- [`views.py`](./views.py) contains standard Django views. In our case, the + main work happens in the template, so this is relatively straightforward. diff --git a/pydis_site/apps/staff/templatetags/deletedmessage_filters.py b/pydis_site/apps/staff/templatetags/deletedmessage_filters.py index 5026068e..9d8f1819 100644 --- a/pydis_site/apps/staff/templatetags/deletedmessage_filters.py +++ b/pydis_site/apps/staff/templatetags/deletedmessage_filters.py @@ -28,5 +28,5 @@ def footer_datetime(timestamp: str) -> datetime: @register.filter def visible_newlines(text: str) -> str: - """Takes an embed timestamp and returns a timezone-aware datetime object.""" + """Visualizes newlines in text by replacing them with a grey-ish `↵`.""" return text.replace("\n", "
") diff --git a/pydis_site/apps/staff/urls.py b/pydis_site/apps/staff/urls.py index ca8d1a0f..0565592b 100644 --- a/pydis_site/apps/staff/urls.py +++ b/pydis_site/apps/staff/urls.py @@ -1,6 +1,6 @@ from django.urls import path -from .viewsets import LogView +from .views import LogView app_name = 'staff' urlpatterns = [ diff --git a/pydis_site/apps/staff/views.py b/pydis_site/apps/staff/views.py new file mode 100644 index 00000000..22dede95 --- /dev/null +++ b/pydis_site/apps/staff/views.py @@ -0,0 +1,11 @@ +from django.views.generic.detail import DetailView + +from pydis_site.apps.api.models.bot.message_deletion_context import MessageDeletionContext + + +class LogView(DetailView): + """The default view for the Deleted Messages logs.""" + + model = MessageDeletionContext + context_object_name = "deletion_context" + template_name = "staff/logs.html" diff --git a/pydis_site/apps/staff/viewsets/__init__.py b/pydis_site/apps/staff/viewsets/__init__.py deleted file mode 100644 index 6b10eb83..00000000 --- a/pydis_site/apps/staff/viewsets/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .logs import LogView - -__all__ = ["LogView"] diff --git a/pydis_site/apps/staff/viewsets/logs.py b/pydis_site/apps/staff/viewsets/logs.py deleted file mode 100644 index 22dede95..00000000 --- a/pydis_site/apps/staff/viewsets/logs.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.views.generic.detail import DetailView - -from pydis_site.apps.api.models.bot.message_deletion_context import MessageDeletionContext - - -class LogView(DetailView): - """The default view for the Deleted Messages logs.""" - - model = MessageDeletionContext - context_object_name = "deletion_context" - template_name = "staff/logs.html" -- cgit v1.2.3 From 6dcdcf519b8a178b4884797d85ad6b2e1b9582c3 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 16 Apr 2023 22:48:08 +0100 Subject: update rule 5 (#943) --- pydis_site/apps/api/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index 20431a61..54fbf809 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -149,9 +149,9 @@ class RulesView(APIView): ["english", "language"] ), ( - "Do not provide or request help on projects that may break laws, " - "breach terms of services, or are malicious or inappropriate.", - ["infraction", "tos", "breach", "malicious", "inappropriate"] + "Do not provide or request help on projects that may violate terms of service, " + "or that may be deemed inappropriate, malicious, or illegal.", + ["infraction", "tos", "breach", "malicious", "inappropriate", "illegal"] ), ( "Do not post unapproved advertising.", -- cgit v1.2.3 From ee04b387f47bd268894b8d0ef3920b4f9c4116e1 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Fri, 21 Apr 2023 00:29:51 +0200 Subject: Implement grammar fix Co-authored-by: wookie184 --- pydis_site/apps/staff/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/staff/README.md b/pydis_site/apps/staff/README.md index db263e5e..6707bf26 100644 --- a/pydis_site/apps/staff/README.md +++ b/pydis_site/apps/staff/README.md @@ -1,7 +1,7 @@ # The "staff" app This Django application hosts any staff-internal tooling, which, at time of -writing, only is an endpoint to view logs uploaded by the Python bot. +writing, is only an endpoint to view logs uploaded by the Python bot. This app mainly interacts with a single model from the `api` app, and has no models on its own. The following files and directories are of interest: -- cgit v1.2.3 From cbc67702bb58a3a2d3c80521f21e1fd6f7f203e9 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Fri, 21 Apr 2023 22:21:13 +0200 Subject: Crosscheck rules between API and static rules --- pydis_site/apps/api/tests/test_rules.py | 38 ++++++++++++++++++++++++++++++ pydis_site/apps/api/views.py | 2 +- pydis_site/apps/content/resources/rules.md | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/tests/test_rules.py b/pydis_site/apps/api/tests/test_rules.py index d08c5fae..3ee2d4e0 100644 --- a/pydis_site/apps/api/tests/test_rules.py +++ b/pydis_site/apps/api/tests/test_rules.py @@ -1,3 +1,7 @@ +import itertools +import re +from pathlib import Path + from django.urls import reverse from .base import AuthenticatedAPITestCase @@ -33,3 +37,37 @@ class RuleAPITests(AuthenticatedAPITestCase): url = reverse('api:rules') response = self.client.get(url + '?link_format=unknown') self.assertEqual(response.status_code, 400) + + +class RuleCorrectnessTests(AuthenticatedAPITestCase): + """Verifies that the rules from the API and by the static rules in the content app match.""" + + @classmethod + def setUpTestData(cls): + cls.markdown_rule_re = re.compile(r'^> \d+\. (.*)$') + + def test_rules_in_markdown_file_roughly_equal_api_rules(self) -> None: + url = reverse('api:rules') + api_response = self.client.get(url + '?link_format=md') + api_rules = tuple(rule for (rule, _tags) in api_response.json()) + + markdown_rules_path = ( + Path(__file__).parent.parent.parent / 'content' / 'resources' / 'rules.md' + ) + + markdown_rules = [] + for line in markdown_rules_path.read_text().splitlines(): + matches = self.markdown_rule_re.match(line) + if matches is not None: + markdown_rules.append(matches.group(1)) + + zipper = itertools.zip_longest(api_rules, markdown_rules) + for idx, (api_rule, markdown_rule) in enumerate(zipper): + with self.subTest(f"Rule {idx}"): + self.assertIsNotNone( + markdown_rule, f"The API has more rules than {markdown_rules_path}" + ) + self.assertIsNotNone( + api_rule, f"{markdown_rules_path} has more rules than the API endpoint" + ) + self.assertEqual(markdown_rule, api_rule) diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index 54fbf809..b1b7dc0f 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -120,7 +120,7 @@ class RulesView(APIView): link_format ) discord_tos = self._format_link( - 'Terms Of Service', + 'Terms of Service', 'https://discordapp.com/terms', link_format ) diff --git a/pydis_site/apps/content/resources/rules.md b/pydis_site/apps/content/resources/rules.md index a0bdb38d..e55c6715 100644 --- a/pydis_site/apps/content/resources/rules.md +++ b/pydis_site/apps/content/resources/rules.md @@ -5,7 +5,7 @@ icon: fab fa-discord --- We have a small but strict set of rules on our server. Please read over them and take them on board. If you don't understand a rule or need to report an incident, please send a direct message to @ModMail! -> 1. Follow the [Python Discord Code of Conduct](/pages/code-of-conduct/). +> 1. Follow the [Python Discord Code of Conduct](https://pythondiscord.com/pages/code-of-conduct/). > 2. Follow the [Discord Community Guidelines](https://discordapp.com/guidelines) and [Terms of Service](https://discordapp.com/terms). > 3. Respect staff members and listen to their instructions. > 4. Use English to the best of your ability. Be polite if someone speaks English imperfectly. -- cgit v1.2.3 From facb030041d916713c9fdacf18c57420d43bc433 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Fri, 14 Apr 2023 21:50:34 +0100 Subject: Seperate manual configuration out of the main bot contributing guide Also update the guide to be far simpler, and less words to read for our contributors to get setup. --- .../bot-extended-configuration-options.md | 192 +++++++++++ .../guides/pydis-guides/contributing/bot.md | 353 ++++----------------- 2 files changed, 257 insertions(+), 288 deletions(-) create mode 100644 pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot-extended-configuration-options.md (limited to 'pydis_site') diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot-extended-configuration-options.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot-extended-configuration-options.md new file mode 100644 index 00000000..b031a668 --- /dev/null +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot-extended-configuration-options.md @@ -0,0 +1,192 @@ +--- +title: Extended options for configuring Bot +description: A guide that lists all extended/optional options to configure the bot further. +icon: fab fa-github +toc: 3 +--- + +## Manual constants configuration + +Reading this means that you're ready for a bit of manual labour. +If for some reason you've missed the automatic server setup section, you can read about it in the bot contributing guide [here](../bot.md#envserver) + +To configure the bot manually, you will **only** need to set inside the `.env.server` file the values for the channels, roles, categories, etc. +that are used by the component you are developing. + +For example, if we're testing a feature that only needs the `announcements` channel: + +`constants.py` + +```py + +class EnvConfig: + # Defines from where & how Pydantic will be looking for env variables + ... + +class _Channels(EnvConfig): + + EnvConfig.Config.env_prefix = "channels_" + + announcements = 1079790565794779156 + changelog = 1077877318564991006 + +# Instantiate the class & load the configuration +Channels = _Channels() +``` + +`.env.server` file: + +```text +# .env.server + +channels_announcements=1077875228002234398 +``` + +When you launch your bot, `pydantic` will load up the server constants from the `.env.server` file if they exist. + +Each constants class will define its own prefix, which will make `pydantic` look for variables that will look like `{{env_prefix}}{{attribute_name}}` in the environment files + +In our example, this will imply that pydantic will look for both `channels_announcements` and `channels_changelog` in the `.env.server` file. + +As you can see here, only `channels_announcements` has been defined in the `.env.server` file since it's the only one needed, which will tell `pydantic` +to use the value **1077875228002234398** for the `announcements` attribute instead of the default **1079790565794779156**, and use the default value for the `changelog` attribute + +```python +>>> Channels.announcements +1077875228002234398 +>>> Channels.changelong +1077877318564991006 +``` + +See [here](../obtaining-discord-ids) for help with obtaining Discord IDs. + +If you wish to set all values in your `env.server` for your testing server, you need to set **all** the ones prefixed with: + +* `guild_` +* `categories_` +* `channels_` +* `roles_` +* `webhooks_` +* `emojis_` + +## Working with the help forum + +**Note**: This is only required when you're not configuring the bot [automatically](#automatic-configuration) + +If you will be working on a feature that includes the python help forum, you will need to use `Forum Channels`. + +Forum channels cannot be included in a template, which is why this needs to be done by hand for the time being. + +To activate forum channels, your Discord server needs to have the community feature. +If that's not the case already, here are the steps required to do it: + +1. Go to server settings +2. Scroll down to the `COMMUNITY` section and click on `Enable Community` +3. Click on `Get Started` and fill out the necessary info + +Once the previous steps are done, all that is left is to: + +1. Create a new channel +2. Choose the `Forum` type +3. [Copy its ID](../obtaining-discord-ids#channel-id) +4. Add the following line to the `.env.server` file: `channels_python_help={newly_created_forum_channel_id}` + +--- + +We understand this is tedious which is why we **heavily recommend** using the [automatic configuration setup](../bot.md#automatic-configuration) + +--- + +## Reloading parts of the bot +If you make changes to an extension, you might not need to restart the entire bot for the changes to take effect. The command `!ext reload ` re-imports the files associated with the extension. +Invoke `!ext list` for a full list of the available extensions. In this bot in particular, cogs are defined inside extensions. + +Note that if you changed code that is not associated with a particular extension, such as utilities, converters, and constants, you will need to restart the bot. + +## Adding new statistics + +Details on how to add new statistics can be found on the [statistic infrastructure page](https://blog.pythondiscord.com/statistics-infrastructure). +We are always open to more statistics so add as many as you can! + +--- + +## With the Bot Running Locally +The advantage of this method is that you can run the bot's code in your preferred editor, with debugger and all, while keeping all the setup of the bot's various dependencies inside Docker. + +* Append the following line to your `.env` file: `API_KEYS_SITE_API=badbot13m0n8f570f942013fc818f234916ca531`. +* In your `.env.server` file, set `urls_site_api="http://localhost:8000/api"`. If you wish to keep using `http://web:8000/api`, then [COMPOSE_PROJECT_NAME](../docker/#compose-project-names) has to be set. +* To work with snekbox, set `urls_snekbox_eval_api="http://localhost:8060/eval"` and `urls_snekbox_311_eval_api="http://localhost:8065/eval"` + + +You will need to start the services separately, but if you got the previous section with Docker working, that's pretty simple: + +* `docker compose up web` to start the site container. This is required. +* `docker compose up snekbox` to start the snekbox container. You only need this if you're planning on working on the snekbox cog. +* `docker compose up snekbox-311` to start the snekbox 3.11 container. You only need this if you're planning on working on the snekbox cog. +* `docker compose up redis` to start the Redis container. You only need this if you're not using fakeredis. For more info refer to [Working with Redis](#optional-working-with-redis). + +You can start several services together: `docker compose up web snekbox redis`. + +### Setting Up a Development Environment + +With at least the site running in Docker already (see the previous section on how to start services separately), you can now start the bot locally through the command line, or through your preferred IDE. +
+ + +
+
+ +### With More Things Running Locally +You can run additional services on the host, but this guide won't go over how to install and start them in this way. +If possible, prefer to start the services through Docker to replicate the production environment as much as possible. + +The site, however, is a mandatory service for the bot. +Refer to the [previous section](#with-the-bot-running-locally) and the [site contributing guide](../site) to learn how to start it on the host, in which case you will need to change `urls.site` in `.env.server` to wherever the site is being hosted. + +--- + +### Starting Redis Using Other Methods +You can run your own instance of Redis, but in that case you will need to correctly set `redis_host` and `redis_port` in your `.env.server` file and the `REDIS_PASSWORD` in the `.env` file. +**Note**: The previously mentioned variables **SHOULD NOT** be overriden or changed in `constants.py` + +--- + +## Working with Metricity +[Metricity](https://github.com/python-discord/metricity) is our home-grown bot for collecting metrics on activity within the server, such as what users are present, and IDs of the messages they've sent. +Certain features in the Python bot rely on querying the Metricity database for information such as the number of messages a user has sent, most notably the voice verification system. + +If you wish to work on a feature that relies on Metricity, for your convenience we've made the process of using it relatively painless with Docker: Enter the `.env` file you've written for the Python bot, and append the line `USE_METRICITY=true`. +Note that if you don't need Metricity, there's no reason to have it enabled as it is just unnecessary overhead. + +To make the Metricity bot work with your test server, you will need to override its configurations similarly to the Python bot. +You can see the various configurations in [the Metricity repo](https://github.com/python-discord/metricity), but the bare minimum is the guild ID setting. +In your local version of the Python bot repo, create a file called `metricity-config.toml` and insert the following lines: +```yaml +[bot] +guild_id = replace_with_your_guild_id +``` +To properly replicate production behavior, set the `staff_role_id`, `staff_categories`, and `ignore_categories` fields as well. + +Now, `docker compose up` will also start Metricity. + +If you want to run the bot locally, you can run `docker compose up metricity` instead. + +--- + +## Working with bot moderation logs +To be able to view moderation-related logs published by the bot to site, you will need to set `urls_site_logs_view=http://localhost:8000/staff/bot/logs` in your `.env.server`. +This will work in both Docker and locally. diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot.md index 769ea838..6639d92d 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot.md @@ -10,6 +10,35 @@ You should have already forked the repository and cloned it to your local machin This page will focus on the quickest steps one can take, with mentions of alternatives afterwards. --- +## Setting up the project + +### Setup Project Dependencies +Below are the dependencies you **must** have installed to get started with the bot. + +1. Make sure you have [Python 3.11](https://www.python.org/downloads/) installed. It helps if it is your system's default Python version. +1. [Install Poetry](https://github.com/python-poetry/poetry#installation). +1. [Install the project's dependencies](../installing-project-dependencies). +1. Docker. + +
+ + +
+
### Set Up a Test Server The Python bot is tightly coupled with the Python Discord server, so to have a functional version of the bot you need a server with channels it can use. @@ -37,137 +66,45 @@ If your bot fails to start with a `PrivilegedIntentsRequired` exception, this in --- ### Configure the Bot -You now have both the bot's code and a server to run it on. It's time for you to connect the two by changing the bot's configurations. -This can be done either automatically or manually, and we'll be detailing the steps for both. - -One thing to know is that the bot relies on precisely **two** configuration files to work. +You now have both the bot's code and a server to run it on. It's time for you to connect the two by setting the bot's configuration. +Both `.env` and `.env.server` files we talk about below are ignored by git, so they do not get accidentally commit to the repository. #### .env -This file will mostly contain sensitive information such as your `BOT_TOKEN` and your `REDIS_PASSWORD`. -It will also contain configurations related to external services the bot might use such as `USE_METRICITY`, which are unrelated to your server, with the only exception being `GUILD_ID`. +This file will contain sensitive information such as your bot's token, do not share it with anybody! -This file will **always** need to have `BOT_TOKEN` and `GUILD_ID` values set: +To start, create a `.env` file in the project root with the below content. ```text BOT_TOKEN=YourDiscordBotTokenHere GUILD_ID=YourDiscordTestServerIdHere +BOT_PREFIX=YourDesiredPrefixHere ``` See [here](../creating-bot-account) for help with obtaining the bot token, and [here](../obtaining-discord-ids#guild-id) for help with obtaining the guild's ID. +Other values will be added to your `.env` over time as you need to interact with other parts of the bot, but those are not needed for a basic setup. For a full list of support values see the ENV file option [appendix](#appendix-full-env-file-options) #### .env.server -All server configuration values are saved in this file, which needs to be at the root directory of the cloned code. -This file contains the various configurations we use to make the bot run on the Python Discord server, such as channel and role IDs, and the emojis it works with. -It also contains configurations such as how long it takes for a help channel to time out, and how many messages a user needs to voice-verify. - -This file will be created for you automatically if you decide to go with [automatic configuration](#automatic-configuration), -otherwise a lot of it has to be done by hand which will be detailed in the [manual configuration](#manual-configuration) section. - - -**Notes**: - -* Both `.env` and `.env.server` are and should remain ignored by git, otherwise you risk pushing sensitive information. -* Skip the following step if you would like to configure the bot manually, but that will require more work. - -#### Automatic configuration -To make setup much easier, the script in `botstrap.py` bootstraps the configuration for you and helps you get started immediately, -without having to spend much time copying IDs from your server into your configuration file. - -**Note**: The script will also work on existing servers as long as the channel names are the same as the one in Python Discord. +All server related configuration values are saved in this file, which also needs to be at the root directory of the project. -##### 1. Script setup -The bootstrapping script is a Python program so you will need a compatible Python version and the necessary dependencies installed, -which are all detailed here: +We provide a script to automatically generate a server config. +**Note**: The script **only** works with servers created with the template mentioned above. -1. Make sure you have [Python 3.11](https://www.python.org/downloads/) installed. It helps if it is your system's default Python version. -2. [Install Poetry](https://github.com/python-poetry/poetry#installation). -3. [Install the dependencies](../installing-project-dependencies). - -##### 2. Running the script +If you want to setup the bot from an existing guild read out [manual configuration guide](../bot-extended-configuration-options#manual-constants-configuration). This is far more complicated and time consuming. -Once the script setup phase is complete, all that is left is to run it. -To do this, you'll simply need to run the `configure` poetry task: +Running the below command will use the `BOT_TOKEN` and `GUILD_ID` from the `.env` file you created above to download all of the relevant IDs from the template guild into your `.env.server` +**Note**: This script will overwrite the `.env.server` file. We suggest you put any configuration not generated by this script in to `.env` instead ```shell $ poetry run task configure ``` -Once the script has finished running, you'll notice the creation of a new file called [`.env.server`](#envserver) at your project's root directory. +Once the script has finished running, you'll notice the creation of a new file called `.env.server` at your project's root directory. This file will contain the extracted IDs from your server which are necessary for your bot to run. **Congratulations**, you have finished the configuration and can now [run your bot](#run-it). -#### Manual configuration - -**Note**: Skip this part if you used the automatic configuration. - -Reading this means that you're ready for a bit of manual labour. -If for some reason you've missed the automatic server setup section, you can read about it [here](#automatic-configuration) - -To configure the bot manually, you will **only** need to set inside the `.env.server` file the values for the channels, roles, categories, etc. -that are used by the component you are developing. - -For example, if we're testing a feature that only needs the `announcements` channel: - -`constants.py` - -```py - -class EnvConfig: - # Defines from where & how Pydantic will be looking for env variables - ... - -class _Channels(EnvConfig): - - EnvConfig.Config.env_prefix = "channels_" - - announcements = 1079790565794779156 - changelog = 1077877318564991006 - -# Instantiate the class & load the configuration -Channels = _Channels() -``` - -`.env.server` file: - -```text -# .env.server - -channels_announcements=1077875228002234398 -``` - -When you launch your bot, `pydantic` will load up the server constants from the `.env.server` file if they exist. - -Each constants class will define its own prefix, which will make `pydantic` look for variables that will look like `{{env_prefix}}{{attribute_name}}` in the environment files - -In our example, this will imply that pydantic will look for both `channels_announcements` and `channels_changelog` in the `.env.server` file. - -As you can see here, only `channels_announcements` has been defined in the `.env.server` file since it's the only one needed, which will tell `pydantic` -to use the value **1077875228002234398** for the `announcements` attribute instead of the default **1079790565794779156**, and use the default value for the `changelog` attribute - -```python ->>> Channels.announcements -1077875228002234398 ->>> Channels.changelong -1077877318564991006 -``` - -See [here](../obtaining-discord-ids) for help with obtaining Discord IDs. - -If you wish to set all values in your `env.server` for your testing server, you need to set **all** the ones prefixed with: - -* `guild_` -* `categories_` -* `channels_` -* `roles_` -* `webhooks_` -* `emojis_` - - -We understand this is tedious which is why we **heavily recommend** using the [automatic configuration setup](#automatic-configuration) -
- -
-
- -In your `.env.server` file: - -* If you wish to work with snekbox, set the following: - * `urls_snekbox_eval_api` to `"http://snekbox:8060/eval"` - * `urls_snekbox_311_eval_api` to `"http://snekbox-311:8060/eval"`. - -* At this stage, set `redis_use_fakeredis` to `true`. If you're looking for instructions for working with Redis, see [Working with Redis](#optional-working-with-redis). - - -Assuming you have Docker installed **and running**, enter the cloned repo in the command line and type `docker compose up`. - -If working with snekbox you can run `docker compose --profile 3.10 up` to also start up a 3.10 snekbox container, in addition to the default 3.11 container! - -After pulling the images and building the containers, your bot will start. Enter your server and type `!help` (or whatever prefix you [chose](#optional--changing-your-command-prefix) instead of `!`). - -Your bot is now running, but this method makes debugging with an IDE a fairly involved process. For additional running methods, continue reading the following sections. -#### With the Bot Running Locally -The advantage of this method is that you can run the bot's code in your preferred editor, with debugger and all, while keeping all the setup of the bot's various dependencies inside Docker. +With all of the above setup, you can run The projec with `docker compose up`. This will start the bot an all required services! Enter your server and type `!help` (or whatever prefix you chose instead of `!`) to see the bot in action! -* Append the following line to your `.env` file: `API_KEYS_SITE_API=badbot13m0n8f570f942013fc818f234916ca531`. -* In your `.env.server` file, set `urls_site_api="http://localhost:8000/api"`. If you wish to keep using `http://web:8000/api`, then [COMPOSE_PROJECT_NAME](../docker/#compose-project-names) has to be set. -* To work with snekbox, set `urls_snekbox_eval_api="http://localhost:8060/eval"` and `urls_snekbox_311_eval_api="http://localhost:8065/eval"` +Some other useful docker commands are as follows: +1. `docker compose pull` this pulls updates for all non-bot services, such as psotgres, redis and our [site](../site) project! +1. `docker compose build` this rebuilds the bot's docker image, this is only needed if you need to make changes to the bot's dependencies, or the Dockerfile itself. +1. `docker compose --profile 3.10 up` this starts a 3.10 snekbox container, in addition to the default 3.11 container! -You will need to start the services separately, but if you got the previous section with Docker working, that's pretty simple: - -* `docker compose up web` to start the site container. This is required. -* `docker compose up snekbox` to start the snekbox container. You only need this if you're planning on working on the snekbox cog. -* `docker compose up snekbox-311` to start the snekbox 3.11 container. You only need this if you're planning on working on the snekbox cog. -* `docker compose up redis` to start the Redis container. You only need this if you're not using fakeredis. For more info refer to [Working with Redis](#optional-working-with-redis). - -You can start several services together: `docker compose up web snekbox redis`. - -##### Setting Up a Development Environment -The bot's code is Python code like any other. To run it locally, you will need the right version of Python with the necessary packages installed: - -1. Make sure you have [Python 3.11](https://www.python.org/downloads/) installed. It helps if it is your system's default Python version. -2. [Install Poetry](https://github.com/python-poetry/poetry#installation). -3. [Install the dependencies](../installing-project-dependencies). - -With at least the site running in Docker already (see the previous section on how to start services separately), you can now start the bot locally through the command line, or through your preferred IDE. -
- - -
-
- -#### With More Things Running Locally -You can run additional services on the host, but this guide won't go over how to install and start them in this way. -If possible, prefer to start the services through Docker to replicate the production environment as much as possible. +Your bot is now running, all inside Docker. -The site, however, is a mandatory service for the bot. -Refer to the [previous section](#with-the-bot-running-locally) and the [site contributing guide](../site) to learn how to start it on the host, in which case you will need to change `urls.site` in `.env.server` to wherever the site is being hosted. +**Note**: If you want to read about how to make debugging with an IDE a easier, or for additional running methods, check out our [extended configuration guide](../bot-extended-configuration-options). --- -### Development Tips + +## Development Tips Now that you have everything setup, it is finally time to make changes to the bot! -#### Working with Git +### Working with Git Version control of our projects is done using Git and Github. It can be intimidating at first, so feel free to ask for any help in the server. [**Click here to see the basic Git workflow when contributing to one of our projects.**](../working-with-git/) -#### Running tests +### Running tests [This section](https://github.com/python-discord/bot/blob/main/tests/README.md#tools) of the README in the `tests` repository will explain how to run tests. The whole document explains how unittesting works, and how it fits in the context of our project. Make sure to run tests *before* pushing code. -Even if you run the bot through Docker, you might want to [setup a development environment](#setting-up-a-development-environment) in order to run the tests locally. +Even if you run the bot through Docker, you might want to [setup a development environment](../bot-extended-configuration-options#setting-up-a-development-environment) in order to run the tests locally. -#### Lint before you push +### Lint before you push As mentioned in the [contributing guidelines](../contributing-guidelines), you should make sure your code passes linting for each commit you make. For ease of development, you can install the pre-commit hook with `poetry run task precommit`, which will check your code every time you try to commit it. -For that purpose, even if you run the bot through Docker, you might want to [setup a development environment](#setting-up-a-development-environment), as otherwise the hook installation will fail. - -#### Reloading parts of the bot -If you make changes to an extension, you might not need to restart the entire bot for the changes to take effect. The command `!ext reload ` re-imports the files associated with the extension. -Invoke `!ext list` for a full list of the available extensions. In this bot in particular, cogs are defined inside extensions. - -Note that if you changed code that is not associated with a particular extension, such as utilities, converters, and constants, you will need to restart the bot. - -#### Adding new statistics - -Details on how to add new statistics can be found on the [statistic infrastructure page](https://blog.pythondiscord.com/statistics-infrastructure). -We are always open to more statistics so add as many as you can! - ---- - -### Optional: Working with the help forum - -**Note**: This is only required when you're not configuring the bot [automatically](#automatic-configuration) +For that purpose, even if you run the bot through Docker, you might want to [setup a development environment](../bot-extended-configuration-options#setting-up-a-development-environment), as otherwise the hook installation will fail. -If you will be working on a feature that includes the python help forum, you will need to use `Forum Channels`. - -Forum channels cannot be included in a template, which is why this needs to be done by hand for the time being. - -To activate forum channels, your Discord server needs to have the community feature. -If that's not the case already, here are the steps required to do it: -1. Go to server settings -2. Scroll down to the `COMMUNITY` section and click on `Enable Community` -3. Click on `Get Started` and fill out the necessary info - -Once the previous steps are done, all that is left is to: -1. Create a new channel -2. Choose the `Forum` type -3. [Copy its ID](../obtaining-discord-ids#channel-id) -4. Add the following line to the `.env.server` file: `channels_python_help={newly_created_forum_channel_id}` - ---- - -### Optional: Working with Redis -In [Configure the Bot](#envserver) you were asked to set `redis_use_fakeredis=true`. If you do not need to work on features that rely on Redis, this is enough. Fakeredis will give the illusion that features relying on Redis are saving information properly, but restarting the bot or the specific cog will wipe that information. - -If you are working on a feature that relies on Redis, you will need to enable Redis to make sure persistency is achieved for the feature across restarts. The first step towards that is going to `.env.server` and setting `redis.use_fakeredis` to `false`. - -#### Starting Redis in Docker (Recommended) -If you're using the Docker image provided in the project's Docker Compose, open your `.env.server` file. If you're running the bot in Docker, set `redis_host=redis`, and if you're running it on the host set it to `localhost`. Set `redis_password=""`. - -#### Starting Redis Using Other Methods -You can run your own instance of Redis, but in that case you will need to correctly set `redis_host` and `redis_port` in your `.env.server` file and the `REDIS_PASSWORD` in the `.env` file. -**Note**: The previously mentioned variables **SHOULD NOT** be overriden or changed in `constants.py` - ---- - -### Optional: Working with Metricity -[Metricity](https://github.com/python-discord/metricity) is our home-grown bot for collecting metrics on activity within the server, such as what users are present, and IDs of the messages they've sent. -Certain features in the Python bot rely on querying the Metricity database for information such as the number of messages a user has sent, most notably the voice verification system. - -If you wish to work on a feature that relies on Metricity, for your convenience we've made the process of using it relatively painless with Docker: Enter the `.env` file you've written for the Python bot, and append the line `USE_METRICITY=true`. -Note that if you don't need Metricity, there's no reason to have it enabled as it is just unnecessary overhead. - -To make the Metricity bot work with your test server, you will need to override its configurations similarly to the Python bot. -You can see the various configurations in [the Metricity repo](https://github.com/python-discord/metricity), but the bare minimum is the guild ID setting. -In your local version of the Python bot repo, create a file called `metricity-config.toml` and insert the following lines: -```yaml -[bot] -guild_id = replace_with_your_guild_id -``` -To properly replicate production behavior, set the `staff_role_id`, `staff_categories`, and `ignore_categories` fields as well. - -Now, `docker compose up` will also start Metricity. - -If you want to run the bot locally, you can run `docker compose up metricity` instead. - ---- - -### Optional: Working with bot moderation logs -To be able to view moderation-related logs published by the bot to site, you will need to set `urls_site_logs_view=http://localhost:8000/staff/bot/logs` in your `.env.server`. -This will work in both Docker and locally. - ---- +### Issues? +If you have any issues with setting up the bot, come discuss it with us on the [#dev-contrib](https://discord.gg/2h3qBv8Xaa) channel on our server. -### Optional: Changing your command prefix -If you would like a prefix other than the default `!`, set `BOT_PREFIX={{your_prefix}}` in `.env.server`. +If you find any bugs in the bot or would like to request a feature, feel free to [open an issue](https://github.com/python-discord/bot/issues/new/choose) on the repository. --- -### Issues? -If you have any issues with setting up the bot, come discuss it with us on the [#dev-contrib](https://discord.gg/2h3qBv8Xaa) channel on our server. +# Next steps +Now that you have everything setup, it is finally time to make changes to the bot! If you have not yet read the [contributing guidelines](../contributing-guidelines.md), now is a good time. Contributions that do not adhere to the guidelines may be rejected. -If you find any bugs in the bot or would like to request a feature, feel free to [open an issue](https://github.com/python-discord/bot/issues/new/choose) on the repository. +Have fun! --- -### Appendix: Full ENV File Options +# Appendix: Full ENV File Options The following is a list of all available environment variables used by the bot: | Variable | Required | Description | @@ -407,17 +193,8 @@ The following is a list of all available environment variables used by the bot: | `BOT_SENTRY_DSN` | When connecting the bot to sentry | The DSN of the sentry monitor. | | `BOT_TRACE_LOGGERS ` | When you wish to see specific or all trace logs | Comma separated list that specifies which loggers emit trace logs through the listed names. If the ! prefix is used, all of the loggers except the listed ones are set to the trace level. If * is used, the root logger is set to the trace level. | | `DEBUG` | In production | `true` or `false`, depending on whether to enable debug mode, affecting the behavior of certain features. `true` by default. | -| `REDIS_PASSWORD` | When not using FakeRedis | The password to connect to the Redis database (see [Optional: Working with Redis](#optional-working-with-redis)). | -| `USE_METRICITY` | When using Metricity | `true` or `false`, depending on whether to enable metrics collection using Metricity (see [Optional: Working with Metricity](#optional-working-with-metricity)). `false` by default. | +| `REDIS_PASSWORD` | When not using FakeRedis | The password to connect to the Redis database (see [Staring Redis with other methods](../bot-extended-configuration-options#starting-redis-using-other-methods)). | +| `USE_METRICITY` | When using Metricity | `true` or `false`, depending on whether to enable metrics collection using Metricity (see [Working with Metricity](../bot-extended-configuration-options#working-with-metricity)). `false` by default. | | `API_KEYS_GITHUB` | When you wish to interact with GitHub | The API key to interact with GitHub, for example to download files for the branding manager. | | `METABASE_USERNAME` | When you wish to interact with Metabase | The username for a Metabase admin account. | | `METABASE_PASSWORD` | When you wish to interact with Metabase | The password for a Metabase admin account. | - ---- - -# Next steps -Now that you have everything setup, it is finally time to make changes to the bot! If you have not yet read the [contributing guidelines](../contributing-guidelines.md), now is a good time. Contributions that do not adhere to the guidelines may be rejected. - -If you're not sure where to go from here, our [detailed walkthrough](../#2-set-up-the-project) is for you. - -Have fun! -- cgit v1.2.3 From aa303ed0776c8deab31890830934a8b0ef833f65 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sat, 22 Apr 2023 14:55:40 +0200 Subject: Make unittests independent of GitHub (#948) This fixes a problem where running the unit tests successively a lot would result in 403 ratelimit exceeded errors being thrown due to the GitHub API being called by the app. Fixes #918 Co-authored-by: wookie184 --- .coveragerc | 2 ++ pydis_site/apps/content/tests/test_views.py | 5 +++-- pydis_site/apps/home/tests/test_views.py | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'pydis_site') diff --git a/.coveragerc b/.coveragerc index 38926b22..b41a2140 100644 --- a/.coveragerc +++ b/.coveragerc @@ -11,6 +11,8 @@ omit = */apps.py */urls.py pydis_site/apps/api/models/bot/metricity.py + # GitHub API functions are mocked away + pydis_site/apps/content/utils.py pydis_site/wsgi.py pydis_site/settings.py pydis_site/utils/resources.py diff --git a/pydis_site/apps/content/tests/test_views.py b/pydis_site/apps/content/tests/test_views.py index 3ef9bcc4..e4f898ef 100644 --- a/pydis_site/apps/content/tests/test_views.py +++ b/pydis_site/apps/content/tests/test_views.py @@ -1,6 +1,6 @@ import textwrap from pathlib import Path -from unittest import TestCase +from unittest import TestCase, mock import django.test import markdown @@ -223,7 +223,8 @@ class TagViewTests(django.test.TestCase): def test_invalid_tag_404(self): """Test that a tag which doesn't exist raises a 404.""" - response = self.client.get("/pages/tags/non-existent/") + with mock.patch("pydis_site.apps.content.utils.fetch_tags", autospec=True): + response = self.client.get("/pages/tags/non-existent/") self.assertEqual(404, response.status_code) def test_context_tag(self): diff --git a/pydis_site/apps/home/tests/test_views.py b/pydis_site/apps/home/tests/test_views.py index b1215df4..379b984e 100644 --- a/pydis_site/apps/home/tests/test_views.py +++ b/pydis_site/apps/home/tests/test_views.py @@ -1,3 +1,5 @@ +from unittest import mock + from django.test import TestCase from django.urls import reverse @@ -6,5 +8,6 @@ class TestIndexReturns200(TestCase): def test_index_returns_200(self): """Check that the index page returns a HTTP 200 response.""" url = reverse('home:home') - resp = self.client.get(url) + with mock.patch("pydis_site.apps.home.views.HomeView._get_api_data", autospec=True): + resp = self.client.get(url) self.assertEqual(resp.status_code, 200) -- cgit v1.2.3 From 7099b1fdd6a16c32204dd8c8e4879a9fd9f19614 Mon Sep 17 00:00:00 2001 From: r4ge <71139938+r4gesingh47@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:28:03 +0530 Subject: Update Code Jam 2022 & Events homepage (#952) * Update Code Jam 2022 and events homepage to show that it has ended. * Remove strike through for important dates in CJ. --- .../templates/events/pages/code-jams/9/_index.html | 55 ++++- .../events/pages/code-jams/9/submissions.html | 232 +++++++++++++++++++++ 2 files changed, 280 insertions(+), 7 deletions(-) create mode 100644 pydis_site/templates/events/pages/code-jams/9/submissions.html (limited to 'pydis_site') diff --git a/pydis_site/templates/events/pages/code-jams/9/_index.html b/pydis_site/templates/events/pages/code-jams/9/_index.html index ca7c4f90..3e60c387 100644 --- a/pydis_site/templates/events/pages/code-jams/9/_index.html +++ b/pydis_site/templates/events/pages/code-jams/9/_index.html @@ -20,15 +20,56 @@ and walking through the program that your team has created. More details and specifics of this will be released within the next 2 weeks.

+

Code Jam Winners

+

Congratulations to our winners and the two runner ups! Check out their projects below.

+ +

Cerebral Centaurs: Drawn

+

Palmirka, Tu®tle, collerek, Rortox

+

+ Drawn is based on old school Pictionary game, with additional surprises waiting for the drawer each turn. +

+

+ GitHub Repository +
+ +

+ +

Kingly Kelpies: for level_id in range(14)

+

Kingu, Falkan, Bamboodja, Redriel, Vinyzu

+

+ A simple multiplayer puzzle game, in which your aim is to reach the goal by pressing buttons, standing on plates and moving boxes. +

+

+ Demo video +
+ GitHub Repository +
+

+ +

Logical Leprechauns: Curse of the Mites

+

Fyx, Aboo Minister, A5rocks, Bautista, ~tylerr

+

+ Curse of the Mites is a text based MUD (multi-user dungeon) in which you play as a caterpillar whose goal is to grow into a butterfly to escape the forest cursed by mites. +

+ GitHub Repository +
+

+ +

Submissions

+

+ By the end of the jam, 20+ teams made project submissions. Check them all out here: +

+

+

Important Dates

    -
  • Saturday, June 18 - Form to submit theme suggestions opens
  • -
  • Wednesday, June 29 - The Qualifier is released
  • -
  • Wednesday, July 6 - Voting for the theme opens
  • -
  • Wednesday, July 13 - The Qualifier closes
  • -
  • Thursday, July 21 - Code Jam Begins
  • -
  • Sunday, July 31 - Coding portion of the jam ends
  • -
  • Sunday, August 4 - Code Jam submissions are closed
  • +
  • Saturday, June 18 - Form to submit theme suggestions opens
  • +
  • Wednesday, June 29 - The Qualifier is released
  • +
  • Wednesday, July 6 - Voting for the theme opens
  • +
  • Wednesday, July 13 - The Qualifier closes
  • +
  • Thursday, July 21 - Code Jam Begins
  • +
  • Sunday, July 31 - Coding portion of the jam ends
  • +
  • Sunday, August 4 - Code Jam submissions are closed

The Qualifier

diff --git a/pydis_site/templates/events/pages/code-jams/9/submissions.html b/pydis_site/templates/events/pages/code-jams/9/submissions.html new file mode 100644 index 00000000..e0139ce8 --- /dev/null +++ b/pydis_site/templates/events/pages/code-jams/9/submissions.html @@ -0,0 +1,232 @@ +{% extends "events/base_sidebar.html" %} + +{% load static %} + +{% block title %}Summer Code Jam 2022{% endblock %} + +{% block breadcrumb %} +
  • Events
  • +
  • Code Jams
  • +
  • Summer Code Jam 2022
  • +
  • Submissions
  • +{% endblock %} + +{% block event_content %} +

    + Below is a list of all projects submitted by the end of Summer Code Jam 2022 +

    + +
    +
    +

    Artful Angels

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Burly Barghests

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Cerebral Centaurs

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Dynamic Dryads

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Generous Giants

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Genuine Djinn

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Gorgeous Ghouls

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Heroic Hydra

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Kindly Kappa

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Kingly Kelpies

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Logical Leprechauns

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Lucky Leucrota

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Muscular Mermaids

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Old-Fashioned Orcs

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Sassy Snallygasters

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Silly Selkies

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Spiffy Sphinxes

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Stately Satyrs

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Tireless Timingila

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Towering Tupilaqs

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Valiant Valkyries

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Wily Werewolves

    +
    +
    +

    GitHub

    +
    +
    + +
    +
    +

    Zesty Zombies

    +
    +
    +

    GitHub

    +
    +
    + +{% endblock %} + +{% block sidebar %} + + {% include "events/sidebar/code-jams/9.html" %} + +{% endblock %} -- cgit v1.2.3 From b4e843ebc1fa35c457e59bfff252b252ef2ef77f Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Fri, 19 Nov 2021 10:11:18 +0800 Subject: feat: Edit on GitHub button for content articles - Using `if pages` to check whether the page is an article or category doesn't work for /pages/guides - I still need to modify the styling and position of the button a bit - Should probably just use a static method and put src_url as context instead of having a template tag --- pydis_site/apps/content/templatetags/__init__.py | 0 pydis_site/apps/content/templatetags/page_src.py | 22 ++++++++++++++++++++++ pydis_site/templates/content/base.html | 1 + 3 files changed, 23 insertions(+) create mode 100644 pydis_site/apps/content/templatetags/__init__.py create mode 100644 pydis_site/apps/content/templatetags/page_src.py (limited to 'pydis_site') diff --git a/pydis_site/apps/content/templatetags/__init__.py b/pydis_site/apps/content/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pydis_site/apps/content/templatetags/page_src.py b/pydis_site/apps/content/templatetags/page_src.py new file mode 100644 index 00000000..33f24b82 --- /dev/null +++ b/pydis_site/apps/content/templatetags/page_src.py @@ -0,0 +1,22 @@ +from django import template + + +register = template.Library() + + +@register.filter() +def page_src_url(request_path: str) -> str: + """ + Return the corresponding GitHub source URL for the current content article. + + request_path is the relative path of an article, as returned by `request.path` in templates. + + For example: /pages/rules/ would return: + https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources/rules.md + """ + src_url = request_path.replace( + "/pages/", + "https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources/", + ) + src_url = src_url[:-1] + ".md" + return src_url diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html index 2fd721a3..8f6fd1d8 100644 --- a/pydis_site/templates/content/base.html +++ b/pydis_site/templates/content/base.html @@ -1,5 +1,6 @@ {% extends 'base/base.html' %} {% load static %} +{% load page_src %} {% block title %}{{ page_title }}{% endblock %} {% block head %} -- cgit v1.2.3 From 1bed1356ab5f58af282315fa059d634766e3592e Mon Sep 17 00:00:00 2001 From: hedy Date: Fri, 28 Oct 2022 21:27:17 +0800 Subject: Edit on GitHub link instead of button - Before the title - Aligned left - more mobile-friendly - Simpler page structure - I personally don't think it makes sense for a simple link to a page's source be a button. Plus, it's similar to the style of other docs like VS Code --- pydis_site/templates/content/base.html | 1 - pydis_site/templates/content/page.html | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'pydis_site') diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html index 8f6fd1d8..2fd721a3 100644 --- a/pydis_site/templates/content/base.html +++ b/pydis_site/templates/content/base.html @@ -1,6 +1,5 @@ {% extends 'base/base.html' %} {% load static %} -{% load page_src %} {% block title %}{{ page_title }}{% endblock %} {% block head %} diff --git a/pydis_site/templates/content/page.html b/pydis_site/templates/content/page.html index 679ecec6..57677243 100644 --- a/pydis_site/templates/content/page.html +++ b/pydis_site/templates/content/page.html @@ -1,6 +1,12 @@ {% extends 'content/base.html' %} +{% load page_src %} {% block page_content %} +

    + + Edit on GitHub +

    +

    {{ page_title }}

    {% if relevant_links or toc %}
    -- cgit v1.2.3 From a34ebfa67838acac9f2651d7eba7a7472a4bd4ec Mon Sep 17 00:00:00 2001 From: hedy Date: Sat, 29 Oct 2022 10:37:45 +0800 Subject: Use content articles source url in django.conf.settings --- pydis_site/apps/content/templatetags/page_src.py | 3 ++- pydis_site/settings.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/content/templatetags/page_src.py b/pydis_site/apps/content/templatetags/page_src.py index 33f24b82..3a8f1e8b 100644 --- a/pydis_site/apps/content/templatetags/page_src.py +++ b/pydis_site/apps/content/templatetags/page_src.py @@ -1,4 +1,5 @@ from django import template +from django.conf import settings register = template.Library() @@ -16,7 +17,7 @@ def page_src_url(request_path: str) -> str: """ src_url = request_path.replace( "/pages/", - "https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources/", + settings.CONTENT_SRC_URL, ) src_url = src_url[:-1] + ".md" return src_url diff --git a/pydis_site/settings.py b/pydis_site/settings.py index e9e0ba67..9da9a156 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -332,3 +332,8 @@ REDIRECTIONS_PATH = Path(BASE_DIR, "pydis_site", "apps", "redirect", "redirects. # How long to wait for synchronous requests before timing out TIMEOUT_PERIOD = env("TIMEOUT_PERIOD") + +# Source files url for 'Edit on GitHub' link on content articles +CONTENT_SRC_URL = ( + "https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources/" +) -- cgit v1.2.3 From 7bf2766bd2468766497b5ec35657856815f8bb34 Mon Sep 17 00:00:00 2001 From: hedy Date: Sat, 29 Oct 2022 10:38:47 +0800 Subject: Put 'Edit on GitHub' on breadcrum row with Sub-Articles dropdown --- pydis_site/static/css/content/page.css | 4 ++++ pydis_site/templates/content/base.html | 12 ++++++++++++ pydis_site/templates/content/dropdown.html | 2 +- pydis_site/templates/content/page.html | 6 ------ 4 files changed, 17 insertions(+), 7 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/static/css/content/page.css b/pydis_site/static/css/content/page.css index d831f86d..73e833a8 100644 --- a/pydis_site/static/css/content/page.css +++ b/pydis_site/static/css/content/page.css @@ -2,6 +2,10 @@ padding: 1rem; } +#edit-on-github { + margin-left: 1rem; +} + i.has-icon-padding { padding: 0 10px 25px 0; } diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html index 2fd721a3..caa08819 100644 --- a/pydis_site/templates/content/base.html +++ b/pydis_site/templates/content/base.html @@ -1,5 +1,6 @@ {% extends 'base/base.html' %} {% load static %} +{% load page_src %} {% block title %}{{ page_title }}{% endblock %} {% block head %} @@ -29,10 +30,21 @@
  • {{ page_title }}
  • +
    {# Sub-Article dropdown for category pages #} {% if subarticles %} {% include "content/dropdown.html" %} {% endif %} + {# Edit on GitHub for content articles #} + {% if page %} + + {% endif %} +
    diff --git a/pydis_site/templates/content/dropdown.html b/pydis_site/templates/content/dropdown.html index 13c89c68..60560547 100644 --- a/pydis_site/templates/content/dropdown.html +++ b/pydis_site/templates/content/dropdown.html @@ -1,4 +1,4 @@ -