Esempio n. 1
0
    def to_object(self):
        if hasattr(self, 'object') and self.object:
            return self.object

        d = self.object_dict
        r = Resource()
        for attr in ['name', 'creator', 'contact', 'description']:
            setattr(r, attr, d[attr])
        if 'geometry' in d:
            r.geometry = d['geometry']
        q = ResourceKind.objects.filter(name=d['kind'])
        if q.count() > 1:  # this *should* be not necessary!
            r.kind = q[0]
        else:
            r.kind, created = ResourceKind.objects \
                                    .get_or_create(name=d['kind'])
        r.save()

        # m2m relationships
        r.community = d['community']
        r.tags.add(*d['tags'])
        r.save()

        self.object = r
        return r
Esempio n. 2
0
    def to_object(self):
        if hasattr(self, 'object') and self.object:
            return self.object

        d = self.object_dict
        r = Resource()
        for attr in ['name', 'creator', 'contact', 'description']:
            setattr(r, attr, d[attr])
        if 'geometry' in d:
            r.geometry = d['geometry']
        q = ResourceKind.objects.filter(name=d['kind'])
        if q.count() > 1:  # this *should* be not necessary!
            r.kind = q[0]
        else:
            r.kind, created = ResourceKind.objects \
                                    .get_or_create(name=d['kind'])
        r.save()
        
        # m2m relationships
        r.community = d['community']
        r.tags.add(*d['tags'])
        r.save()

        self.object = r
        return r
Esempio n. 3
0
def save_resource(vals):
    name = get_field(vals, 'B').title().strip()

    if not name:
        return

    desc = """

#### Representante

O {AS} do [Comitê Nacional de Enfrentamento à Violência Sexual contra Crianças e Adolescentes](http://maps.mootiro.org/organization/comite-nacional-de-enfrentamento-a-violencia-sexual-contra-criancas-e-adolescentes "Comitê Nacional no MootiroMaps") no estado de {AW}, é representado por {AA}.

{AA} integra a organização {BG} - {BH}.

#### Referências

- [{BM}] ({BL} "Arquivo no GoogleDocs"), {BN}
- [Site institucional do Comitê Nacional de Enfrentamento à Violência Sexual contra Crianças e Adolescentes] (http://www.comitenacional.org.br/ "")


    """.format(
        **format_fields(vals, 'AS', 'AW', 'AA', 'BG', 'BH', 'BM', 'BL', 'BN'))

    contact = """

**Fone:** ({AB}) {AC}

**E-mail:** {Z}

**Facebook:** [{BD}] ({BE} "{B} no Facebook")

    """.format(**format_fields(vals, 'AB', 'AC', 'Z', 'BD', 'BE', 'B'))

    tags = [
        get_field(vals, f) for f in ["AQ", "AR", "AS", "AT", "AU", "AV", "AW"]
    ]

    now = datetime.now()

    o = Resource()
    o.name = name
    o.description = desc
    o.contact = contact
    o.creation_date = now
    o.creator = users[get_field(vals, 'C')]
    o.save()
    for t in tags:
        o.tags.add(t)

    ProjectRelatedObject.objects.create(project=projeto, content_object=o)
    print 'OK  -  ', name
Esempio n. 4
0
def save_resource(vals):
    name = get_field(vals, 'B').title().strip()

    if not name:
        return

    desc = """

#### Representante

O {AS} do [Comitê Nacional de Enfrentamento à Violência Sexual contra Crianças e Adolescentes](http://maps.mootiro.org/organization/comite-nacional-de-enfrentamento-a-violencia-sexual-contra-criancas-e-adolescentes "Comitê Nacional no MootiroMaps") no estado de {AW}, é representado por {AA}.

{AA} integra a organização {BG} - {BH}.

#### Referências

- [{BM}] ({BL} "Arquivo no GoogleDocs"), {BN}
- [Site institucional do Comitê Nacional de Enfrentamento à Violência Sexual contra Crianças e Adolescentes] (http://www.comitenacional.org.br/ "")


    """.format(**format_fields(vals, 'AS', 'AW', 'AA', 'BG', 'BH', 'BM', 'BL', 'BN'))

    contact = """

**Fone:** ({AB}) {AC}

**E-mail:** {Z}

**Facebook:** [{BD}] ({BE} "{B} no Facebook")

    """.format(**format_fields(vals, 'AB', 'AC', 'Z', 'BD', 'BE', 'B'))

    tags = [get_field(vals, f) for f in
            ["AQ", "AR", "AS", "AT", "AU", "AV", "AW"]]

    now = datetime.now()

    o = Resource()
    o.name = name
    o.description = desc
    o.contact = contact
    o.creation_date = now
    o.creator = users[get_field(vals, 'C')]
    o.save()
    for t in tags:
        o.tags.add(t)

    ProjectRelatedObject.objects.create(project=projeto, content_object=o)
    print 'OK  -  ', name
