Skip to content

Commit

Permalink
New logo, color header admin when debug and verbose names
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioDelConte committed Feb 21, 2024
1 parent d60e414 commit 87f32f0
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docker/deploy
47 changes: 42 additions & 5 deletions drmaatic/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import uuid

import jwt
from django.contrib.admin import display
from django.contrib.admin.widgets import AdminDateWidget, AdminSplitDateTime
from django.contrib.admin.widgets import AdminSplitDateTime
from django.contrib.auth import admin as auth
from django.utils import timezone
from django.core.cache import cache

from drmaatic.models import *
# noinspection PyUnresolvedReferences
Expand All @@ -15,6 +14,7 @@
from drmaatic.queue.admin import *
# noinspection PyUnresolvedReferences
from drmaatic.task.admin import *
from drmaatic.throttles import TokenBucketThrottle

# Register user in the admin web interface, using the default interface
admin.site.register(Admin, auth.UserAdmin)
Expand Down Expand Up @@ -77,9 +77,46 @@ class UserAdmin(admin.ModelAdmin):


class GroupForm(forms.ModelForm):
def clean(self):
def clean_token_renewal_time(self):
if timeparse(self.cleaned_data["token_renewal_time"]) is None:
raise forms.ValidationError({'token_renewal_time': "Invalid time"})
raise forms.ValidationError("Invalid time")
return self.cleaned_data["token_renewal_time"]

def clean_throttling_rate_burst(self):
def parse_rate(rate):
num, period = rate.split('/')
num_requests = int(num)
duration = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}[period[0]]
return num_requests, duration

try:
parse_rate(self.cleaned_data["throttling_rate_burst"])
except:
raise forms.ValidationError("Invalid rate, expected format: <number>/<s|m|h|d>")
return self.cleaned_data["throttling_rate_burst"]

def clean__cpu_credit_regen_time(self):
if timeparse(self.cleaned_data["_cpu_credit_regen_time"]) is None:
raise forms.ValidationError("Invalid time")
return self.cleaned_data["_cpu_credit_regen_time"]

def clean_cpu_credit_max_amount(self):
if self.cleaned_data["cpu_credit_max_amount"] < 0:
raise forms.ValidationError("Invalid amount")
return self.cleaned_data["cpu_credit_max_amount"]

def clean_cpu_credit_regen_amount(self):
if self.cleaned_data["cpu_credit_regen_amount"] < 0:
raise forms.ValidationError("Invalid amount")
return self.cleaned_data["cpu_credit_regen_amount"]

def save(self, commit=True):
super().save(commit=commit)
# If the cpu_credit_max_amount is changed, invalidate the cache
if 'cpu_credit_max_amount' in self.changed_data:
cache_keys_to_invalidate = [key.split(':')[-1] for key in cache._cache.keys() if TokenBucketThrottle.TOKENS_CACHE_PREFIX in key]
cache.delete_many(cache_keys_to_invalidate)
return self.instance


@admin.register(Group)
Expand Down
2 changes: 1 addition & 1 deletion drmaatic/job/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def delete_jobs_from_file_system(jobs):
@admin.register(Job)
class JobAdmin(admin.ModelAdmin):
class Media:
css = {'all': ('css/mymodel_list.css',)}
css = {'all': ('css/job-list-admin.css',)}

readonly_fields = ('uuid', 'task', 'creation_date', '_sender_ip_addr',
'_drm_job_id', 'parent_job', 'dependencies', 'dependency_type', '_files_name')
Expand Down
4 changes: 4 additions & 0 deletions drmaatic/job/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def delete_from_user(self):
self.deleted = True
self.save()

def delete(self, using=None, keep_parents=False):
self.delete_from_file_system()
super().delete(using, keep_parents)

def get_first_ancestor(self):
current_job = self
while current_job.parent_job is not None:
Expand Down
14 changes: 7 additions & 7 deletions drmaatic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ class Group(models.Model):
name = models.CharField(max_length=50)
has_full_access = models.BooleanField(default=False, blank=False, null=False)
throttling_rate_burst = models.CharField(max_length=30, default="10/s", null=False, blank=False)
token_renewal_time = models.CharField(default="1 day", null=False, blank=False, max_length=40)
cpu_credit_max_amount = models.IntegerField(default=100, blank=False, null=False)
_cpu_credit_regen_time = models.CharField(default="30 seconds", null=False, blank=False, max_length=40)
cpu_credit_regen_amount = models.IntegerField(default=1, blank=False, null=False)
token_renewal_time = models.CharField(default="1 day", null=False, blank=False, max_length=40, verbose_name="JWT renewal time")
cpu_credit_max_amount = models.IntegerField(default=100, blank=False, null=False, verbose_name="CPU credit max amount")
_cpu_credit_regen_time = models.CharField(default="30 seconds", null=False, blank=False, max_length=40, verbose_name="CPU credit regen time")
cpu_credit_regen_amount = models.IntegerField(default=1, blank=False, null=False, verbose_name="CPU credit regen amount")

@property
def cpu_credit_regen_time(self):
return timeparse(self._cpu_credit_regen_time)

@classproperty
def anonymous(self):
if table_exists('drmaatic_group', 'default'):
try:
return self.objects.get_or_create(name='anonymous', defaults={'throttling_rate_burst': '20/s',
'token_renewal_time': '3 days',
'cpu_credit_max_amount': 100})[0]
else:
except OperationalError:
return Group(name='anonymous', throttling_rate_burst='20/s', token_renewal_time='3 days',
cpu_credit_max_amount=100)

Expand Down Expand Up @@ -102,7 +102,7 @@ class User(models.Model):
# Defines whether the user is enabled
active = models.BooleanField(default=True, blank=False, null=False)

token_renewal_time = models.CharField(max_length=40, blank=True, null=True)
token_renewal_time = models.CharField(max_length=40, blank=True, null=True, verbose_name="JWT renewal time")

group = models.ForeignKey('Group', on_delete=models.SET_DEFAULT, null=False, default=Group.registered.id)

Expand Down
15 changes: 15 additions & 0 deletions drmaatic/static/css/admin-when-debug.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#header {
background-color: #ab3434;
}

.theme-toggle svg.theme-icon-when-auto, .theme-toggle svg.theme-icon-when-dark, .theme-toggle svg.theme-icon-when-light {
color: #ab3434 !important;
}

div.breadcrumbs {
background-color: #792424;
}

#site-name > a:after {
content: " DEBUG";
}
File renamed without changes.
Binary file added drmaatic/static/favicon/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions drmaatic/static/favicon/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions drmaatic/static/img/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 87f32f0

Please sign in to comment.