forked from openwisp/openwisp-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[admin] Removed logic duplicates openwisp#40
Removed the logics which were duplicated in the others modules and redefined it here to enable reusability and ease debugging. Fixes openwisp#40
- Loading branch information
1 parent
a194e80
commit d0f9dc3
Showing
12 changed files
with
150 additions
and
7 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
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,10 @@ | ||
django.jQuery(function ($) { | ||
"use strict"; | ||
var p = $('.field-receive_url p, .field-receive_url > div > div'), | ||
value = window.location.origin + p.text(); | ||
p.html('<input readonly id="id_receive_url" type="text" class="vTextField readonly" value="' + value + '">'); | ||
var field = $('#id_receive_url'); | ||
field.click(function () { | ||
$(this).select(); | ||
}); | ||
}; |
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,10 @@ | ||
django.jQuery(function ($) { | ||
"use strict"; | ||
var container = $('.field-uuid .readonly').eq(0), | ||
value = container.text(); | ||
container.html('<input readonly id="id_id" type="text" class="vTextField readonly" value="' + value + '">'); | ||
var id = $('#id_id'); | ||
id.click(function () { | ||
$(this).select(); | ||
}); | ||
}); |
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,8 @@ | ||
from django.utils.crypto import get_random_string | ||
|
||
|
||
def get_random_key(): | ||
""" | ||
generates a device key of 32 characters | ||
""" | ||
return get_random_string(length=32) |
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,8 @@ | ||
from django.core.validators import RegexValidator, _lazy_re_compile | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
key_validator = RegexValidator( | ||
_lazy_re_compile('^[^\s/\.]+$'), | ||
message=_('Key must not contain spaces, dots or slashes.'), | ||
code='invalid', | ||
) |
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,27 @@ | ||
# Generated by Django 2.0.13 on 2019-04-21 19:50 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
import openwisp_utils.utils | ||
import re | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('test_project', '0003_project_operator'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='project', | ||
name='key', | ||
field=models.CharField(db_index=True, default=openwisp_utils.utils.get_random_key, help_text='unique device key', max_length=64, unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[^\\s/\\.]+$'), code='invalid', message='Key must not contain spaces, dots or slashes.')]), | ||
), | ||
migrations.AlterField( | ||
model_name='project', | ||
name='id', | ||
field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False), | ||
), | ||
] |
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,22 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase | ||
|
||
from ..models import Project | ||
|
||
|
||
class TestModel(TestCase): | ||
TEST_KEY = 'w1gwJxKaHcamUw62TQIPgYchwLKn3AA0' | ||
|
||
def test_key_validator(self): | ||
p = Project.objects.create(name='test_project') | ||
p.key = 'key/key' | ||
with self.assertRaises(ValidationError): | ||
p.full_clean() | ||
p.key = 'key.key' | ||
with self.assertRaises(ValidationError): | ||
p.full_clean() | ||
p.key = 'key key' | ||
with self.assertRaises(ValidationError): | ||
p.full_clean() | ||
p.key = self.TEST_KEY | ||
p.full_clean() |