Esempio n. 5
0
def save_resource(vals):
    e = get_field(vals, 'E').strip()
    d = get_field(vals, 'D').strip()

    if d:
        name = '{} - {}'.format(e, d)
    else:
        name = e

    if not name:
        return

    distrito = get_field(vals, 'M').strip()
    if distrito:
        desc = """
#### Localização

{C} fica {M} {N}, {O} do município {Q}, {R}.
""".format(**format_fields(vals, 'C', 'M', 'N', 'O', 'Q', 'R'))
    else:
        desc = """
#### Localização

{C} fica no bairro {L} do município {Q}, {R}.
""".format(**format_fields(vals, 'C', 'L', 'Q', 'R'))
    desc += """

#### Serviços e Programas

{AM} {AN}

#### Funcionamento

* Horário: {BG}
* Situação: {BJ}

#### Área de abrangência

{BF}

#### Registros e certificações

""".format(**format_fields(vals, 'AM', 'AN', 'BG', 'BJ', 'BF'))

    g = get_field(vals, 'G')
    bm = get_field(vals, 'BM')
    h = get_field(vals, 'H')
    bh = get_field(vals, 'BH')
    z = get_field(vals, 'Z')

    if g:
        desc += """
- Código da Escola (INEP): {G}
""".format(G=g)

    if bm:
        desc += """
- Código Municipal da Escola: {BM}
""".format(BM=bm)

    if h:
        desc += """
- Cadastro Nacional de Estabelecimentos de Saúde (CNES): {H}
""".format(H=h)

    if bh:
        desc += """
- Código do Conselho Tutelar: {BH}
""".format(BH=bh)

    if z:
        desc += """
- CNPJ: {Z}
""".format(Z=z)

    desc += """
#### Órgão superior

- {BO}

#### Pessoas de contato

{W}, {X}

#### Outros contatos

Fax: ({S}) {U}

#### Referências

- [{AE}]({AF} "{AG}"), consultado em {AH}
""".format(**format_fields(vals, 'BO', 'W', 'X', 'S', 'U', 'AE', 'AF', 'AG',
                           'AH'))

    k = get_field(vals, 'K').strip()
    if k:
        k = ', ' + k

    contact = """
Endereço: {I}, {J} {K} | {L}, {P} | {Q}-{R}

Telefone: ({S}) {T}

E-mail: {V}
    """.format(K=k,
               **format_fields(vals, 'I', 'J', 'L', 'P', 'Q', 'R', 'S', 'T',
                               'V'))

    tags = [
        get_field(vals, f) for f in [
            'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'BN',
            'BO', 'BP', 'BQ'
        ]
    ]
    tags = filter(bool, tags)

    now = datetime.now()
    user_id = get_field(vals, 'B').split('/')[-1]
    creator = User.objects.get(pk=user_id)

    longitude, latitude = get_field(vals, 'BL'), get_field(vals, 'BK')
    if longitude and latitude:
        x, y = map(float, [
            c.replace(',', '.').replace(' ', '') for c in (longitude, latitude)
        ])
        geom = []
        geom.append('%s,%s' % (x + 0.0005, y + 0.0005))
        geom.append('%s,%s' % (x + 0.0005, y - 0.0005))
        geom.append('%s,%s' % (x - 0.0005, y - 0.0005))
        geom.append('%s,%s' % (x - 0.0005, y + 0.0005))
        geom.append('%s,%s' % (x + 0.0005, y + 0.0005))
        coords = ''
        for i, coord in enumerate(geom):
            coord = coord.split(',')
            coords += '%s %s' % (coord[1], coord[0])
            if not i == len(geom) - 1:
                coords += ', '
        geometry = "GEOMETRYCOLLECTION( POLYGON (( %s )))" % coords
    else:
        geometry = ''

    o = Resource()
    o.name = name
    o.description = desc
    o.contact = contact
    o.creation_date = now
    o.creator = creator
    if geometry:
        o.geometry = geometry
    o.save()
    for t in tags:
        o.tags.add(t)

    proj_slug = get_field(vals, 'BE').split('/')[-1]
    if proj_slug:
        print proj_slug
        proj = Project.objects.get(slug=proj_slug)
        ProjectRelatedObject.objects.get_or_create(project=proj,
                                                   content_type=ct_resource,
                                                   object_id=o.id)

    print 'OK  -  ', name
