Beispiel #1
0
def migrate_community_relations():
    for model in [Resource, Organization, Need]:
        for obj in model.objects.all():
            if obj.community.count() > 0:
                obj_oid = Relation.build_oid(obj)
                relations = [{
                    'target': 'c{id}'.format(id=comm.id),
                    'rel_type': COMM_REL_TYPE[model],
                    'direction': '-',
                } for comm in obj.community.all()]
                if relations:
                    Relation.edit(obj_oid, relations)
def migrate_community_relations():
    for model in [Resource, Organization, Need]:
        for obj in model.objects.all():
            if obj.community.count() > 0:
                obj_oid = Relation.build_oid(obj)
                relations = [
                    {
                        'target': 'c{id}'.format(id=comm.id),
                        'rel_type': COMM_REL_TYPE[model],
                        'direction': '-',
                    } for comm in obj.community.all()
                ]
                if relations:
                    Relation.edit(obj_oid, relations)
def edit_relations_for(context, obj=None):
    options = Relation.rel_type_options()
    currencies = RelationMetadata.CURRENCIES_CHOICES
    relations = [
        {
            "id": rel['id'],
            "direction": rel['direction'],
            "rel_type": rel['rel_type'],
            "target_oid": rel['target_oid'],
            "target_name": rel['target'].name,
            "metadata": rel['metadata']
        }
        for rel in Relation.relations_for(obj)]
    oid = Relation.build_oid(obj)
    return {"options": options, "currencies": currencies, "relations": to_json(relations), "oid": oid}
def migrate_investments():
    for inv in Investment.objects.all():
        if not inv.investor.is_anonymous and inv.investor.content_object:
            oid = Relation.build_oid(inv.investor.content_object)
            relation = [{
                'target': Relation.build_oid(inv.grantee),
                'rel_type': 'investment',
                'direction': '+',
                'metadata': {
                    'start_date': inv.date.strftime('%d/%m/%Y') if inv.date else None,
                    'end_date': inv.end_date.strftime('%d/%m/%Y') if inv.end_date else None,
                    'description': "%s\n%s" % (inv.name, inv.description),
                    'value': inv.value,
                    'currency': inv.currency,
                }
            }]
            Relation.edit(oid, relation)
Beispiel #5
0
def edit_relations_for(context, obj=None):
    options = Relation.rel_type_options()
    currencies = RelationMetadata.CURRENCIES_CHOICES
    relations = [{
        "id": rel['id'],
        "direction": rel['direction'],
        "rel_type": rel['rel_type'],
        "target_oid": rel['target_oid'],
        "target_name": rel['target'].name,
        "metadata": rel['metadata']
    } for rel in Relation.relations_for(obj)]
    oid = Relation.build_oid(obj)
    return {
        "options": options,
        "currencies": currencies,
        "relations": to_json(relations),
        "oid": oid
    }
Beispiel #6
0
def view_relations_for(context, obj=None):
    relations = [{
        'name': rel['target'].name,
        'rel_type': rel['relation_title'],
        'link': rel['target'].view_url,
        'metadata':
        rel['metadata'] if _dict_has_values(rel['metadata']) else {}
    } for rel in Relation.relations_for(obj)]

    return {"relations": relations}
def view_relations_for(context, obj=None):
    relations = [
            {
                'name': rel['target'].name,
                'rel_type': rel['relation_title'],
                'link': rel['target'].view_url,
                'metadata': rel['metadata'] if _dict_has_values(rel['metadata']) else {}
            }
            for rel in Relation.relations_for(obj)]

    return {"relations": relations}
Beispiel #8
0
def migrate_investments():
    for inv in Investment.objects.all():
        if not inv.investor.is_anonymous and inv.investor.content_object:
            oid = Relation.build_oid(inv.investor.content_object)
            relation = [{
                'target': Relation.build_oid(inv.grantee),
                'rel_type': 'investment',
                'direction': '+',
                'metadata': {
                    'start_date':
                    inv.date.strftime('%d/%m/%Y') if inv.date else None,
                    'end_date':
                    inv.end_date.strftime('%d/%m/%Y')
                    if inv.end_date else None,
                    'description':
                    "%s\n%s" % (inv.name, inv.description),
                    'value':
                    inv.value,
                    'currency':
                    inv.currency,
                }
            }]
            Relation.edit(oid, relation)
Beispiel #9
0
def edit_relations(request):
    Relation.edit(request.POST['object_oid'],
                  json.loads(request.POST['relations_json']))
    return redirect(_back_url(request))
Beispiel #10
0
 def communities(self):
     from relations.models import Relation
     return [rel['target'] for rel in Relation.relations_for(self)
             if rel['target'].__class__.__name__ == 'Community']
Beispiel #11
0
 def post_save(self, obj, created=False):
     Relation.build_relations(self.request.user, obj)
     super(InviteUser, self).post_save(obj, created)
def edit_relations(request):
    Relation.edit(request.POST['object_oid'], json.loads(request.POST['relations_json']))
    return redirect(_back_url(request))