diff options
| author | 2018-12-09 19:27:32 +0100 | |
|---|---|---|
| committer | 2018-12-09 19:27:32 +0100 | |
| commit | 8b7c4e55dcede6732e30cca1a19e7e99391ceedb (patch) | |
| tree | 1867912cf613498a4ca56fe3a0ef8660876157e3 /api | |
| parent | Bump minimum DRF version to `3.9.0`. (diff) | |
| parent | Fixed merge conflicts (diff) | |
Merge pull request #156 from python-discord/django-beautify
Django - API Corrections
Diffstat (limited to 'api')
| -rw-r--r-- | api/models.py | 110 | ||||
| -rw-r--r-- | api/tests/test_users.py | 2 | ||||
| -rw-r--r-- | api/viewsets.py | 6 | 
3 files changed, 59 insertions, 59 deletions
| diff --git a/api/models.py b/api/models.py index 3387e9be..21b5975a 100644 --- a/api/models.py +++ b/api/models.py @@ -60,6 +60,50 @@ class OffTopicChannelName(ModelReprMixin, models.Model):          return self.name +class Role(ModelReprMixin, models.Model): +    """A role on our Discord server.""" + +    id = models.BigIntegerField(  # noqa +        primary_key=True, +        validators=( +            MinValueValidator( +                limit_value=0, +                message="Role IDs cannot be negative." +            ), +        ), +        help_text="The role ID, taken from Discord." +    ) +    name = models.CharField( +        max_length=100, +        help_text="The role name, taken from Discord." +    ) +    colour = models.IntegerField( +        validators=( +            MinValueValidator( +                limit_value=0, +                message="Colour hex cannot be negative." +            ), +        ), +        help_text="The integer value of the colour of this role from Discord." +    ) +    permissions = models.IntegerField( +        validators=( +            MinValueValidator( +                limit_value=0, +                message="Role permissions cannot be negative." +            ), +            MaxValueValidator( +                limit_value=2 << 32, +                message="Role permission bitset exceeds value of having all permissions" +            ) +        ), +        help_text="The integer value of the permission bitset of this role from Discord." +    ) + +    def __str__(self): +        return self.name + +  class SnakeFact(ModelReprMixin, models.Model):      """A snake fact used by the bot's snake cog.""" @@ -126,48 +170,24 @@ class SpecialSnake(ModelReprMixin, models.Model):          return self.name -class Role(ModelReprMixin, models.Model): -    """A role on our Discord server.""" +class Tag(ModelReprMixin, models.Model): +    """A tag providing (hopefully) useful information.""" -    id = models.BigIntegerField(  # noqa -        primary_key=True, -        validators=( -            MinValueValidator( -                limit_value=0, -                message="Role IDs cannot be negative." -            ), -        ), -        help_text="The role ID, taken from Discord." -    ) -    name = models.CharField( +    title = models.CharField(          max_length=100, -        help_text="The role name, taken from Discord." -    ) -    colour = models.IntegerField( -        validators=( -            MinValueValidator( -                limit_value=0, -                message="Colour hex cannot be negative." -            ), +        help_text=( +            "The title of this tag, shown in searches and providing " +            "a quick overview over what this embed contains."          ), -        help_text="The integer value of the colour of this role from Discord." +        primary_key=True      ) -    permissions = models.IntegerField( -        validators=( -            MinValueValidator( -                limit_value=0, -                message="Role permissions cannot be negative." -            ), -            MaxValueValidator( -                limit_value=2 << 32, -                message="Role permission bitset exceeds value of having all permissions" -            ) -        ), -        help_text="The integer value of the permission bitset of this role from Discord." +    embed = pgfields.JSONField( +        help_text="The actual embed shown by this tag.", +        validators=(validate_tag_embed,)      )      def __str__(self): -        return self.name +        return self.title  class User(ModelReprMixin, models.Model): @@ -217,26 +237,6 @@ class User(ModelReprMixin, models.Model):          return f"{self.name}#{self.discriminator}" -class Tag(ModelReprMixin, models.Model): -    """A tag providing (hopefully) useful information.""" - -    title = models.CharField( -        max_length=100, -        help_text=( -            "The title of this tag, shown in searches and providing " -            "a quick overview over what this embed contains." -        ), -        primary_key=True -    ) -    embed = pgfields.JSONField( -        help_text="The actual embed shown by this tag.", -        validators=(validate_tag_embed,) -    ) - -    def __str__(self): -        return self.title - -  class Infraction(ModelReprMixin, models.Model):      """An infraction for a Discord user.""" diff --git a/api/tests/test_users.py b/api/tests/test_users.py index 8dadcbdb..90bc3d30 100644 --- a/api/tests/test_users.py +++ b/api/tests/test_users.py @@ -4,7 +4,7 @@ from .base import APISubdomainTestCase  from ..models import Role, User -class UnauthedDocumentationLinkAPITests(APISubdomainTestCase): +class UnauthedUserAPITests(APISubdomainTestCase):      def setUp(self):          super().setUp()          self.client.force_authenticate(user=None) diff --git a/api/viewsets.py b/api/viewsets.py index 2784bbad..aa5d5fd3 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -506,7 +506,7 @@ class TagViewSet(ModelViewSet):      - 201: returned on success      - 400: if one of the given fields is invalid -    ### PUT /bot/members/<title:str> +    ### PUT /bot/tags/<title:str>      Update the tag with the given `title`.      #### Request body @@ -524,7 +524,7 @@ class TagViewSet(ModelViewSet):      - 400: if the request body was invalid, see response body for details      - 404: if the tag with the given `title` could not be found -    ### PATCH /bot/members/<title:str> +    ### PATCH /bot/tags/<title:str>      Update the tag with the given `title`.      #### Request body @@ -542,7 +542,7 @@ class TagViewSet(ModelViewSet):      - 400: if the request body was invalid, see response body for details      - 404: if the tag with the given `title` could not be found -    ### DELETE /bot/members/<title:str> +    ### DELETE /bot/tags/<title:str>      Deletes the tag with the given `title`.      #### Status codes | 