def save_obj(vals):
    imp, transf, comunidade, name, desc, folder, tipo, geom = vals
    geom = eval(geom)
    print type(geom)
    print 'saving: ', vals
    if ',' in comunidade:
        comunidade = comunidade.split(',')[0]

    if transf == 'sim':
        tipo = 'polys'
        x, y, z = map(float, geom[0].split(','))
        geom = []
        geom.append('%s,%s,%s' % (x + 0.0005, y + 0.0005, z))
        geom.append('%s,%s,%s' % (x + 0.0005, y - 0.0005, z))
        geom.append('%s,%s,%s' % (x - 0.0005, y - 0.0005, z))
        geom.append('%s,%s,%s' % (x - 0.0005, y + 0.0005, z))
        geom.append('%s,%s,%s' % (x + 0.0005, y + 0.0005, z))

    if tipo == 'polys':
        coords = ''
        for i, coord in enumerate(geom):
            x, y, z = coord.split(',')
            coords += '%s %s' % (y, x)
            if not i == len(geom) - 1:
                coords += ', '
        geo_ref = 'GEOMETRYCOLLECTION ( POLYGON (( %s )))' % coords
    elif tipo == 'point':
        x, y, z = geom[0].split(',')
        geo_ref = 'GEOMETRYCOLLECTION ( POINT ( %s %s))' % (y, x)

    if imp == 'R':
        r = Resource()
        r.name = name
        r.description = desc
        if comunidade:
            c = Community.objects.get(slug=comunidade)
            r.community = c
        r.geometry = geo_ref
        r.save()

    elif imp == 'N':
        n = Need()
        n.title = name
        n.description = desc
        if comunidade:
            c = Community.objects.get(slug=comunidade)
            n.community = c
        n.geometry = geo_ref
        # n.target_audiences.add(1)
        n.save()

    elif imp == 'O':
        if name:
            o = Organization()
            o.name = name
            o.description = desc
            o.save()
            if comunidade:
                c = Community.objects.get(slug=comunidade)
                o.community.add(c)

            b = OrganizationBranch()
            b.name = name + ' - sede'
            b.geometry = geo_ref
            b.organization = o
            b.save()
Esempio n. 7
0
def save_resource(vals):
    name = "{} {}".format(
            get_field(vals, 'D'), get_field(vals, 'E'))

    desc = """
####Localização

{C} fica no distrito {K} da Subprefeitura {L} da capital paulista.

####Horário de Atendimento

{Y}

""".format(
        C=get_field(vals, 'C'),
        K=get_field(vals, 'K'),
        L=get_field(vals, 'L'),
        Y=get_field(vals, 'Y'),
    )

    if get_field(vals, 'G') or get_field(vals, 'S'):
        desc += """
####Registros e Certificações

"""
        if get_field(vals, 'G'):
            desc += """
- Código INEP da Instituição de Ensino: {G}""".format(G=get_field(vals, 'G'))
        if get_field(vals, 'S'):
            desc += """
- Cadastro Nacional de Pessoa Jurídica (CNPJ): {S}""".format(S=get_field(
                                                                vals, 'S'))

    desc += """

####Referência

- [{U}]({V} "{W}"), {X}
    """.format(
        U=get_field(vals, 'U'),
        V=get_field(vals, 'V'),
        W=get_field(vals, 'W'),
        X=get_field(vals, 'X'),
    )

    contact = """
{H}, {I} | {J}
CEP: {M}, São Paulo-SP

Fone: {O} {P}

Email: {Q}
    """.format(
        H=get_field(vals, 'H'),
        I=get_field(vals, 'I'),
        J=get_field(vals, 'J'),
        M=get_field(vals, 'M'),
        O=get_field(vals, 'O'),
        P=get_field(vals, 'P'),
        Q=get_field(vals, 'Q'),
    )


    # Palavras-Chave
    tags = [get_field(vals, f) for f in [ 'Z', 'AA', 'AB', 'AC', 'AD', 'AE'] ]

    now = datetime.now()

    o = Resource()
    o.name = name
    o.description = desc
    o.contact = contact
    o.creation_date = now
    o.creator = mariarita
    o.save()
    for t in tags:
        o.tags.add(t)
    print 'OK'
