Revision 37d59b27 snf-astakos-app/astakos/im/models.py
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
36 | 36 |
import logging |
37 | 37 |
import json |
38 | 38 |
import math |
39 |
import copy |
|
40 | 39 |
|
41 | 40 |
from time import asctime |
42 | 41 |
from datetime import datetime, timedelta |
... | ... | |
65 | 64 |
from django.core.validators import email_re |
66 | 65 |
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist |
67 | 66 |
|
67 |
from synnefo.lib.utils import dict_merge |
|
68 |
|
|
68 | 69 |
from astakos.im.settings import ( |
69 | 70 |
DEFAULT_USER_LEVEL, INVITATIONS_PER_LEVEL, |
70 | 71 |
AUTH_TOKEN_DURATION, EMAILCHANGE_ACTIVATION_DAYS, LOGGING_LEVEL, |
... | ... | |
103 | 104 |
inf = float('inf') |
104 | 105 |
|
105 | 106 |
|
106 |
def dict_merge(a, b): |
|
107 |
""" |
|
108 |
http://www.xormedia.com/recursively-merge-dictionaries-in-python/ |
|
109 |
""" |
|
110 |
if not isinstance(b, dict): |
|
111 |
return b |
|
112 |
result = copy.deepcopy(a) |
|
113 |
for k, v in b.iteritems(): |
|
114 |
if k in result and isinstance(result[k], dict): |
|
115 |
result[k] = dict_merge(result[k], v) |
|
116 |
else: |
|
117 |
result[k] = copy.deepcopy(v) |
|
118 |
return result |
|
119 |
|
|
120 |
|
|
121 | 107 |
class Service(models.Model): |
122 | 108 |
name = models.CharField(_('Name'), max_length=255, unique=True, |
123 | 109 |
db_index=True) |
... | ... | |
188 | 174 |
|
189 | 175 |
|
190 | 176 |
_presentation_data = {} |
177 |
|
|
178 |
|
|
191 | 179 |
def get_presentation(resource): |
192 | 180 |
global _presentation_data |
193 | 181 |
resource_presentation = _presentation_data.get(resource, {}) |
... | ... | |
197 | 185 |
_presentation_data[resource] = resource_presentation |
198 | 186 |
return resource_presentation |
199 | 187 |
|
188 |
|
|
200 | 189 |
class Resource(models.Model): |
201 | 190 |
name = models.CharField(_('Name'), max_length=255, unique=True) |
202 | 191 |
desc = models.TextField(_('Description'), null=True) |
Also available in: Unified diff