From ac139c8a9906b8d86d7d77a888a351717d78acfa Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 21 Jan 2021 20:46:12 +0530 Subject: [PATCH 1/3] Register UserHostingKey to admin site and add str repr --- datacenterlight/admin.py | 2 ++ hosting/models.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/datacenterlight/admin.py b/datacenterlight/admin.py index 5a1fc8a2..334a6c06 100644 --- a/datacenterlight/admin.py +++ b/datacenterlight/admin.py @@ -3,6 +3,7 @@ from cms.admin.placeholderadmin import PlaceholderAdminMixin from cms.extensions import PageExtensionAdmin from .cms_models import CMSIntegration, CMSFaviconExtension from .models import VMPricing, VMTemplate +from hosting.models import UserHostingKey class CMSIntegrationAdmin(PlaceholderAdminMixin, admin.ModelAdmin): @@ -17,3 +18,4 @@ admin.site.register(CMSIntegration, CMSIntegrationAdmin) admin.site.register(CMSFaviconExtension, CMSFaviconExtensionAdmin) admin.site.register(VMPricing) admin.site.register(VMTemplate) +admin.site.register(UserHostingKey) diff --git a/hosting/models.py b/hosting/models.py index 48238afe..b7175af5 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -208,6 +208,16 @@ class UserHostingKey(models.Model): created_at = models.DateTimeField(auto_now_add=True) name = models.CharField(max_length=100) + def __str__(self): + display_str = '%s - %s - %s - %s - %s' % ( + self.user.username, + self.user.email, + self.name, + self.created_at, + self.public_key + ) + return display_str + @staticmethod def generate_RSA(bits=2048): ''' From c6f05889ff2384589fbeb7dabb16b87cbcfcfa39 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 22 Jan 2021 08:08:40 +0530 Subject: [PATCH 2/3] Modify admin template to include table wrap styles --- .../datacenterlight/admin/base_site.html | 18 ++++++++++++++++++ dynamicweb/settings/base.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 datacenterlight/templates/datacenterlight/admin/base_site.html diff --git a/datacenterlight/templates/datacenterlight/admin/base_site.html b/datacenterlight/templates/datacenterlight/admin/base_site.html new file mode 100644 index 00000000..00e31c8f --- /dev/null +++ b/datacenterlight/templates/datacenterlight/admin/base_site.html @@ -0,0 +1,18 @@ +{% extends "admin/base_site.html" %} +{% block extrahead %} + +{% endblock %} \ No newline at end of file diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 03013ea5..13362fba 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -81,7 +81,6 @@ INSTALLED_APPS = ( # 1st migrate 'membership', 'djangocms_admin_style', - 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.humanize', @@ -154,6 +153,7 @@ INSTALLED_APPS = ( 'opennebula_api', 'django_celery_results', 'webhook', + 'django.contrib.admin', ) MIDDLEWARE_CLASSES = ( From e51af13a3153d5ba9952ff4b9e54617e29ffd456 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 22 Jan 2021 22:41:56 +0530 Subject: [PATCH 3/3] Change the str repr --- dynamicweb/settings/base.py | 3 ++- hosting/models.py | 15 ++++++++++++--- .../admin/base_site.html | 0 3 files changed, 14 insertions(+), 4 deletions(-) rename {datacenterlight/templates/datacenterlight => templates}/admin/base_site.html (100%) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 13362fba..a88938ce 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -79,6 +79,7 @@ SECRET_KEY = env('DJANGO_SECRET_KEY') INSTALLED_APPS = ( # 1st migrate + 'hosting', 'membership', 'djangocms_admin_style', 'django.contrib.auth', @@ -143,7 +144,6 @@ INSTALLED_APPS = ( # ungleich 'ungleich', 'ungleich_page', - 'hosting', 'digitalglarus', 'nosystemd', 'datacenterlight', @@ -196,6 +196,7 @@ TEMPLATES = [ os.path.join(PROJECT_DIR, 'cms_templates/'), os.path.join(PROJECT_DIR, 'cms_templates/djangocms_blog/'), os.path.join(PROJECT_DIR, 'templates/gdpr'), + os.path.join(PROJECT_DIR, 'templates'), ], 'APP_DIRS': True, 'OPTIONS': { diff --git a/hosting/models.py b/hosting/models.py index b7175af5..16297ab8 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -209,9 +209,18 @@ class UserHostingKey(models.Model): name = models.CharField(max_length=100) def __str__(self): - display_str = '%s - %s - %s - %s - %s' % ( - self.user.username, - self.user.email, + username = "None" + email = "None" + if self.user: + username = self.user.username + email = self.user.email + display_str = '''Username: %s, +Email: %s, +Key name: %s, +Created at: %s, +Public Key: %s''' % ( + username, + email, self.name, self.created_at, self.public_key diff --git a/datacenterlight/templates/datacenterlight/admin/base_site.html b/templates/admin/base_site.html similarity index 100% rename from datacenterlight/templates/datacenterlight/admin/base_site.html rename to templates/admin/base_site.html