Esempio n. 8
0
def save_obj(vals):
    imp, transf, comunidade, name, desc, folder, tipo, geom = vals
    geom = eval(geom)
    print type(geom)
    print 'saving: ', vals
    if ',' in comunidade:
        comunidade = comunidade.split(',')[0]
    if comunidade == 'morro-do-INPS':
        comunidade = 'morro-do-inps'
    elif comunidade == 'mineiros':
        comunidade = 'morro-dos-mineiros'
    elif comunidade == 'conjunto-habitacional-BNH':
        comunidade = 'conjunto-habitacional-bnh'


    if transf == 'sim':
        tipo = 'polys'
        x,y, z = map(float, geom[0].split(','))
        geom = []
        geom.append('%s,%s,%s' % (x + 0.0005, y + 0.0005, z))
        geom.append('%s,%s,%s' % (x + 0.0005, y - 0.0005, z))
        geom.append('%s,%s,%s' % (x - 0.0005, y - 0.0005, z))
        geom.append('%s,%s,%s' % (x - 0.0005, y + 0.0005, z))
        geom.append('%s,%s,%s' % (x + 0.0005, y + 0.0005, z))

    if tipo == 'polys':
        coords = ''
        for i, coord in enumerate(geom):
            x,y, z = coord.split(',')
            coords += '%s %s' % (y, x)
            if not i == len(geom) - 1:
                coords += ', '
        geo_ref = 'GEOMETRYCOLLECTION ( POLYGON (( %s )))' % coords
    elif tipo == 'point':
        x,y, z = geom[0].split(',')
        geo_ref = 'GEOMETRYCOLLECTION ( POINT ( %s %s))' % (y, x)


    if imp == 'R':
        r = Resource()
        r.name = name
        r.description = desc
        if comunidade:
            c = Community.objects.get(slug=comunidade)
            r.community = c
        r.geometry = geo_ref
        r.save()

    elif imp == 'N':
        n = Need()
        n.title = name
        n.description = desc
        if comunidade:
            c = Community.objects.get(slug=comunidade)
            n.community = c
        n.geometry = geo_ref
        # n.target_audiences.add(1)
        n.save()

    elif imp == 'O':
        if name:
            o = Organization()
            o.name = name
            o.description = desc
            o.save()
            if comunidade:
                c = Community.objects.get(slug=comunidade)
                o.community.add(c)

            b = OrganizationBranch()
            b.name = name + ' - sede'
            b.geometry = geo_ref
            b.organization = o
            b.save()
