aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2019-07-21 10:00:53 +0200
committerGravatar GitHub <[email protected]>2019-07-21 10:00:53 +0200
commit5766439c3b521d9a70f5469ecaa2f4820270ea67 (patch)
treebaaafbd03801af3efc25a1a3fac47bf1ee25a0a3 /pydis_site
parentMerge pull request #220 from python-discord/django-api-bot-nomination-changes (diff)
parentUpdate pre-commit config to ignore migrations directory (diff)
Merge pull request #229 from python-discord/low-hanging-merge-fruit
Minor Merges from master
Diffstat (limited to 'pydis_site')
-rw-r--r--pydis_site/apps/api/admin.py6
-rw-r--r--pydis_site/apps/api/migrations/0036_removing_snake_apis.py25
-rw-r--r--pydis_site/apps/api/migrations/0038_merge_20190719_1817.py14
-rw-r--r--pydis_site/apps/api/models/__init__.py4
-rw-r--r--pydis_site/apps/api/models/bot/__init__.py4
-rw-r--r--pydis_site/apps/api/models/bot/bot_setting.py1
-rw-r--r--pydis_site/apps/api/models/bot/documentation_link.py1
-rw-r--r--pydis_site/apps/api/models/bot/infraction.py1
-rw-r--r--pydis_site/apps/api/models/bot/off_topic_channel_name.py1
-rw-r--r--pydis_site/apps/api/models/bot/reminder.py1
-rw-r--r--pydis_site/apps/api/models/bot/role.py1
-rw-r--r--pydis_site/apps/api/models/bot/snake_fact.py18
-rw-r--r--pydis_site/apps/api/models/bot/snake_idiom.py18
-rw-r--r--pydis_site/apps/api/models/bot/snake_name.py25
-rw-r--r--pydis_site/apps/api/models/bot/special_snake.py28
-rw-r--r--pydis_site/apps/api/models/bot/tag.py5
-rw-r--r--pydis_site/apps/api/models/bot/user.py1
-rw-r--r--pydis_site/apps/api/models/utils.py1
-rw-r--r--pydis_site/apps/api/serializers.py46
-rw-r--r--pydis_site/apps/api/tests/test_models.py12
-rw-r--r--pydis_site/apps/api/tests/test_snake_names.py67
-rw-r--r--pydis_site/apps/api/urls.py23
-rw-r--r--pydis_site/apps/api/views.py1
-rw-r--r--pydis_site/apps/api/viewsets/__init__.py4
-rw-r--r--pydis_site/apps/api/viewsets/bot/__init__.py4
-rw-r--r--pydis_site/apps/api/viewsets/bot/infraction.py5
-rw-r--r--pydis_site/apps/api/viewsets/bot/nomination.py1
-rw-r--r--pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py4
-rw-r--r--pydis_site/apps/api/viewsets/bot/snake_fact.py30
-rw-r--r--pydis_site/apps/api/viewsets/bot/snake_idiom.py30
-rw-r--r--pydis_site/apps/api/viewsets/bot/snake_name.py69
-rw-r--r--pydis_site/apps/api/viewsets/bot/special_snake.py33
-rw-r--r--pydis_site/apps/home/models/repository_metadata.py1
-rw-r--r--pydis_site/apps/home/templatetags/extra_filters.py1
-rw-r--r--pydis_site/apps/home/templatetags/wiki_extra.py9
-rw-r--r--pydis_site/apps/home/tests/test_repodata_helpers.py6
-rw-r--r--pydis_site/apps/home/views/home.py8
-rw-r--r--pydis_site/utils/resources.py5
38 files changed, 50 insertions, 464 deletions
diff --git a/pydis_site/apps/api/admin.py b/pydis_site/apps/api/admin.py
index a5b75fa9..c3784317 100644
--- a/pydis_site/apps/api/admin.py
+++ b/pydis_site/apps/api/admin.py
@@ -5,8 +5,6 @@ from .models import (
DocumentationLink, Infraction,
MessageDeletionContext, Nomination,
OffTopicChannelName, Role,
- SnakeFact, SnakeIdiom,
- SnakeName, SpecialSnake,
Tag, User
)
@@ -19,9 +17,5 @@ admin.site.register(MessageDeletionContext)
admin.site.register(Nomination)
admin.site.register(OffTopicChannelName)
admin.site.register(Role)
-admin.site.register(SnakeFact)
-admin.site.register(SnakeIdiom)
-admin.site.register(SnakeName)
-admin.site.register(SpecialSnake)
admin.site.register(Tag)
admin.site.register(User)
diff --git a/pydis_site/apps/api/migrations/0036_removing_snake_apis.py b/pydis_site/apps/api/migrations/0036_removing_snake_apis.py
new file mode 100644
index 00000000..624afc95
--- /dev/null
+++ b/pydis_site/apps/api/migrations/0036_removing_snake_apis.py
@@ -0,0 +1,25 @@
+# Generated by Django 2.2.3 on 2019-07-10 09:07
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('api', '0035_create_table_log_entry'),
+ ]
+
+ operations = [
+ migrations.DeleteModel(
+ name='SnakeFact',
+ ),
+ migrations.DeleteModel(
+ name='SnakeIdiom',
+ ),
+ migrations.DeleteModel(
+ name='SnakeName',
+ ),
+ migrations.DeleteModel(
+ name='SpecialSnake',
+ ),
+ ]
diff --git a/pydis_site/apps/api/migrations/0038_merge_20190719_1817.py b/pydis_site/apps/api/migrations/0038_merge_20190719_1817.py
new file mode 100644
index 00000000..532bcb70
--- /dev/null
+++ b/pydis_site/apps/api/migrations/0038_merge_20190719_1817.py
@@ -0,0 +1,14 @@
+# Generated by Django 2.2.3 on 2019-07-19 22:17
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('api', '0037_nomination_field_name_change'),
+ ('api', '0036_removing_snake_apis'),
+ ]
+
+ operations = [
+ ]
diff --git a/pydis_site/apps/api/models/__init__.py b/pydis_site/apps/api/models/__init__.py
index 4645bda2..a7eccb04 100644
--- a/pydis_site/apps/api/models/__init__.py
+++ b/pydis_site/apps/api/models/__init__.py
@@ -9,10 +9,6 @@ from .bot import ( # noqa
OffTopicChannelName,
Reminder,
Role,
- SnakeFact,
- SnakeIdiom,
- SnakeName,
- SpecialSnake,
Tag,
User
)
diff --git a/pydis_site/apps/api/models/bot/__init__.py b/pydis_site/apps/api/models/bot/__init__.py
index fb313193..b805924a 100644
--- a/pydis_site/apps/api/models/bot/__init__.py
+++ b/pydis_site/apps/api/models/bot/__init__.py
@@ -8,9 +8,5 @@ from .nomination import Nomination # noqa
from .off_topic_channel_name import OffTopicChannelName # noqa
from .reminder import Reminder # noqa
from .role import Role # noqa
-from .snake_fact import SnakeFact # noqa
-from .snake_idiom import SnakeIdiom # noqa
-from .snake_name import SnakeName # noqa
-from .special_snake import SpecialSnake # noqa
from .tag import Tag # noqa
from .user import User # noqa
diff --git a/pydis_site/apps/api/models/bot/bot_setting.py b/pydis_site/apps/api/models/bot/bot_setting.py
index ee9838b7..a52f3e34 100644
--- a/pydis_site/apps/api/models/bot/bot_setting.py
+++ b/pydis_site/apps/api/models/bot/bot_setting.py
@@ -7,7 +7,6 @@ from pydis_site.apps.api.models.utils import ModelReprMixin
def validate_bot_setting_name(name):
"""Raises a ValidationError if the given name is not a known setting."""
-
known_settings = (
'defcon',
)
diff --git a/pydis_site/apps/api/models/bot/documentation_link.py b/pydis_site/apps/api/models/bot/documentation_link.py
index 30379396..f844ae04 100644
--- a/pydis_site/apps/api/models/bot/documentation_link.py
+++ b/pydis_site/apps/api/models/bot/documentation_link.py
@@ -23,5 +23,4 @@ class DocumentationLink(ModelReprMixin, models.Model):
def __str__(self):
"""Returns the package and URL for the current documentation link, for display purposes."""
-
return f"{self.package} - {self.base_url}"
diff --git a/pydis_site/apps/api/models/bot/infraction.py b/pydis_site/apps/api/models/bot/infraction.py
index 7669352f..da91d6c2 100644
--- a/pydis_site/apps/api/models/bot/infraction.py
+++ b/pydis_site/apps/api/models/bot/infraction.py
@@ -60,7 +60,6 @@ class Infraction(ModelReprMixin, models.Model):
def __str__(self):
"""Returns some info on the current infraction, for display purposes."""
-
s = f"#{self.id}: {self.type} on {self.user_id}"
if self.expires_at:
s += f" until {self.expires_at}"
diff --git a/pydis_site/apps/api/models/bot/off_topic_channel_name.py b/pydis_site/apps/api/models/bot/off_topic_channel_name.py
index 2f55a131..0891f811 100644
--- a/pydis_site/apps/api/models/bot/off_topic_channel_name.py
+++ b/pydis_site/apps/api/models/bot/off_topic_channel_name.py
@@ -16,5 +16,4 @@ class OffTopicChannelName(ModelReprMixin, models.Model):
def __str__(self):
"""Returns the current off-topic name, for display purposes."""
-
return self.name
diff --git a/pydis_site/apps/api/models/bot/reminder.py b/pydis_site/apps/api/models/bot/reminder.py
index ae45b5de..decc9391 100644
--- a/pydis_site/apps/api/models/bot/reminder.py
+++ b/pydis_site/apps/api/models/bot/reminder.py
@@ -42,5 +42,4 @@ class Reminder(ModelReprMixin, models.Model):
def __str__(self):
"""Returns some info on the current reminder, for display purposes."""
-
return f"{self.content} on {self.expiration} by {self.author}"
diff --git a/pydis_site/apps/api/models/bot/role.py b/pydis_site/apps/api/models/bot/role.py
index ad043bd6..34e74009 100644
--- a/pydis_site/apps/api/models/bot/role.py
+++ b/pydis_site/apps/api/models/bot/role.py
@@ -46,5 +46,4 @@ class Role(ModelReprMixin, models.Model):
def __str__(self):
"""Returns the name of the current role, for display purposes."""
-
return self.name
diff --git a/pydis_site/apps/api/models/bot/snake_fact.py b/pydis_site/apps/api/models/bot/snake_fact.py
deleted file mode 100644
index c960cbc4..00000000
--- a/pydis_site/apps/api/models/bot/snake_fact.py
+++ /dev/null
@@ -1,18 +0,0 @@
-from django.db import models
-
-from pydis_site.apps.api.models.utils import ModelReprMixin
-
-
-class SnakeFact(ModelReprMixin, models.Model):
- """A snake fact used by the bot's snake cog."""
-
- fact = models.CharField(
- primary_key=True,
- max_length=200,
- help_text="A fact about snakes."
- )
-
- def __str__(self):
- """Returns the current snake fact, for display purposes."""
-
- return self.fact
diff --git a/pydis_site/apps/api/models/bot/snake_idiom.py b/pydis_site/apps/api/models/bot/snake_idiom.py
deleted file mode 100644
index 0e8f5e94..00000000
--- a/pydis_site/apps/api/models/bot/snake_idiom.py
+++ /dev/null
@@ -1,18 +0,0 @@
-from django.db import models
-
-from pydis_site.apps.api.models.utils import ModelReprMixin
-
-
-class SnakeIdiom(ModelReprMixin, models.Model):
- """A snake idiom used by the snake cog."""
-
- idiom = models.CharField(
- primary_key=True,
- max_length=140,
- help_text="A saying about a snake."
- )
-
- def __str__(self):
- """Returns the current idiom, for display purposes."""
-
- return self.idiom
diff --git a/pydis_site/apps/api/models/bot/snake_name.py b/pydis_site/apps/api/models/bot/snake_name.py
deleted file mode 100644
index b6ea6202..00000000
--- a/pydis_site/apps/api/models/bot/snake_name.py
+++ /dev/null
@@ -1,25 +0,0 @@
-from django.core.validators import RegexValidator
-from django.db import models
-
-from pydis_site.apps.api.models.utils import ModelReprMixin
-
-
-class SnakeName(ModelReprMixin, models.Model):
- """A snake name used by the bot's snake cog."""
-
- name = models.CharField(
- primary_key=True,
- max_length=100,
- help_text="The regular name for this snake, e.g. 'Python'.",
- validators=[RegexValidator(regex=r'^([^0-9])+$')]
- )
- scientific = models.CharField(
- max_length=150,
- help_text="The scientific name for this snake, e.g. 'Python bivittatus'.",
- validators=[RegexValidator(regex=r'^([^0-9])+$')]
- )
-
- def __str__(self):
- """Returns the regular and scientific name of the current snake, for display purposes."""
-
- return f"{self.name} ({self.scientific})"
diff --git a/pydis_site/apps/api/models/bot/special_snake.py b/pydis_site/apps/api/models/bot/special_snake.py
deleted file mode 100644
index 662ff8e3..00000000
--- a/pydis_site/apps/api/models/bot/special_snake.py
+++ /dev/null
@@ -1,28 +0,0 @@
-from django.contrib.postgres import fields as pgfields
-from django.core.validators import RegexValidator
-from django.db import models
-
-from pydis_site.apps.api.models.utils import ModelReprMixin
-
-
-class SpecialSnake(ModelReprMixin, models.Model):
- """A special snake's name, info and image from our database used by the bot's snake cog."""
-
- name = models.CharField(
- max_length=140,
- primary_key=True,
- help_text='A special snake name.',
- validators=[RegexValidator(regex=r'^([^0-9])+$')]
- )
- info = models.TextField(
- help_text='Info about a special snake.'
- )
- images = pgfields.ArrayField(
- models.URLField(),
- help_text='Images displaying this special snake.'
- )
-
- def __str__(self):
- """Returns the name of the current snake, for display purposes."""
-
- return self.name
diff --git a/pydis_site/apps/api/models/bot/tag.py b/pydis_site/apps/api/models/bot/tag.py
index 99819e42..01b49525 100644
--- a/pydis_site/apps/api/models/bot/tag.py
+++ b/pydis_site/apps/api/models/bot/tag.py
@@ -10,7 +10,6 @@ from pydis_site.apps.api.models.utils import ModelReprMixin
def validate_tag_embed_fields(fields):
"""Raises a ValidationError if any of the given embed fields is invalid."""
-
field_validators = {
'name': (MaxLengthValidator(limit_value=256),),
'value': (MaxLengthValidator(limit_value=1024),)
@@ -30,7 +29,6 @@ def validate_tag_embed_fields(fields):
def validate_tag_embed_footer(footer):
"""Raises a ValidationError if the given footer is invalid."""
-
field_validators = {
'text': (
MinLengthValidator(
@@ -56,7 +54,6 @@ def validate_tag_embed_footer(footer):
def validate_tag_embed_author(author):
"""Raises a ValidationError if the given author is invalid."""
-
field_validators = {
'name': (
MinLengthValidator(
@@ -120,7 +117,6 @@ def validate_tag_embed(embed):
is raised which in turn will allow Django to display errors
as appropriate.
"""
-
all_keys = {
'title', 'type', 'description', 'url', 'timestamp',
'color', 'footer', 'image', 'thumbnail', 'video',
@@ -184,5 +180,4 @@ class Tag(ModelReprMixin, models.Model):
def __str__(self):
"""Returns the title of this tag, for display purposes."""
-
return self.title
diff --git a/pydis_site/apps/api/models/bot/user.py b/pydis_site/apps/api/models/bot/user.py
index 8b995b59..d4deb630 100644
--- a/pydis_site/apps/api/models/bot/user.py
+++ b/pydis_site/apps/api/models/bot/user.py
@@ -50,5 +50,4 @@ class User(ModelReprMixin, models.Model):
def __str__(self):
"""Returns the name and discriminator for the current user, for display purposes."""
-
return f"{self.name}#{self.discriminator}"
diff --git a/pydis_site/apps/api/models/utils.py b/pydis_site/apps/api/models/utils.py
index 8f590392..0540c4de 100644
--- a/pydis_site/apps/api/models/utils.py
+++ b/pydis_site/apps/api/models/utils.py
@@ -6,7 +6,6 @@ class ModelReprMixin:
def __repr__(self):
"""Returns the current model class name and initialisation parameters."""
-
attributes = ' '.join(
f'{attribute}={value!r}'
for attribute, value in sorted(
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py
index f1200d34..51ad9276 100644
--- a/pydis_site/apps/api/serializers.py
+++ b/pydis_site/apps/api/serializers.py
@@ -9,8 +9,6 @@ from .models import (
LogEntry, MessageDeletionContext,
Nomination, OffTopicChannelName,
Reminder, Role,
- SnakeFact, SnakeIdiom,
- SnakeName, SpecialSnake,
Tag, User
)
@@ -75,7 +73,6 @@ class MessageDeletionContextSerializer(ModelSerializer):
itself, this serializer also allows for passing the `deletedmessage_set` element
which contains messages that were deleted as part of this context.
"""
-
messages = validated_data.pop('deletedmessage_set')
deletion_context = MessageDeletionContext.objects.create(**validated_data)
for message in messages:
@@ -110,7 +107,6 @@ class InfractionSerializer(ModelSerializer):
def validate(self, attrs):
"""Validate data constraints for the given data and abort if it is invalid."""
-
infr_type = attrs.get('type')
expires_at = attrs.get('expires_at')
@@ -133,7 +129,6 @@ class ExpandedInfractionSerializer(InfractionSerializer):
def to_representation(self, instance):
"""Return the dictionary representation of this infraction."""
-
ret = super().to_representation(instance)
user = User.objects.get(id=ret['user'])
@@ -178,50 +173,9 @@ class OffTopicChannelNameSerializer(ModelSerializer):
Additionally, this allows off topic channel name routes to simply return an
array of names instead of objects, saving on bandwidth.
"""
-
return obj.name
-class SnakeFactSerializer(ModelSerializer):
- """A class providing (de-)serialization of `SnakeFact` instances."""
-
- class Meta:
- """Metadata defined for the Django REST Framework."""
-
- model = SnakeFact
- fields = ('fact',)
-
-
-class SnakeIdiomSerializer(ModelSerializer):
- """A class providing (de-)serialization of `SnakeIdiom` instances."""
-
- class Meta:
- """Metadata defined for the Django REST Framework."""
-
- model = SnakeIdiom
- fields = ('idiom',)
-
-
-class SnakeNameSerializer(ModelSerializer):
- """A class providing (de-)serialization of `SnakeName` instances."""
-
- class Meta:
- """Metadata defined for the Django REST Framework."""
-
- model = SnakeName
- fields = ('name', 'scientific')
-
-
-class SpecialSnakeSerializer(ModelSerializer):
- """A class providing (de-)serialization of `SpecialSnake` instances."""
-
- class Meta:
- """Metadata defined for the Django REST Framework."""
-
- model = SpecialSnake
- fields = ('name', 'images', 'info')
-
-
class ReminderSerializer(ModelSerializer):
"""A class providing (de-)serialization of `Reminder` instances."""
diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py
index a958419d..cfc8464e 100644
--- a/pydis_site/apps/api/tests/test_models.py
+++ b/pydis_site/apps/api/tests/test_models.py
@@ -7,10 +7,7 @@ from ..models import (
Infraction, Message,
MessageDeletionContext, ModelReprMixin,
OffTopicChannelName, Reminder,
- Role, SnakeFact,
- SnakeIdiom, SnakeName,
- SpecialSnake, Tag,
- User
+ Role, Tag, User
)
@@ -52,13 +49,6 @@ class StringDunderMethodTests(SimpleTestCase):
'test', 'http://example.com', 'http://example.com'
),
OffTopicChannelName(name='bob-the-builders-playground'),
- SnakeFact(fact='snakes are cute'),
- SnakeIdiom(idiom='snake snacks'),
- SnakeName(name='python', scientific='3'),
- SpecialSnake(
- name='Pythagoras Pythonista',
- info='The only python snake that is born a triangle'
- ),
Role(
id=5, name='test role',
colour=0x5, permissions=0
diff --git a/pydis_site/apps/api/tests/test_snake_names.py b/pydis_site/apps/api/tests/test_snake_names.py
deleted file mode 100644
index 41dfae63..00000000
--- a/pydis_site/apps/api/tests/test_snake_names.py
+++ /dev/null
@@ -1,67 +0,0 @@
-from django_hosts.resolvers import reverse
-
-from .base import APISubdomainTestCase
-from ..models import SnakeName
-
-
-class StatusTests(APISubdomainTestCase):
- def setUp(self):
- super().setUp()
- self.client.force_authenticate(user=None)
-
- def test_cannot_read_snake_name_list(self):
- url = reverse('bot:snakename-list', host='api')
- response = self.client.get(url)
-
- self.assertEqual(response.status_code, 401)
-
- def test_cannot_read_snake_names_with_get_all_param(self):
- url = reverse('bot:snakename-list', host='api')
- response = self.client.get(f'{url}?get_all=True')
-
- self.assertEqual(response.status_code, 401)
-
-
-class EmptyDatabaseSnakeNameTests(APISubdomainTestCase):
- def test_endpoint_returns_empty_object(self):
- url = reverse('bot:snakename-list', host='api')
- response = self.client.get(url)
-
- self.assertEqual(response.status_code, 200)
- self.assertEqual(response.json(), {})
-
- def test_endpoint_returns_empty_list_with_get_all_param(self):
- url = reverse('bot:snakename-list', host='api')
- response = self.client.get(f'{url}?get_all=True')
-
- self.assertEqual(response.status_code, 200)
- self.assertEqual(response.json(), [])
-
-
-class SnakeNameListTests(APISubdomainTestCase):
- @classmethod
- def setUpTestData(cls): # noqa
- cls.snake_python = SnakeName.objects.create(name='Python', scientific='Totally.')
-
- def test_endpoint_returns_all_snakes_with_get_all_param(self):
- url = reverse('bot:snakename-list', host='api')
- response = self.client.get(f'{url}?get_all=True')
-
- self.assertEqual(response.status_code, 200)
- self.assertEqual(
- response.json(),
- [
- {
- 'name': self.snake_python.name,
- 'scientific': self.snake_python.scientific
- }
- ]
- )
-
- def test_endpoint_returns_single_snake_without_get_all_param(self):
- url = reverse('bot:snakename-list', host='api')
- response = self.client.get(url)
- self.assertEqual(response.json(), {
- 'name': self.snake_python.name,
- 'scientific': self.snake_python.scientific
- })
diff --git a/pydis_site/apps/api/urls.py b/pydis_site/apps/api/urls.py
index 724d7e2b..ac6704c8 100644
--- a/pydis_site/apps/api/urls.py
+++ b/pydis_site/apps/api/urls.py
@@ -7,10 +7,7 @@ from .viewsets import (
DocumentationLinkViewSet, InfractionViewSet,
LogEntryViewSet, NominationViewSet,
OffTopicChannelNameViewSet, ReminderViewSet,
- RoleViewSet, SnakeFactViewSet,
- SnakeIdiomViewSet, SnakeNameViewSet,
- SpecialSnakeViewSet, TagViewSet,
- UserViewSet
+ RoleViewSet, TagViewSet, UserViewSet
)
@@ -50,23 +47,6 @@ bot_router.register(
RoleViewSet
)
bot_router.register(
- 'snake-facts',
- SnakeFactViewSet
-)
-bot_router.register(
- 'snake-idioms',
- SnakeIdiomViewSet
-)
-bot_router.register(
- 'snake-names',
- SnakeNameViewSet,
- base_name='snakename'
-)
-bot_router.register(
- 'special-snakes',
- SpecialSnakeViewSet
-)
-bot_router.register(
'tags',
TagViewSet
)
@@ -80,7 +60,6 @@ urlpatterns = (
# Build URLs using something like...
#
# from django_hosts.resolvers import reverse
- # snake_name_endpoint = reverse('bot:snakename-list', host='api') # `bot/` endpoints
path('bot/', include((bot_router.urls, 'api'), namespace='bot')),
path('logs', LogEntryViewSet.as_view({'post': 'create'}), name='logs'),
path('healthcheck', HealthcheckView.as_view(), name='healthcheck'),
diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py
index c7dbf5c8..e79de5e1 100644
--- a/pydis_site/apps/api/views.py
+++ b/pydis_site/apps/api/views.py
@@ -86,7 +86,6 @@ class RulesView(APIView):
ValueError:
If `target` is not `'md'` or `'html'`.
"""
-
if target == 'html':
return f'<a href="{link}">{description}</a>'
elif target == 'md':
diff --git a/pydis_site/apps/api/viewsets/__init__.py b/pydis_site/apps/api/viewsets/__init__.py
index 553ca2c3..224e6910 100644
--- a/pydis_site/apps/api/viewsets/__init__.py
+++ b/pydis_site/apps/api/viewsets/__init__.py
@@ -7,10 +7,6 @@ from .bot import ( # noqa
OffTopicChannelNameViewSet,
ReminderViewSet,
RoleViewSet,
- SnakeFactViewSet,
- SnakeIdiomViewSet,
- SnakeNameViewSet,
- SpecialSnakeViewSet,
TagViewSet,
UserViewSet
)
diff --git a/pydis_site/apps/api/viewsets/bot/__init__.py b/pydis_site/apps/api/viewsets/bot/__init__.py
index 8e7d1290..465ba5f4 100644
--- a/pydis_site/apps/api/viewsets/bot/__init__.py
+++ b/pydis_site/apps/api/viewsets/bot/__init__.py
@@ -6,9 +6,5 @@ from .nomination import NominationViewSet # noqa
from .off_topic_channel_name import OffTopicChannelNameViewSet # noqa
from .reminder import ReminderViewSet # noqa
from .role import RoleViewSet # noqa
-from .snake_fact import SnakeFactViewSet # noqa
-from .snake_idiom import SnakeIdiomViewSet # noqa
-from .snake_name import SnakeNameViewSet # noqa
-from .special_snake import SpecialSnakeViewSet # noqa
from .tag import TagViewSet # noqa
from .user import UserViewSet # noqa
diff --git a/pydis_site/apps/api/viewsets/bot/infraction.py b/pydis_site/apps/api/viewsets/bot/infraction.py
index d12f0862..c471ca2c 100644
--- a/pydis_site/apps/api/viewsets/bot/infraction.py
+++ b/pydis_site/apps/api/viewsets/bot/infraction.py
@@ -125,7 +125,6 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge
def partial_update(self, request, *_args, **_kwargs):
"""Method that handles the nuts and bolts of updating an Infraction."""
-
for field in request.data:
if field in self.frozen_fields:
raise ValidationError({field: ['This field cannot be updated.']})
@@ -144,7 +143,6 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge
Called by the Django Rest Framework in response to the corresponding HTTP request.
"""
-
self.serializer_class = ExpandedInfractionSerializer
return self.list(*args, **kwargs)
@@ -155,7 +153,6 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge
Called by the Django Rest Framework in response to the corresponding HTTP request.
"""
-
self.serializer_class = ExpandedInfractionSerializer
return self.create(*args, **kwargs)
@@ -166,7 +163,6 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge
Called by the Django Rest Framework in response to the corresponding HTTP request.
"""
-
self.serializer_class = ExpandedInfractionSerializer
return self.retrieve(*args, **kwargs)
@@ -177,6 +173,5 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge
Called by the Django Rest Framework in response to the corresponding HTTP request.
"""
-
self.serializer_class = ExpandedInfractionSerializer
return self.partial_update(*args, **kwargs)
diff --git a/pydis_site/apps/api/viewsets/bot/nomination.py b/pydis_site/apps/api/viewsets/bot/nomination.py
index a9dacd68..8d551697 100644
--- a/pydis_site/apps/api/viewsets/bot/nomination.py
+++ b/pydis_site/apps/api/viewsets/bot/nomination.py
@@ -143,6 +143,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge
See operation 1 for the response format and status codes.
"""
+
serializer_class = NominationSerializer
queryset = Nomination.objects.all()
filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter)
diff --git a/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py b/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py
index 4976c291..d977aade 100644
--- a/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py
+++ b/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py
@@ -60,14 +60,12 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):
If it doesn't, a HTTP 404 is returned by way of throwing an exception.
"""
-
queryset = self.get_queryset()
name = self.kwargs[self.lookup_field]
return get_object_or_404(queryset, name=name)
def get_queryset(self):
"""Returns a queryset that covers the entire OffTopicChannelName table."""
-
return OffTopicChannelName.objects.all()
def create(self, request):
@@ -76,7 +74,6 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):
Called by the Django Rest Framework in response to the corresponding HTTP request.
"""
-
if 'name' in request.query_params:
create_data = {'name': request.query_params['name']}
serializer = OffTopicChannelNameSerializer(data=create_data)
@@ -95,7 +92,6 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):
Called by the Django Rest Framework in response to the corresponding HTTP request.
"""
-
if 'random_items' in request.query_params:
param = request.query_params['random_items']
try:
diff --git a/pydis_site/apps/api/viewsets/bot/snake_fact.py b/pydis_site/apps/api/viewsets/bot/snake_fact.py
deleted file mode 100644
index 0b2e8ede..00000000
--- a/pydis_site/apps/api/viewsets/bot/snake_fact.py
+++ /dev/null
@@ -1,30 +0,0 @@
-from rest_framework.mixins import ListModelMixin
-from rest_framework.viewsets import GenericViewSet
-
-from pydis_site.apps.api.models.bot.snake_fact import SnakeFact
-from pydis_site.apps.api.serializers import SnakeFactSerializer
-
-
-class SnakeFactViewSet(ListModelMixin, GenericViewSet):
- """
- View providing snake facts created by the Pydis community in the first code jam.
-
- ## Routes
- ### GET /bot/snake-facts
- Returns snake facts from the database.
-
- #### Response format
- >>> [
- ... {'fact': 'Snakes are dangerous'},
- ... {'fact': 'Except for Python, we all love it'}
- ... ]
-
- #### Status codes
- - 200: returned on success
-
- ## Authentication
- Requires an API token.
- """
-
- serializer_class = SnakeFactSerializer
- queryset = SnakeFact.objects.all()
diff --git a/pydis_site/apps/api/viewsets/bot/snake_idiom.py b/pydis_site/apps/api/viewsets/bot/snake_idiom.py
deleted file mode 100644
index 9f274d2f..00000000
--- a/pydis_site/apps/api/viewsets/bot/snake_idiom.py
+++ /dev/null
@@ -1,30 +0,0 @@
-from rest_framework.mixins import ListModelMixin
-from rest_framework.viewsets import GenericViewSet
-
-from pydis_site.apps.api.models.bot.snake_idiom import SnakeIdiom
-from pydis_site.apps.api.serializers import SnakeIdiomSerializer
-
-
-class SnakeIdiomViewSet(ListModelMixin, GenericViewSet):
- """
- View providing snake idioms for the snake cog.
-
- ## Routes
- ### GET /bot/snake-idioms
- Returns snake idioms from the database.
-
- #### Response format
- >>> [
- ... {'idiom': 'Sneky snek'},
- ... {'idiom': 'Snooky Snake'}
- ... ]
-
- #### Status codes
- - 200: returned on success
-
- ## Authentication
- Requires an API token
- """
-
- serializer_class = SnakeIdiomSerializer
- queryset = SnakeIdiom.objects.all()
diff --git a/pydis_site/apps/api/viewsets/bot/snake_name.py b/pydis_site/apps/api/viewsets/bot/snake_name.py
deleted file mode 100644
index 8e63a542..00000000
--- a/pydis_site/apps/api/viewsets/bot/snake_name.py
+++ /dev/null
@@ -1,69 +0,0 @@
-from rest_framework.response import Response
-from rest_framework.viewsets import ViewSet
-
-from pydis_site.apps.api.models.bot.snake_name import SnakeName
-from pydis_site.apps.api.serializers import SnakeNameSerializer
-
-
-class SnakeNameViewSet(ViewSet):
- """
- View providing snake names for the bot's snake cog from our first code jam's winners.
-
- ## Routes
- ### GET /bot/snake-names
- By default, return a single random snake name along with its name and scientific name.
- If the `get_all` query parameter is given, for example using...
- $ curl api.pythondiscord.local:8000/bot/snake-names?get_all=yes
- ... then the API will return all snake names and scientific names in the database.
-
- #### Response format
- Without `get_all` query parameter:
- >>> {
- ... 'name': "Python",
- ... 'scientific': "Langus greatus"
- ... }
-
- If the database is empty for whatever reason, this will return an empty dictionary.
-
- With `get_all` query parameter:
- >>> [
- ... {'name': "Python 3", 'scientific': "Langus greatus"},
- ... {'name': "Python 2", 'scientific': "Langus decentus"}
- ... ]
-
- #### Status codes
- - 200: returned on success
-
- ## Authentication
- Requires a API token.
- """
-
- serializer_class = SnakeNameSerializer
-
- def get_queryset(self):
- """Returns a queryset that covers the entire SnakeName table."""
-
- return SnakeName.objects.all()
-
- def list(self, request):
- """
- DRF method for listing SnakeName entries.
-
- Called by the Django Rest Framework in response to the corresponding HTTP request.
- """
-
- if request.query_params.get('get_all'):
- queryset = self.get_queryset()
- serialized = self.serializer_class(queryset, many=True)
- return Response(serialized.data)
-
- single_snake = SnakeName.objects.order_by('?').first()
- if single_snake is not None:
- body = {
- 'name': single_snake.name,
- 'scientific': single_snake.scientific
- }
-
- return Response(body)
-
- return Response({})
diff --git a/pydis_site/apps/api/viewsets/bot/special_snake.py b/pydis_site/apps/api/viewsets/bot/special_snake.py
deleted file mode 100644
index 446c79a1..00000000
--- a/pydis_site/apps/api/viewsets/bot/special_snake.py
+++ /dev/null
@@ -1,33 +0,0 @@
-from rest_framework.mixins import ListModelMixin
-from rest_framework.viewsets import GenericViewSet
-
-from pydis_site.apps.api.models.bot import SpecialSnake
-from pydis_site.apps.api.serializers import SpecialSnakeSerializer
-
-
-class SpecialSnakeViewSet(ListModelMixin, GenericViewSet):
- """
- View providing special snake names for our bot's snake cog.
-
- ## Routes
- ### GET /bot/special-snakes
- Returns a list of special snake names.
-
- #### Response Format
- >>> [
- ... {
- ... 'name': 'Snakky sneakatus',
- ... 'info': 'Scary snek',
- ... 'image': 'https://discordapp.com/assets/53ef346458017da2062aca5c7955946b.svg'
- ... }
- ... ]
-
- #### Status codes
- - 200: returned on success
-
- ## Authentication
- Requires an API token.
- """
-
- serializer_class = SpecialSnakeSerializer
- queryset = SpecialSnake.objects.all()
diff --git a/pydis_site/apps/home/models/repository_metadata.py b/pydis_site/apps/home/models/repository_metadata.py
index f68d3985..92d2404d 100644
--- a/pydis_site/apps/home/models/repository_metadata.py
+++ b/pydis_site/apps/home/models/repository_metadata.py
@@ -31,5 +31,4 @@ class RepositoryMetadata(models.Model):
def __str__(self):
"""Returns the repo name, for display purposes."""
-
return self.repo_name
diff --git a/pydis_site/apps/home/templatetags/extra_filters.py b/pydis_site/apps/home/templatetags/extra_filters.py
index 8af11591..99ba3dcd 100644
--- a/pydis_site/apps/home/templatetags/extra_filters.py
+++ b/pydis_site/apps/home/templatetags/extra_filters.py
@@ -16,5 +16,4 @@ def starts_with(value: str, arg: str):
{% endif %}
```
"""
-
return value.startswith(arg)
diff --git a/pydis_site/apps/home/templatetags/wiki_extra.py b/pydis_site/apps/home/templatetags/wiki_extra.py
index ab14f7be..2e90af43 100644
--- a/pydis_site/apps/home/templatetags/wiki_extra.py
+++ b/pydis_site/apps/home/templatetags/wiki_extra.py
@@ -1,4 +1,4 @@
-from typing import Any, Dict, Type, Union
+from typing import Any, Dict, List, Type, Union
from django import template
from django.forms import BooleanField, BoundField, CharField, Field, ImageField, ModelChoiceField
@@ -33,7 +33,6 @@ def get_unbound_field(field: Union[BoundField, Field]) -> Field:
Bound fields often don't give you the same level of access to the field's underlying attributes,
so sometimes it helps to have access to the underlying field object.
"""
-
while isinstance(field, BoundField):
field = field.field
@@ -47,7 +46,6 @@ def render(template_path: str, context: Dict[str, Any]):
This was extracted mostly for the sake of mocking it out in the tests - but do note that
the resulting rendered template is wrapped with `mark_safe`, so it will not be escaped.
"""
-
return mark_safe(get_template(template_path).render(context)) # noqa: S703, S308
@@ -67,7 +65,6 @@ def render_field(field: Field, render_labels: bool = True):
Usage: `{% render_field field_obj [render_labels=True/False] %}`
"""
-
unbound_field = get_unbound_field(field)
if not isinstance(render_labels, bool):
@@ -104,11 +101,10 @@ def get_field_options(context: Context, field: BoundField):
{% endif %}
```
"""
-
widget = field.field.widget
if field.value() is None:
- value = []
+ value: List[str] = []
else:
value = [str(field.value())]
@@ -130,7 +126,6 @@ def render_urlpath(value: Union[URLPath, str]):
Usage: `{{ url_path | render_urlpath }}`
"""
-
if isinstance(value, str):
return value or "/"
diff --git a/pydis_site/apps/home/tests/test_repodata_helpers.py b/pydis_site/apps/home/tests/test_repodata_helpers.py
index 59cb2331..df1ffd73 100644
--- a/pydis_site/apps/home/tests/test_repodata_helpers.py
+++ b/pydis_site/apps/home/tests/test_repodata_helpers.py
@@ -34,13 +34,11 @@ class TestRepositoryMetadataHelpers(TestCase):
def setUp(self):
"""Executed before each test method."""
-
self.home_view = HomeView()
@mock.patch('requests.get', side_effect=mocked_requests_get)
def test_returns_metadata(self, _: mock.MagicMock):
"""Test if the _get_repo_data helper actually returns what it should."""
-
metadata = self.home_view._get_repo_data()
self.assertIsInstance(metadata[0], RepositoryMetadata)
@@ -48,7 +46,6 @@ class TestRepositoryMetadataHelpers(TestCase):
def test_returns_cached_metadata(self):
"""Test if the _get_repo_data helper returns cached data when available."""
-
repo_data = RepositoryMetadata(
repo_name="python-discord/site",
description="testrepo",
@@ -65,7 +62,6 @@ class TestRepositoryMetadataHelpers(TestCase):
@mock.patch('requests.get', side_effect=mocked_requests_get)
def test_refresh_stale_metadata(self, _: mock.MagicMock):
"""Test if the _get_repo_data helper will refresh when the data is stale"""
-
repo_data = RepositoryMetadata(
repo_name="python-discord/site",
description="testrepo",
@@ -82,7 +78,6 @@ class TestRepositoryMetadataHelpers(TestCase):
@mock.patch('requests.get', side_effect=mocked_requests_get)
def test_returns_api_data(self, _: mock.MagicMock):
"""Tests if the _get_api_data helper returns what it should."""
-
api_data = self.home_view._get_api_data()
repo = self.home_view.repos[0]
@@ -94,7 +89,6 @@ class TestRepositoryMetadataHelpers(TestCase):
@mock.patch('requests.get', side_effect=mocked_requests_get)
def test_mocked_requests_get(self, mock_get: mock.MagicMock):
"""Tests if our mocked_requests_get is returning what it should."""
-
success_data = mock_get(HomeView.github_api)
fail_data = mock_get("failtest")
diff --git a/pydis_site/apps/home/views/home.py b/pydis_site/apps/home/views/home.py
index e4daf380..03873a72 100644
--- a/pydis_site/apps/home/views/home.py
+++ b/pydis_site/apps/home/views/home.py
@@ -28,12 +28,10 @@ class HomeView(View):
def _get_api_data(self) -> Dict[str, Dict[str, str]]:
"""Call the GitHub API and get information about our repos."""
-
- repo_dict = {repo_name: {} for repo_name in self.repos}
+ repo_dict: Dict[str, dict] = {repo_name: {} for repo_name in self.repos}
# Fetch the data from the GitHub API
- api_data = requests.get(self.github_api)
- api_data = api_data.json()
+ api_data: List[dict] = requests.get(self.github_api).json()
# Process the API data into our dict
for repo in api_data:
@@ -51,7 +49,6 @@ class HomeView(View):
def _get_repo_data(self) -> List[RepositoryMetadata]:
"""Build a list of RepositoryMetadata objects that we can use to populate the front page."""
-
# Try to get site data from the cache
try:
repo_data = RepositoryMetadata.objects.get(repo_name="python-discord/site")
@@ -110,6 +107,5 @@ class HomeView(View):
def get(self, request: WSGIRequest) -> HttpResponse:
"""Collect repo data and render the homepage view"""
-
repo_data = self._get_repo_data()
return render(request, "home/index.html", {"repo_data": repo_data})
diff --git a/pydis_site/utils/resources.py b/pydis_site/utils/resources.py
index ab0df9d7..fcf8bd75 100644
--- a/pydis_site/utils/resources.py
+++ b/pydis_site/utils/resources.py
@@ -10,6 +10,7 @@ import yaml
@dataclass
class URL:
"""A class representing a link to a resource"""
+
icon: str
title: str
url: str
@@ -17,6 +18,7 @@ class URL:
class Resource:
"""A class representing a resource on the resource page"""
+
description: str
name: str
payment: str
@@ -28,7 +30,7 @@ class Resource:
return f"<Resource name={self.name}>"
@classmethod
- def construct_from_yaml(cls, yaml_data: str) -> Resource: # noqa
+ def construct_from_yaml(cls, yaml_data: typing.TextIO) -> Resource: # noqa
resource = cls()
loaded = yaml.safe_load(yaml_data)
@@ -45,6 +47,7 @@ class Resource:
class Category:
"""A class representing a resource on the resources page"""
+
resources: typing.List[Resource]
name: str
description: str