-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
176 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Generated by Django 3.2.3 on 2021-05-19 08:25 | ||
|
||
import datetime | ||
|
||
from django.db import migrations, models | ||
|
||
import durin.throttling | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("durin", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="client", | ||
name="throttle_rate", | ||
field=models.CharField( | ||
blank=True, | ||
default="", | ||
help_text="Follows the same format as DRF's throttle rates.\n Format: <em>'number_of_requests/period'</em>\n where period should be one of: ('s', 'm', 'h', 'd').\n Example: '100/h' implies 100 requests each hour.\n ", | ||
max_length=64, | ||
validators=[ | ||
durin.throttling.UserClientRateThrottle.validate_client_throttle_rate | ||
], | ||
verbose_name="Throttle rate for requests authed with this client", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="authtoken", | ||
name="id", | ||
field=models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="client", | ||
name="id", | ||
field=models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="client", | ||
name="token_ttl", | ||
field=models.DurationField( | ||
default=datetime.timedelta(days=1), | ||
help_text="\n Token Time To Live (TTL) in timedelta. Format: <code>DAYS HH:MM:SS</code>.\n ", | ||
verbose_name="Token Time To Live (TTL)", | ||
), | ||
), | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.contrib import admin | ||
|
||
from durin.models import Client | ||
|
||
from .models import ClientSettings | ||
|
||
|
||
class ClientSettingsInlineAdmin(admin.StackedInline): | ||
""" | ||
Django's StackedInline for :class:`ClientSettings` model. | ||
""" | ||
|
||
model = ClientSettings | ||
|
||
list_select_related = True | ||
extra = 1 | ||
|
||
|
||
class ClientAdmin(admin.ModelAdmin): | ||
""" | ||
Django's ModelAdmin for :class:`Client` model. | ||
""" | ||
|
||
inlines = [ | ||
ClientSettingsInlineAdmin, | ||
] | ||
|
||
list_display = ( | ||
"id", | ||
"name", | ||
"token_ttl", | ||
"throttle_rate", | ||
) | ||
|
||
|
||
# Unregister default admin view | ||
admin.site.unregister(Client) | ||
admin.site.register(Client, ClientAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 3.2.3 on 2021-05-19 08:31 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
("durin", "0002_client_throttlerate"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ClientSettings", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("description", models.TextField()), | ||
( | ||
"client", | ||
models.OneToOneField( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="settings", | ||
to="durin.client", | ||
), | ||
), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.db import models | ||
|
||
|
||
class ClientSettings(models.Model): | ||
""" | ||
It is recommended to create a model like this | ||
(and not subclass :py:class:`durin.models.Client`) | ||
if you wish to add extra fields for storing any | ||
configuration or settings against ``Client`` instances. | ||
Reverse lookup: ``Client.settings``. | ||
""" | ||
|
||
#: `OneToOneField | ||
#: <https://docs.djangoproject.com/en/3.2/topics/db/examples/one_to_one/>`__ | ||
#: with :py:class:`~Client` with ``on_delete=models.CASCADE``. | ||
client = models.OneToOneField( | ||
"durin.Client", | ||
blank=False, | ||
related_name="settings", | ||
on_delete=models.CASCADE, | ||
) | ||
|
||
description = models.TextField() | ||
|
||
def __str__(self): | ||
return "ClientSettings(<{0}>)".format(self.client.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.