Esempio n. 9
0
def save_obj(vals):
    imp, transf, comunidade, name, desc, folder, tipo, geom = vals
    geom = eval(geom)
    print 'saving: ', vals

    user = User.objects.get(username='******')
    now = datetime.now()

    # Transform geometry data type
    if transf == 'sim':
        tipo = 'polys'
        x, y, z = map(float, geom[0].split(','))
        geom = []
        geom.append('%s,%s,%s' % (x + 0.0003, y + 0.0003, z))
        geom.append('%s,%s,%s' % (x + 0.0003, y - 0.0003, z))
        geom.append('%s,%s,%s' % (x - 0.0003, y - 0.0003, z))
        geom.append('%s,%s,%s' % (x - 0.0003, y + 0.0003, z))
        geom.append('%s,%s,%s' % (x + 0.0003, y + 0.0003, z))

    # build geomtry info
    if tipo == 'polys':
        coords = ''
        for i, coord in enumerate(geom):
            x, y, z = coord.split(',')
            coords += '%s %s' % (y, x)
            if not i == len(geom) - 1:
                coords += ', '
        geo_ref = 'GEOMETRYCOLLECTION ( POLYGON (( %s )))' % coords
    elif tipo == 'point':
        x, y, z = geom[0].split(',')
        geo_ref = 'GEOMETRYCOLLECTION ( POINT ( %s %s))' % (y, x)

    # save Resource
    if imp == 'R':

        #fix comunidade
        tags = []
        if ',' in comunidade:
            split = [c.strip() for c in comunidade.split(',')]
            comunidade, tags = split[0], split[1:]

        r = Resource()
        r.name = name
        r.description = desc

        # comunity is the firt
        if comunidade:
            c = Community.objects.get(slug=comunidade)
            r.community = c

        r.creator = user
        r.creation_date = now
        r.geometry = geo_ref
        r.save()

        # load remaining comunities as tags
        for tag in tags:
            r.tags.add(tag)

    # save Need
    elif imp == 'N':

        #fix comunidade
        tags = []
        if ',' in comunidade:
            split = [c.strip() for c in comunidade.split(',')]
            comunidade, tags = split[0], split[1:]

        n = Need()
        n.title = name
        n.description = desc

        if comunidade:
            c = Community.objects.get(slug=comunidade)
            n.community = c

        n.creator = user
        n.creation_date = now
        n.geometry = geo_ref
        # n.target_audiences.add(1)
        n.save()

        # load remaining comunities as tags
        for tag in tags:
            n.tags.add(tag)

    # save organization
    elif imp == 'O':
        if name:
            o = Organization()
            o.name = name
            o.description = desc
            o.creation_date = now
            o.creator = user
            o.save()
            for comm in [c.strip() for c in comunidade.split(',')]:
                c = Community.objects.get(slug=comm)
                o.community.add(c)

            b = OrganizationBranch()
            b.name = name + ' - sede'
            b.geometry = geo_ref
            b.organization = o
            b.creator = user
            b.creation_date = now
            b.save()
Esempio n. 10
0
def save_resource(vals):
    name = "{} {}".format(get_field(vals, 'D'), get_field(vals, 'E'))

    desc = """
####Localização

{C} fica no distrito {K} da Subprefeitura {L} da capital paulista.

####Horário de Atendimento

{Y}

""".format(
        C=get_field(vals, 'C'),
        K=get_field(vals, 'K'),
        L=get_field(vals, 'L'),
        Y=get_field(vals, 'Y'),
    )

    if get_field(vals, 'G') or get_field(vals, 'S'):
        desc += """
####Registros e Certificações

"""
        if get_field(vals, 'G'):
            desc += """
- Código INEP da Instituição de Ensino: {G}""".format(G=get_field(vals, 'G'))
        if get_field(vals, 'S'):
            desc += """
- Cadastro Nacional de Pessoa Jurídica (CNPJ): {S}""".format(
                S=get_field(vals, 'S'))

    desc += """

####Referência

- [{U}]({V} "{W}"), {X}
    """.format(
        U=get_field(vals, 'U'),
        V=get_field(vals, 'V'),
        W=get_field(vals, 'W'),
        X=get_field(vals, 'X'),
    )

    contact = """
{H}, {I} | {J}
CEP: {M}, São Paulo-SP

Fone: {O} {P}

Email: {Q}
    """.format(
        H=get_field(vals, 'H'),
        I=get_field(vals, 'I'),
        J=get_field(vals, 'J'),
        M=get_field(vals, 'M'),
        O=get_field(vals, 'O'),
        P=get_field(vals, 'P'),
        Q=get_field(vals, 'Q'),
    )

    # Palavras-Chave
    tags = [get_field(vals, f) for f in ['Z', 'AA', 'AB', 'AC', 'AD', 'AE']]

    now = datetime.now()

    o = Resource()
    o.name = name
    o.description = desc
    o.contact = contact
    o.creation_date = now
    o.creator = mariarita
    o.save()
    for t in tags:
        o.tags.add(t)
    print 'OK'
