summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-02-17 12:55:07 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-02-17 12:55:07 +0100
commitb3856fc87277daa856292b71b51381f139c2fdf3 (patch)
tree5e80fbe23775e8bfe2986f9201c6e32005c2f7ec
parent6f080a33d88f8245bbd26f917fcce5c58d9f62f7 (diff)
downloadIshtar-b3856fc87277daa856292b71b51381f139c2fdf3.tar.bz2
Ishtar-b3856fc87277daa856292b71b51381f139c2fdf3.zip
Fix cache for multiple instance of ishtar - Database changes for managing modules via profile
-rw-r--r--example_project/local_settings.py.sample10
-rw-r--r--example_project/settings.py18
-rw-r--r--ishtar_common/admin.py8
-rw-r--r--ishtar_common/migrations/0048_auto__add_ishtarsiteprofile.py374
-rw-r--r--ishtar_common/models.py92
-rw-r--r--ishtar_common/tests.py126
-rw-r--r--ishtar_common/utils.py3
7 files changed, 538 insertions, 93 deletions
diff --git a/example_project/local_settings.py.sample b/example_project/local_settings.py.sample
index dae6f98b5..942a35df5 100644
--- a/example_project/local_settings.py.sample
+++ b/example_project/local_settings.py.sample
@@ -34,6 +34,7 @@ DEBUG_TOOLBAR = False
TEMPLATE_DEBUG = DEBUG
SQL_DEBUG = False
+# important to change on a server hosting multiple ishtar instances
PROJECT_SLUG = "my-project"
# complete with host/domain names that this website can serve
@@ -51,12 +52,3 @@ SRID = 27572
ENCODING = '' # specific encoding for CSV export - default to utf-8
SURFACE_UNIT = 'square-metre'
SURFACE_UNIT_LABEL = u'm²'
-
-# choose the extensions to install
-# you can remove lines according to the comments but don't change the order
-EXTRA_APPS = [
- 'archaeological_files',
- 'archaeological_context_records',
- 'archaeological_warehouse', # need archaeological_finds
- 'archaeological_finds', # need archaeological_context_records
-]
diff --git a/example_project/settings.py b/example_project/settings.py
index e124198aa..4b91c554f 100644
--- a/example_project/settings.py
+++ b/example_project/settings.py
@@ -128,8 +128,14 @@ INSTALLED_APPS = [
'south',
'registration',
# 'geodjangofla',
+ 'ishtar_pdl',
'ishtar_common',
- 'archaeological_operations', # mandatory app to run ishtar
+ 'archaeological_files_pdl',
+ 'archaeological_files',
+ 'archaeological_operations',
+ 'archaeological_context_records',
+ 'archaeological_warehouse',
+ 'archaeological_finds',
# 'django_extensions',
# 'debug_toolbar',
]
@@ -214,16 +220,6 @@ except ImportError, e:
if 'test' in sys.argv:
SOUTH_TESTS_MIGRATE = False
-for app in PRE_APPS:
- INSTALLED_APPS.insert(INSTALLED_APPS.index('ishtar_common'), app)
-
-if 'archaeological_files' in EXTRA_APPS:
- EXTRA_APPS.pop(EXTRA_APPS.index('archaeological_files'))
- INSTALLED_APPS.insert(INSTALLED_APPS.index('archaeological_operations'),
- 'archaeological_files')
-
-INSTALLED_APPS += EXTRA_APPS
-
PROJECT_SLUG = locals().get('PROJECT_SLUG', 'default')
if LOGFILE:
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index f8cc34208..b7ad530b7 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -93,6 +93,14 @@ admin.site.unregister(Group)
admin.site.register(Group, MyGroupAdmin)
+class IshtarSiteProfileAdmin(admin.ModelAdmin):
+ list_display = ('label', 'slug', 'active', 'files', 'context_record',
+ 'find', 'warehouse')
+ model = models.IshtarSiteProfile
+
+admin.site.register(models.IshtarSiteProfile, IshtarSiteProfileAdmin)
+
+
class DepartmentAdmin(admin.ModelAdmin):
list_display = ('number', 'label',)
model = models.Department
diff --git a/ishtar_common/migrations/0048_auto__add_ishtarsiteprofile.py b/ishtar_common/migrations/0048_auto__add_ishtarsiteprofile.py
new file mode 100644
index 000000000..5a2c21bf1
--- /dev/null
+++ b/ishtar_common/migrations/0048_auto__add_ishtarsiteprofile.py
@@ -0,0 +1,374 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'IshtarSiteProfile'
+ db.create_table('ishtar_common_ishtarsiteprofile', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('label', self.gf('django.db.models.fields.TextField')()),
+ ('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50)),
+ ('description', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
+ ('files', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('context_record', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('find', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('warehouse', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('active', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ))
+ db.send_create_signal('ishtar_common', ['IshtarSiteProfile'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'IshtarSiteProfile'
+ db.delete_table('ishtar_common_ishtarsiteprofile')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'ishtar_common.arrondissement': {
+ 'Meta': {'object_name': 'Arrondissement'},
+ 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Department']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '30'})
+ },
+ 'ishtar_common.author': {
+ 'Meta': {'object_name': 'Author'},
+ 'author_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.AuthorType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'person': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'author'", 'to': "orm['ishtar_common.Person']"})
+ },
+ 'ishtar_common.authortype': {
+ 'Meta': {'object_name': 'AuthorType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
+ },
+ 'ishtar_common.canton': {
+ 'Meta': {'object_name': 'Canton'},
+ 'arrondissement': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Arrondissement']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '30'})
+ },
+ 'ishtar_common.department': {
+ 'Meta': {'ordering': "['number']", 'object_name': 'Department'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
+ 'number': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '3'}),
+ 'state': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.State']", 'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.documenttemplate': {
+ 'Meta': {'ordering': "['associated_object_name', 'name']", 'object_name': 'DocumentTemplate'},
+ 'associated_object_name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'template': ('django.db.models.fields.files.FileField', [], {'max_length': '100'})
+ },
+ 'ishtar_common.format': {
+ 'Meta': {'object_name': 'Format'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
+ },
+ 'ishtar_common.formatertype': {
+ 'Meta': {'ordering': "('formater_type', 'options')", 'unique_together': "(('formater_type', 'options', 'many_split'),)", 'object_name': 'FormaterType'},
+ 'formater_type': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'many_split': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'options': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.globalvar': {
+ 'Meta': {'ordering': "['slug']", 'object_name': 'GlobalVar'},
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),
+ 'value': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.historicalorganization': {
+ 'Meta': {'ordering': "('-history_date', '-history_id')", 'object_name': 'HistoricalOrganization'},
+ 'address': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'address_complement': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'country': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'exclude_from_merge': ('django.db.models.fields.NullBooleanField', [], {'default': 'False', 'null': 'True', 'blank': 'True'}),
+ 'history_creator_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'history_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'history_id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'history_modifier_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'history_type': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
+ 'history_user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+ 'id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'blank': 'True'}),
+ 'merge_key': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'mobile_phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
+ 'organization_type_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'postal_code': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'town': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.import': {
+ 'Meta': {'object_name': 'Import'},
+ 'conservative_import': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+ 'encoding': ('django.db.models.fields.CharField', [], {'default': "'utf-8'", 'max_length': '15'}),
+ 'end_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'error_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'imported_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+ 'imported_images': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'importer_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.ImporterType']"}),
+ 'match_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'result_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'seconds_remaining': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'skip_lines': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
+ 'state': ('django.db.models.fields.CharField', [], {'default': "'C'", 'max_length': '2'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.IshtarUser']"})
+ },
+ 'ishtar_common.importercolumn': {
+ 'Meta': {'ordering': "('importer_type', 'col_number')", 'unique_together': "(('importer_type', 'col_number'),)", 'object_name': 'ImporterColumn'},
+ 'col_number': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'importer_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'columns'", 'to': "orm['ishtar_common.ImporterType']"}),
+ 'regexp_pre_filter': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Regexp']", 'null': 'True', 'blank': 'True'}),
+ 'required': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ 'ishtar_common.importerdefault': {
+ 'Meta': {'object_name': 'ImporterDefault'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'importer_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'defaults'", 'to': "orm['ishtar_common.ImporterType']"}),
+ 'target': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'ishtar_common.importerdefaultvalues': {
+ 'Meta': {'object_name': 'ImporterDefaultValues'},
+ 'default_target': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'default_values'", 'to': "orm['ishtar_common.ImporterDefault']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'target': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+ 'value': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'ishtar_common.importerduplicatefield': {
+ 'Meta': {'object_name': 'ImporterDuplicateField'},
+ 'column': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'duplicate_fields'", 'to': "orm['ishtar_common.ImporterColumn']"}),
+ 'concat': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'concat_str': ('django.db.models.fields.CharField', [], {'max_length': '5', 'null': 'True', 'blank': 'True'}),
+ 'field_name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'force_new': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ 'ishtar_common.importertype': {
+ 'Meta': {'object_name': 'ImporterType'},
+ 'associated_models': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_template': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '100', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ 'unicity_keys': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ 'users': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['ishtar_common.IshtarUser']", 'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.importtarget': {
+ 'Meta': {'object_name': 'ImportTarget'},
+ 'column': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'targets'", 'to': "orm['ishtar_common.ImporterColumn']"}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'concat': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'concat_str': ('django.db.models.fields.CharField', [], {'max_length': '5', 'null': 'True', 'blank': 'True'}),
+ 'force_new': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'formater_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.FormaterType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'regexp_filter': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Regexp']", 'null': 'True', 'blank': 'True'}),
+ 'target': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'ishtar_common.ishtarsiteprofile': {
+ 'Meta': {'ordering': "['label']", 'object_name': 'IshtarSiteProfile'},
+ 'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'context_record': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'files': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'find': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.TextField', [], {}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),
+ 'warehouse': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ 'ishtar_common.ishtaruser': {
+ 'Meta': {'object_name': 'IshtarUser', '_ormbases': ['auth.User']},
+ 'person': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'ishtaruser'", 'unique': 'True', 'to': "orm['ishtar_common.Person']"}),
+ 'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ 'ishtar_common.itemkey': {
+ 'Meta': {'object_name': 'ItemKey'},
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'importer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Import']", 'null': 'True', 'blank': 'True'}),
+ 'key': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {})
+ },
+ 'ishtar_common.operationtype': {
+ 'Meta': {'ordering': "['-preventive', 'order', 'label']", 'object_name': 'OperationType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
+ 'preventive': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
+ },
+ 'ishtar_common.organization': {
+ 'Meta': {'object_name': 'Organization'},
+ 'address': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'address_complement': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'country': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'exclude_from_merge': ('django.db.models.fields.NullBooleanField', [], {'default': 'False', 'null': 'True', 'blank': 'True'}),
+ 'history_creator': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['auth.User']"}),
+ 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['auth.User']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'imports': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'imported_ishtar_common_organization'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['ishtar_common.Import']"}),
+ 'merge_candidate': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'merge_candidate_rel_+'", 'null': 'True', 'to': "orm['ishtar_common.Organization']"}),
+ 'merge_exclusion': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'merge_exclusion_rel_+'", 'null': 'True', 'to': "orm['ishtar_common.Organization']"}),
+ 'merge_key': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'mobile_phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
+ 'organization_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.OrganizationType']"}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'postal_code': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'town': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.organizationtype': {
+ 'Meta': {'ordering': "('label',)", 'object_name': 'OrganizationType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
+ },
+ 'ishtar_common.person': {
+ 'Meta': {'object_name': 'Person'},
+ 'address': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'address_complement': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'attached_to': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'members'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['ishtar_common.Organization']"}),
+ 'country': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'exclude_from_merge': ('django.db.models.fields.NullBooleanField', [], {'default': 'False', 'null': 'True', 'blank': 'True'}),
+ 'history_creator': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['auth.User']"}),
+ 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['auth.User']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'imports': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'imported_ishtar_common_person'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['ishtar_common.Import']"}),
+ 'merge_candidate': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'merge_candidate_rel_+'", 'null': 'True', 'to': "orm['ishtar_common.Person']"}),
+ 'merge_exclusion': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'merge_exclusion_rel_+'", 'null': 'True', 'to': "orm['ishtar_common.Person']"}),
+ 'merge_key': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'mobile_phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'person_types': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ishtar_common.PersonType']", 'symmetrical': 'False'}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'postal_code': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'raw_name': ('django.db.models.fields.CharField', [], {'max_length': '300', 'null': 'True', 'blank': 'True'}),
+ 'surname': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'town': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.persontype': {
+ 'Meta': {'ordering': "('label',)", 'object_name': 'PersonType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['auth.Group']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
+ },
+ 'ishtar_common.regexp': {
+ 'Meta': {'object_name': 'Regexp'},
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'regexp': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'ishtar_common.sourcetype': {
+ 'Meta': {'object_name': 'SourceType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
+ },
+ 'ishtar_common.state': {
+ 'Meta': {'ordering': "['number']", 'object_name': 'State'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
+ 'number': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '3'})
+ },
+ 'ishtar_common.supporttype': {
+ 'Meta': {'object_name': 'SupportType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
+ },
+ 'ishtar_common.targetkey': {
+ 'Meta': {'unique_together': "(('target', 'key', 'associated_user', 'associated_import'),)", 'object_name': 'TargetKey'},
+ 'associated_import': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Import']", 'null': 'True', 'blank': 'True'}),
+ 'associated_user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.IshtarUser']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_set': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'key': ('django.db.models.fields.TextField', [], {}),
+ 'target': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'keys'", 'to': "orm['ishtar_common.ImportTarget']"}),
+ 'value': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.town': {
+ 'Meta': {'ordering': "['numero_insee']", 'object_name': 'Town'},
+ 'canton': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Canton']", 'null': 'True', 'blank': 'True'}),
+ 'center': ('django.contrib.gis.db.models.fields.PointField', [], {'srid': '27572', 'null': 'True', 'blank': 'True'}),
+ 'departement': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Department']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'numero_insee': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '6'}),
+ 'surface': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['ishtar_common'] \ No newline at end of file
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index d7e63856b..bcd1881d6 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -249,7 +249,21 @@ class OwnPerms:
return cls.objects.filter(query).order_by(*cls._meta.ordering)
-class GeneralType(models.Model):
+class Cached(object):
+ @classmethod
+ def get_cache(cls, slug):
+ cache_key, value = get_cache(cls, slug)
+ if value:
+ return value
+ try:
+ obj = cls.objects.get(txt_idx=slug)
+ cache.set(cache_key, obj, settings.CACHE_TIMEOUT)
+ return obj
+ except cls.DoesNotExist:
+ return None
+
+
+class GeneralType(models.Model, Cached):
"""
Abstract class for "types"
"""
@@ -457,18 +471,6 @@ class GeneralType(models.Model):
for item in cls.objects.all():
item.generate_key()
- @classmethod
- def get_cache(cls, slug):
- cache_key, value = get_cache(cls, slug)
- if value:
- return value
- try:
- obj = cls.objects.get(txt_idx=slug)
- cache.set(cache_key, obj, settings.CACHE_TIMEOUT)
- return obj
- except cls.DoesNotExist:
- return None
-
class ItemKey(models.Model):
key = models.CharField(_(u"Key"), max_length=100)
@@ -765,7 +767,57 @@ class LightHistorizedItem(BaseHistorizedItem):
return True
-class GlobalVar(models.Model):
+class IshtarSiteProfile(models.Model, Cached):
+ label = models.TextField(_(u"Name"))
+ slug = models.SlugField(_(u"Slug"), unique=True)
+ description = models.TextField(_(u"Description"), null=True, blank=True)
+ files = models.BooleanField(_(u"Files module"), default=False)
+ context_record = models.BooleanField(_(u"Context records module"),
+ default=False)
+ find = models.BooleanField(_(u"Finds module"), default=False,
+ help_text=_(u"Need context records module"))
+ warehouse = models.BooleanField(
+ _(u"Warehouses module"), default=False,
+ help_text=_(u"Need finds module"))
+ active = models.BooleanField(_(u"Current active"), default=False)
+
+ class Meta:
+ verbose_name = _(u"Ishtar site profile")
+ verbose_name_plural = _(u"Ishtar site profiles")
+ ordering = ['label']
+
+ def __unicode__(self):
+ return unicode(self.label)
+
+ def save(self, *args, **kwargs):
+ raw = False
+ if 'raw' in kwargs:
+ raw = kwargs.pop('raw')
+ super(IshtarSiteProfile, self).save(*args, **kwargs)
+ obj = self
+ if raw:
+ return obj
+ q = self.__class__.objects.filter(active=True).exclude(pk=self.pk)
+ if obj.active and q.count():
+ for profile in q.all():
+ profile.active = False
+ profile.save(raw=True)
+ changed = False
+ if not obj.active and not q.count():
+ obj.active = True
+ changed = True
+ if obj.warehouse and not obj.find:
+ obj.find = True
+ changed = True
+ if obj.find and not obj.context_record:
+ obj.context_record = True
+ changed = True
+ if changed:
+ obj = obj.save(raw=True)
+ return obj
+
+
+class GlobalVar(models.Model, Cached):
slug = models.SlugField(_(u"Variable name"), unique=True)
description = models.TextField(_(u"Description of the variable"),
null=True, blank=True)
@@ -779,18 +831,6 @@ class GlobalVar(models.Model):
def __unicode__(self):
return unicode(self.slug)
- @classmethod
- def get_cache(cls, slug):
- cache_key, value = get_cache(cls, slug)
- if value:
- return value
- try:
- obj = cls.objects.get(slug=slug)
- cache.set(cache_key, obj.value, settings.CACHE_TIMEOUT)
- return obj.value
- except cls.DoesNotExist:
- return None
-
def cached_globalvar_changed(sender, **kwargs):
if not kwargs['instance']:
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 621b05242..4e800b0d5 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -17,10 +17,6 @@
# See the file COPYING for details.
-import tempfile, datetime
-from zipfile import ZipFile, ZIP_DEFLATED
-
-from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.template.defaultfilters import slugify
@@ -29,6 +25,10 @@ from django.test import TestCase
from ishtar_common import models
"""
+from django.conf import settings
+import tempfile, datetime
+from zipfile import ZipFile, ZIP_DEFLATED
+
from oook_replace.oook_replace import oook_replace
class OOOGenerationTest(TestCase):
@@ -53,34 +53,36 @@ class OOOGenerationTest(TestCase):
class MergeTest(TestCase):
def setUp(self):
self.user, created = User.objects.get_or_create(username='username')
- self.organisation_types = models.OrganizationType.create_default_for_test()
+ self.organisation_types = \
+ models.OrganizationType.create_default_for_test()
self.person_types = [models.PersonType.objects.create(label='Admin'),
models.PersonType.objects.create(label='User')]
self.author_types = [models.AuthorType.objects.create(label='1'),
- models.AuthorType.objects.create(label='2'),]
+ models.AuthorType.objects.create(label='2')]
self.company_1 = models.Organization.objects.create(
- history_modifier=self.user, name='Franquin Comp.',
- organization_type=self.organisation_types[0])
- self.person_1 = models.Person.objects.create(name='Boule',
- surname=' ',
- history_modifier=self.user, attached_to=self.company_1)
+ history_modifier=self.user, name='Franquin Comp.',
+ organization_type=self.organisation_types[0])
+ self.person_1 = models.Person.objects.create(
+ name='Boule', surname=' ', history_modifier=self.user,
+ attached_to=self.company_1)
self.person_1.person_types.add(self.person_types[0])
- self.author_1_pk = models.Author.objects.create(person=self.person_1,
- author_type=self.author_types[0]).pk
+ self.author_1_pk = models.Author.objects.create(
+ person=self.person_1, author_type=self.author_types[0]).pk
self.company_2 = models.Organization.objects.create(
- history_modifier=self.user, name='Goscinny Corp.',
- organization_type=self.organisation_types[1])
- self.person_2 = models.Person.objects.create(name='Bill',
- history_modifier=self.user, surname='Peyo', title='Mr',
- attached_to=self.company_2)
+ history_modifier=self.user, name='Goscinny Corp.',
+ organization_type=self.organisation_types[1])
+ self.person_2 = models.Person.objects.create(
+ name='Bill', history_modifier=self.user, surname='Peyo',
+ title='Mr', attached_to=self.company_2)
self.person_2.person_types.add(self.person_types[1])
- self.author_2_pk = models.Author.objects.create(person=self.person_2,
- author_type=self.author_types[1]).pk
- self.person_3 = models.Person.objects.create(name='George',
- history_modifier=self.user, attached_to=self.company_1)
+ self.author_2_pk = models.Author.objects.create(
+ person=self.person_2, author_type=self.author_types[1]).pk
+ self.person_3 = models.Person.objects.create(
+ name='George', history_modifier=self.user,
+ attached_to=self.company_1)
def testPersonMerge(self):
self.person_1.merge(self.person_2)
@@ -93,9 +95,11 @@ class MergeTest(TestCase):
# preserve existing foreign key
self.assertEqual(self.person_1.attached_to, self.company_1)
# preserve existing many to many
- self.assertTrue(self.person_types[0] in self.person_1.person_types.all())
+ self.assertTrue(self.person_types[0]
+ in self.person_1.person_types.all())
# add new many to many
- self.assertTrue(self.person_types[1] in self.person_1.person_types.all())
+ self.assertTrue(self.person_types[1]
+ in self.person_1.person_types.all())
# update reverse foreign key association and dont break the existing
self.assertEqual(models.Author.objects.get(pk=self.author_1_pk).person,
self.person_1)
@@ -104,32 +108,37 @@ class MergeTest(TestCase):
self.person_3.merge(self.person_1)
# manage well empty many to many fields
- self.assertTrue(self.person_types[1] in self.person_3.person_types.all())
+ self.assertTrue(self.person_types[1]
+ in self.person_3.person_types.all())
+
class ImportKeyTest(TestCase):
def testKeys(self):
- content_type = ContentType.objects.get_for_model(models.OrganizationType)
+ content_type = ContentType.objects.get_for_model(
+ models.OrganizationType)
# creation
label = u"Ploufé"
ot = models.OrganizationType.objects.create(label=label)
- self.assertEqual(models.ItemKey.objects.filter(object_id=ot.pk,
- key=slugify(label),
- content_type=content_type).count(), 1)
+ self.assertEqual(models.ItemKey.objects.filter(
+ object_id=ot.pk, key=slugify(label),
+ content_type=content_type).count(), 1)
label_2 = u"Plif"
ot_2 = models.OrganizationType.objects.create(label=label_2)
- self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk,
- key=slugify(label_2),
- content_type=content_type).count(), 1)
+ self.assertEqual(models.ItemKey.objects.filter(
+ object_id=ot_2.pk, key=slugify(label_2),
+ content_type=content_type).count(), 1)
# replace key
ot_2.add_key(slugify(label), force=True)
# one key point to only one item
- self.assertEqual(models.ItemKey.objects.filter(key=slugify(label),
- content_type=content_type).count(), 1)
+ self.assertEqual(models.ItemKey.objects.filter(
+ key=slugify(label),
+ content_type=content_type).count(), 1)
# this key point to the right item
- self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk,
- key=slugify(label), content_type=content_type).count(), 1)
+ self.assertEqual(models.ItemKey.objects.filter(
+ object_id=ot_2.pk, key=slugify(label),
+ content_type=content_type).count(), 1)
# modification
label_3 = "Yop"
@@ -137,14 +146,39 @@ class ImportKeyTest(TestCase):
ot_2.txt_idx = slugify(label_3)
ot_2.save()
# old label not referenced anymore
- self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk,
- key=slugify(label_2), content_type=content_type).count(), 0)
- # forced key association is always here
- self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk,
- key=slugify(label), content_type=content_type).count(), 1)
+ self.assertEqual(models.ItemKey.objects.filter(
+ object_id=ot_2.pk, key=slugify(label_2),
+ content_type=content_type).count(), 0)
+ # # forced key association is always here
# new key is here
- self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk,
- key=slugify(label_3), content_type=content_type).count(), 1)
-
-
-
+ self.assertEqual(models.ItemKey.objects.filter(
+ object_id=ot_2.pk, key=slugify(label),
+ content_type=content_type).count(), 1)
+ self.assertEqual(models.ItemKey.objects.filter(
+ object_id=ot_2.pk, key=slugify(label_3),
+ content_type=content_type).count(), 1)
+
+
+class IshtarSiteProfileTest(TestCase):
+ def testRelevance(self):
+ profile = models.IshtarSiteProfile.objects.create(
+ label="Test profile", slug='test-profile')
+ profile2 = models.IshtarSiteProfile.objects.create(
+ label="Test profile 2", slug='test-profile-2')
+ # when no profile is the current, activate by default the first created
+ self.assertTrue(profile.active and not profile2.active)
+ profile2.active = True
+ profile2 = profile2.save()
+ profile = models.IshtarSiteProfile.objects.get(slug='test-profile')
+ # only one profile active at a time
+ self.assertTrue(profile2.active and not profile.active)
+ # activate find active automatically context records
+ self.assertFalse(profile.context_record)
+ profile.find = True
+ profile = profile.save()
+ self.assertTrue(profile.context_record)
+ # activate warehouse active automatically context records and finds
+ self.assertFalse(profile2.context_record or profile2.find)
+ profile2.warehouse = True
+ profile2 = profile2.save()
+ self.assertTrue(profile2.context_record and profile2.find)
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 65bd1ee15..25ae6ddf5 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -17,13 +17,14 @@
# See the file COPYING for details.
+from django.conf import settings
from django.core.cache import cache
from django.utils.translation import ugettext
from django.template.defaultfilters import slugify
def get_cache(cls, extra_args=[]):
- cache_key = cls.__name__
+ cache_key = u"{}-{}".format(settings.PROJECT_SLUG, cls.__name__)
for arg in extra_args:
if not arg:
cache_key += '-0'