# Path: lrs/models.py
# class Activity(models.Model):
#     activity_id = models.CharField(
#         max_length=MAX_URL_LENGTH, db_index=True, unique=True)
#     canonical_data = JSONField(default=dict)
#     authority = models.ForeignKey(Agent, null=True, on_delete=models.CASCADE)
# 
#     def return_activity_with_lang_format(self, lang=None, ids_only=False):
#         if ids_only:
#             return {'id': self.activity_id}
#         ret = self.canonical_data
#         if 'objectType' not in self.canonical_data:
#             ret['objectType'] = 'Activity'
#         if 'definition' in self.canonical_data:
#             if 'name' in ret['definition'] and list(ret['definition']['name'].items()):
#                 ret['definition']['name'] = get_lang(
#                     ret['definition']['name'], lang)
#             if 'description' in ret['definition'] and list(ret['definition']['description'].items()):
#                 ret['definition']['description'] = get_lang(
#                     ret['definition']['description'], lang)
#             if 'scale' in ret['definition']:
#                 for s in ret['definition']['scale']:
#                     if list(s.items()):
#                         s['description'] = get_lang(s['description'], lang)
#             if 'choices' in ret['definition']:
#                 for c in ret['definition']['choices']:
#                     if list(c.items()):
#                         c['description'] = get_lang(c['description'], lang)
#             if 'steps' in ret['definition']:
#                 for st in ret['definition']['steps']:
#                     if st.items:
#                         st['description'] = get_lang(st['description'], lang)
#             if 'source' in ret['definition']:
#                 for so in ret['definition']['source']:
#                     if so.items:
#                         so['description'] = get_lang(so['description'], lang)
#                 for t in ret['definition']['target']:
#                     if list(t.items()):
#                         t['description'] = get_lang(t['description'], lang)
#         return ret
# 
#     def get_a_name(self):
#         if 'definition' in self.canonical_data:
#             return self.canonical_data['definition'].get('en-US', self.activity_id)
#         else:
#             return self.activity_id
# 
#     def __unicode__(self):
#         return json.dumps(self.canonical_data, sort_keys=False)


from django.db import IntegrityError
from ..models import Activity
                    if c['id'] in trans:
                        c['description'] = dict(
                            list(c['description'].items()) + list(trans[c['id']].items()))
            if 'steps' in incoming_act_def and 'steps' in self.activity.canonical_data['definition']:
                trans = {x['id']: x['description']
                         for x in incoming_act_def['steps']}
                for s in self.activity.canonical_data['definition']['steps']:
                    if s['id'] in trans:
                        s['description'] = dict(
                            list(s['description'].items()) + list(trans[s['id']].items()))
            if 'source' in incoming_act_def and 'source' in self.activity.canonical_data['definition']:
                trans = {x['id']: x['description']
                         for x in incoming_act_def['source']}
                for s in self.activity.canonical_data['definition']['source']:
                    if s['id'] in trans:
                        s['description'] = dict(
                            list(s['description'].items()) + list(trans[s['id']].items()))
            if 'target' in incoming_act_def and 'target' in self.activity.canonical_data['definition']:
                trans = {x['id']: x['description']
                         for x in incoming_act_def['target']}
                for s in self.activity.canonical_data['definition']['target']:
                    if s['id'] in trans:
                        s['description'] = dict(
                            list(s['description'].items()) + list(trans[s['id']].items()))

    def populate(self, data):
        activity_id = data['id']
        can_define = False
        # Try to get activity
        try:

# Path: lrs/models.py
# class Activity(models.Model):
#     activity_id = models.CharField(
#         max_length=MAX_URL_LENGTH, db_index=True, unique=True)
#     canonical_data = JSONField(default=dict)
#     authority = models.ForeignKey(Agent, null=True, on_delete=models.CASCADE)
# 
#     def return_activity_with_lang_format(self, lang=None, ids_only=False):
#         if ids_only:
#             return {'id': self.activity_id}
#         ret = self.canonical_data
#         if 'objectType' not in self.canonical_data:
#             ret['objectType'] = 'Activity'
#         if 'definition' in self.canonical_data:
#             if 'name' in ret['definition'] and list(ret['definition']['name'].items()):
#                 ret['definition']['name'] = get_lang(
#                     ret['definition']['name'], lang)
#             if 'description' in ret['definition'] and list(ret['definition']['description'].items()):
#                 ret['definition']['description'] = get_lang(
#                     ret['definition']['description'], lang)
#             if 'scale' in ret['definition']:
#                 for s in ret['definition']['scale']:
#                     if list(s.items()):
#                         s['description'] = get_lang(s['description'], lang)
#             if 'choices' in ret['definition']:
#                 for c in ret['definition']['choices']:
#                     if list(c.items()):
#                         c['description'] = get_lang(c['description'], lang)
#             if 'steps' in ret['definition']:
#                 for st in ret['definition']['steps']:
#                     if st.items:
#                         st['description'] = get_lang(st['description'], lang)
#             if 'source' in ret['definition']:
#                 for so in ret['definition']['source']:
#                     if so.items:
#                         so['description'] = get_lang(so['description'], lang)
#                 for t in ret['definition']['target']:
#                     if list(t.items()):
#                         t['description'] = get_lang(t['description'], lang)
#         return ret
# 
#     def get_a_name(self):
#         if 'definition' in self.canonical_data:
#             return self.canonical_data['definition'].get('en-US', self.activity_id)
#         else:
#             return self.activity_id
# 
#     def __unicode__(self):
#         return json.dumps(self.canonical_data, sort_keys=False)


# Path: lrs/managers/ActivityManager.py
from django.db import IntegrityError
from ..models import Activity

                    if c['id'] in trans:
                        c['description'] = dict(
                            list(c['description'].items()) + list(trans[c['id']].items()))
            if 'steps' in incoming_act_def and 'steps' in self.activity.canonical_data['definition']:
                trans = {x['id']: x['description']
                         for x in incoming_act_def['steps']}
                for s in self.activity.canonical_data['definition']['steps']:
                    if s['id'] in trans:
                        s['description'] = dict(
                            list(s['description'].items()) + list(trans[s['id']].items()))
            if 'source' in incoming_act_def and 'source' in self.activity.canonical_data['definition']:
                trans = {x['id']: x['description']
                         for x in incoming_act_def['source']}
                for s in self.activity.canonical_data['definition']['source']:
                    if s['id'] in trans:
                        s['description'] = dict(
                            list(s['description'].items()) + list(trans[s['id']].items()))
            if 'target' in incoming_act_def and 'target' in self.activity.canonical_data['definition']:
                trans = {x['id']: x['description']
                         for x in incoming_act_def['target']}
                for s in self.activity.canonical_data['definition']['target']:
                    if s['id'] in trans:
                        s['description'] = dict(
                            list(s['description'].items()) + list(trans[s['id']].items()))

    def populate(self, data):
        activity_id = data['id']
        can_define = False
        # Try to get activity
        try:

            self.activity = Activity.objects.get(activity_id=activity_id)