Esempio n. 11
0
def save_resource(vals):
    e = get_field(vals, 'E').strip()
    d = get_field(vals, 'D').strip()

    if d:
        name = '{} - {}'.format(e, d)
    else:
        name = e

    if not name:
        return

    distrito = get_field(vals, 'M').strip()
    if distrito:
        desc = """
#### Localização

{C} fica {M} {N}, {O} do município {Q}, {R}.
""".format(**format_fields(vals, 'C', 'M', 'N', 'O', 'Q', 'R'))
    else:
        desc = """
#### Localização

{C} fica no bairro {L} do município {Q}, {R}.
""".format(**format_fields(vals, 'C', 'L', 'Q', 'R'))
    desc += """

#### Serviços e Programas

{AM} {AN}

#### Funcionamento

* Horário: {BG}
* Situação: {BJ}

#### Área de abrangência

{BF}

#### Registros e certificações

""".format(**format_fields(vals, 'AM', 'AN', 'BG', 'BJ', 'BF'))

    g = get_field(vals, 'G')
    bm = get_field(vals, 'BM')
    h = get_field(vals, 'H')
    bh = get_field(vals, 'BH')
    z = get_field(vals, 'Z')

    if g:
        desc += """
- Código da Escola (INEP): {G}
""".format(G=g)

    if bm:
        desc += """
- Código Municipal da Escola: {BM}
""".format(BM=bm)

    if h:
        desc += """
- Cadastro Nacional de Estabelecimentos de Saúde (CNES): {H}
""".format(H=h)

    if bh:
        desc += """
- Código do Conselho Tutelar: {BH}
""".format(BH=bh)

    if z:
        desc += """
- CNPJ: {Z}
""".format(Z=z)

    desc += """
#### Órgão superior

- {BO}

#### Pessoas de contato

{W}, {X}

#### Outros contatos

Fax: ({S}) {U}

#### Referências

- [{AE}]({AF} "{AG}"), consultado em {AH}
""".format(**format_fields(vals, 'BO', 'W', 'X', 'S', 'U', 'AE', 'AF', 'AG',
           'AH'))

    k = get_field(vals, 'K').strip()
    if k:
        k = ', ' + k

    contact = """
Endereço: {I}, {J} {K} | {L}, {P} | {Q}-{R}

Telefone: ({S}) {T}

E-mail: {V}
    """.format(K=k, **format_fields(vals, 'I', 'J', 'L', 'P', 'Q', 'R', 'S',
                'T', 'V'))

    tags = [get_field(vals, f) for f in
               ['AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX',
                'BN', 'BO', 'BP', 'BQ']]
    tags = filter(bool, tags)

    now = datetime.now()
    user_id = get_field(vals, 'B').split('/')[-1]
    creator = User.objects.get(pk=user_id)

    longitude, latitude = get_field(vals, 'BL'), get_field(vals, 'BK')
    if longitude and latitude:
        x, y = map(float, [c.replace(',', '.').replace(' ', '')
                    for c in (longitude, latitude)])
        geom = []
        geom.append('%s,%s' % (x + 0.0005, y + 0.0005))
        geom.append('%s,%s' % (x + 0.0005, y - 0.0005))
        geom.append('%s,%s' % (x - 0.0005, y - 0.0005))
        geom.append('%s,%s' % (x - 0.0005, y + 0.0005))
        geom.append('%s,%s' % (x + 0.0005, y + 0.0005))
        coords = ''
        for i, coord in enumerate(geom):
            coord = coord.split(',')
            coords += '%s %s' % (coord[1], coord[0])
            if not i == len(geom) - 1:
                coords += ', '
        geometry = "GEOMETRYCOLLECTION( POLYGON (( %s )))" % coords
    else:
        geometry = ''

    o = Resource()
    o.name = name
    o.description = desc
    o.contact = contact
    o.creation_date = now
    o.creator = creator
    if geometry:
        o.geometry = geometry
    o.save()
    for t in tags:
        o.tags.add(t)

    proj_slug = get_field(vals, 'BE').split('/')[-1]
    if proj_slug:
        print proj_slug
        proj = Project.objects.get(slug=proj_slug)
        ProjectRelatedObject.objects.get_or_create(project=proj,
                content_type=ct_resource, object_id=o.id)

    print 'OK  -  ', name