Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
[openwisp-utils] Moved shared logic to openwisp-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Jul 5, 2017
1 parent bd3ab20 commit 0dcc71d
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 294 deletions.
Empty file.
13 changes: 0 additions & 13 deletions django_netjsonconfig/admin_theme/admin.py

This file was deleted.

102 changes: 0 additions & 102 deletions django_netjsonconfig/admin_theme/static/admin/css/openwisp.css

This file was deleted.

Binary file not shown.

This file was deleted.

15 changes: 0 additions & 15 deletions django_netjsonconfig/admin_theme/templates/admin/base_site.html

This file was deleted.

2 changes: 0 additions & 2 deletions django_netjsonconfig/admin_theme/templates/base.html

This file was deleted.

16 changes: 4 additions & 12 deletions django_netjsonconfig/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _

from openwisp_utils.admin import TimeReadonlyAdminMixin

from .. import settings as app_settings
from ..utils import send_file
from ..widgets import JsonSchemaWidget
Expand All @@ -25,17 +27,7 @@
from django.contrib.admin import ModelAdmin


class TimeReadonlyMixin(object):
"""
mixin that automatically flags
`created` and `modified` as readonly
"""
def __init__(self, *args, **kwargs):
self.readonly_fields += ('created', 'modified',)
super(TimeReadonlyMixin, self).__init__(*args, **kwargs)


class BaseAdmin(TimeReadonlyMixin, ModelAdmin):
class BaseAdmin(TimeReadonlyAdminMixin, ModelAdmin):
pass


Expand Down Expand Up @@ -231,7 +223,7 @@ def clean_templates(self):
return templates


class AbstractConfigInline(TimeReadonlyMixin, admin.StackedInline):
class AbstractConfigInline(TimeReadonlyAdminMixin, admin.StackedInline):
verbose_name_plural = _('Device configuration details')
readonly_fields = ['status', 'last_ip']
fields = ['backend',
Expand Down
8 changes: 2 additions & 6 deletions django_netjsonconfig/base/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import collections
import hashlib
import json
import uuid
from copy import deepcopy

from django.core.exceptions import ValidationError
Expand All @@ -11,22 +10,19 @@
from django.utils.module_loading import import_string
from django.utils.translation import ugettext_lazy as _
from jsonfield import JSONField
from model_utils.fields import AutoCreatedField, AutoLastModifiedField

from netjsonconfig.exceptions import ValidationError as SchemaError
from openwisp_utils.base import TimeStampedEditableModel

from .. import settings as app_settings


@python_2_unicode_compatible
class BaseModel(models.Model):
class BaseModel(TimeStampedEditableModel):
"""
Shared logic
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=64, unique=True, db_index=True)
created = AutoCreatedField(_('created'), editable=True)
modified = AutoLastModifiedField(_('modified'), editable=True)

class Meta:
abstract = True
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ django-sortedm2m>=1.3.2,<1.4
django-reversion>=2.0.6,<2.1
django-x509>=0.2.0,<0.3.0
django-taggit>=0.22.1,<0.23.0
openwisp-utils<0.2
1 change: 0 additions & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django_netjsonconfig',
'django_netjsonconfig.admin_theme',
'django.contrib.admin',
'sortedm2m',
'reversion',
Expand Down
5 changes: 1 addition & 4 deletions tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from django_netjsonconfig.admin_theme.admin import admin, openwisp_admin

openwisp_admin()

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
# controller URLs
Expand Down

0 comments on commit 0dcc71d

Please sign in to comment.