Пример #1
0
 def _resolve_change(self):
     change = {}
     for k, v in self.change.items():
         if k == 'extra':
             if not v:
                 continue
             if self.target and self.target.extra:
                 change[k] = self.target.extra
             else:
                 from share.models.base import ExtraData
                 change[k] = ExtraData()
             change[k].change = self
             change[k].data.update({self.change_set.normalized_data.source.username: v})
             change[k].save()
             change[k + '_version_id'] = change[k].version_id
         elif isinstance(v, dict):
             inst = self.change_set._resolve_ref(v)
             change[k] = inst
             try:
                 change[k + '_version_id'] = inst.version_id
             except AttributeError:
                 # this isn't a ShareObject, no worries
                 pass
         elif isinstance(v, list):
             change[k] = [self.change_set._resolve_ref(r) for r in v]
         else:
             change[k] = v
     return change
Пример #2
0
 def _resolve_change(self):
     change = {}
     for k, v in self.change.items():
         if k == 'extra':
             if not v:
                 continue
             if self.target and self.target.extra:
                 change[k] = self.target.extra
             else:
                 from share.models.base import ExtraData
                 change[k] = ExtraData()
             change[k].change = self
             change[k].data.update(
                 {self.change_set.normalized_data.source.username: v})
             change[k].save()
             change[k + '_version_id'] = change[k].version_id
         elif isinstance(v, dict):
             inst = self.change_set._resolve_ref(v)
             change[k] = inst
             try:
                 change[k + '_version_id'] = inst.version_id
             except AttributeError:
                 # this isn't a ShareObject, no worries
                 pass
         elif isinstance(v, list):
             change[k] = [self.change_set._resolve_ref(r) for r in v]
         else:
             change[k] = v
     return change
Пример #3
0
 def _resolve_change(self):
     change = {}
     for k, v in self.change.items():
         if k == 'extra':
             if not v:
                 continue
             if self.target:
                 change[k] = self.target.extra
             else:
                 from share.models.base import ExtraData
                 change[k] = ExtraData()
             change[k].change = self
             change[k].data.update(
                 {self.change_set.normalized_data.source.username: v})
             change[k].save()
             change[k].refresh_from_db()
             change[k + '_version'] = change[k].version
         elif isinstance(v, dict):
             inst = self._resolve_ref(v)
             change[k] = inst
             change[k + '_version'] = inst.version
         elif isinstance(v, list):
             change[k] = [self._resolve_ref(r) for r in v]
         else:
             change[k] = v
     return change
Пример #4
0
    def _resolve_change(self):
        change = {}
        for k, v in self.change.items():
            if k == 'extra':
                if not v:
                    continue
                if self.target and self.target.extra:
                    change[k] = self.target.extra
                else:
                    from share.models.base import ExtraData
                    change[k] = ExtraData()
                change[k].change = self
                change[k].data.update(
                    {self.change_set.normalized_data.source.username: v})
                change[k].save()
                change[k + '_version_id'] = change[k].version_id
            elif isinstance(v, dict):
                inst = self.change_set._resolve_ref(v)
                change[k] = inst
                try:
                    change[k + '_version_id'] = inst.version_id
                except AttributeError:
                    # this isn't a ShareObject, no worries
                    pass
            elif isinstance(v, list):
                change[k] = [self.change_set._resolve_ref(r) for r in v]
            else:
                change[k] = v

        if self.target_type.model == 'subject':
            SubjectTaxonomy = apps.get_model('share', 'subjecttaxonomy')
            user = self.change_set.normalized_data.source
            central_synonym = change.get(
                'central_synonym',
                self.target.central_synonym if self.target else None)
            if central_synonym is None and user.username != settings.APPLICATION_USERNAME:
                raise PermissionError(
                    'Only the system user can modify the central subject taxonomy, not {}'
                    .format(user))
            change['taxonomy'], _ = SubjectTaxonomy.objects.get_or_create(
                source=user.source)

        return change
Пример #5
0
    def _resolve_change(self):
        change = {}
        for k, v in self.change.items():
            if k == 'extra':
                if not v:
                    continue
                if self.target and self.target.extra:
                    change[k] = self.target.extra
                else:
                    from share.models.base import ExtraData
                    change[k] = ExtraData()
                change[k].change = self
                change[k].data.update({self.change_set.normalized_data.source.username: v})
                change[k].save()
                change[k + '_version_id'] = change[k].version_id
            elif isinstance(v, dict):
                inst = self.change_set._resolve_ref(v)
                change[k] = inst
                try:
                    change[k + '_version_id'] = inst.version_id
                except AttributeError:
                    # this isn't a ShareObject, no worries
                    pass
            elif isinstance(v, list):
                change[k] = [self.change_set._resolve_ref(r) for r in v]
            else:
                change[k] = v

        if self.target_type.model == 'subject':
            SubjectTaxonomy = apps.get_model('share', 'subjecttaxonomy')
            user = self.change_set.normalized_data.source
            central_synonym = change.get('central_synonym', self.target.central_synonym if self.target else None)
            if central_synonym is None and user.username != settings.APPLICATION_USERNAME:
                raise PermissionError('Only the system user can modify the central subject taxonomy, not {}'.format(user))
            change['taxonomy'], _ = SubjectTaxonomy.objects.get_or_create(source=user.source)

        return change