-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
1 parent
8b03012
commit 2cb2ccd
Showing
19 changed files
with
80 additions
and
178 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ dist/ | |
test.db | ||
.tox | ||
.coverage | ||
coverage.xml | ||
docs/_build | ||
.idea |
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 |
---|---|---|
@@ -1,45 +1,9 @@ | ||
from django.db.models import signals | ||
from django.apps import apps, AppConfig | ||
from django.apps import AppConfig | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class ConstanceConfig(AppConfig): | ||
name = 'constance' | ||
verbose_name = _('Constance') | ||
default_auto_field = 'django.db.models.AutoField' | ||
|
||
def ready(self): | ||
super().ready() | ||
signals.post_migrate.connect(self.create_perm, | ||
dispatch_uid='constance.create_perm') | ||
|
||
def create_perm(self, using=None, *args, **kwargs): | ||
""" | ||
Creates a fake content type and permission | ||
to be able to check for permissions | ||
""" | ||
from django.conf import settings | ||
|
||
constance_dbs = getattr(settings, 'CONSTANCE_DBS', None) | ||
if constance_dbs is not None and using not in constance_dbs: | ||
return | ||
if ( | ||
apps.is_installed('django.contrib.contenttypes') and | ||
apps.is_installed('django.contrib.auth') | ||
): | ||
ContentType = apps.get_model('contenttypes.ContentType') | ||
Permission = apps.get_model('auth.Permission') | ||
content_type, created = ContentType.objects.using(using).get_or_create( | ||
app_label='constance', | ||
model='config', | ||
) | ||
|
||
Permission.objects.using(using).get_or_create( | ||
content_type=content_type, | ||
codename='change_config', | ||
defaults={'name': 'Can change config'}, | ||
) | ||
Permission.objects.using(using).get_or_create( | ||
content_type=content_type, | ||
codename='view_config', | ||
defaults={'name': 'Can view config'}, | ||
) |
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 was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
constance/backends/database/migrations/0002_auto_20190129_2304.py
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
15 changes: 8 additions & 7 deletions
15
...kends/database/migrations/0001_initial.py → constance/migrations/0001_initial.py
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 |
---|---|---|
@@ -1,24 +1,25 @@ | ||
from django.db import models, migrations | ||
from django.db import migrations, models | ||
import picklefield.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Constance', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', primary_key=True, | ||
auto_created=True, serialize=False)), | ||
('key', models.CharField(unique=True, max_length=255)), | ||
('value', picklefield.fields.PickledObjectField(editable=False)), | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('key', models.CharField(max_length=255, unique=True)), | ||
('value', picklefield.fields.PickledObjectField(blank=True, editable=False, null=True)), | ||
], | ||
options={ | ||
'verbose_name': 'constance', | ||
'verbose_name_plural': 'constances', | ||
'db_table': 'constance_config', | ||
'permissions': [('change_config', 'Can change config'), ('view_config', 'Can view config')], | ||
}, | ||
bases=(models.Model,), | ||
), | ||
] |
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,33 @@ | ||
from django.core.management.color import no_style | ||
from django.db import migrations, connection, DatabaseError | ||
|
||
|
||
def _migrate_from_old_table(apps, schema_editor) -> None: | ||
""" | ||
Copies values from old table. | ||
On new installations just ignore error that table does not exist. | ||
""" | ||
try: | ||
with connection.cursor() as cursor: | ||
cursor.execute('INSERT INTO constance_constance ( id, key, value ) SELECT id, key, value FROM constance_config', []) | ||
cursor.execute('DROP TABLE constance_config', []) | ||
|
||
except DatabaseError: | ||
pass | ||
|
||
Constance = apps.get_model('constance', 'Constance') | ||
sequence_sql = connection.ops.sequence_reset_sql(no_style(), [Constance]) | ||
with connection.cursor() as cursor: | ||
for sql in sequence_sql: | ||
cursor.execute(sql) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [('constance', '0001_initial')] | ||
|
||
atomic = False | ||
|
||
operations = [ | ||
migrations.RunPython(_migrate_from_old_table, reverse_code=lambda x, y: None), | ||
] |
File renamed without changes.
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.