Example #1
0
    def userModelHasLanguaje(self):
        """
      Muestra que el idioma de un usuario es el correcto
    """
        america = Location(name="America", location_type="continent")
        america.save()

        guate = Location(name="Guatemala",
                         shortname="GT",
                         code=502,
                         location_type="country",
                         parent=america)
        guate.save()

        gtDep = Location(name="Guatemala",
                         location_type="department",
                         parent=guate)
        gtDep.save()

        mixco = Location(name='Mixco',
                         location_type='municipality',
                         parent=gtDep)
        mixco.save()

        uvg = Institution(name="Universidad del Valle de Guatemala",
                          institution_type="university",
                          location=mixco)
        uvg.save()

        computerscience = Career(
            name=
            "Ingeniería en Ciencias de la Computación y Tecnología de la Información",
            institution=uvg)
        computerscience.save()

        spanish = Language(name="Español")

        marcfuents = User(username="******",
                          first_name="Marco José",
                          last_name="Fuentes Lima",
                          email="*****@*****.**")
        marcfuents.set_password("Contrasena1234")
        marcfuents.save()

        marcofuentes = UserDetail(user_ptr=marcfuents,
                                  birthdate="1999-7-16",
                                  language=spanish,
                                  phone=54131389,
                                  gender="M",
                                  is_tutor=True,
                                  institution=uvg,
                                  career=computerscience,
                                  location=mixco)
        marcofuentes.save_base(raw=True)

        self.assertEqual((marcofuentes.language == spanish), True)
        self.assertEqual((marcofuentes.language == spanish), False)
Example #2
0
def institution_detail(request,
                       institution_id,
                       language=enums.languages.ENGLISH):
    institution, error = Institution.find(institution_id, language)

    if error:
        return render(request, '500.html')

    page = get_page_for_language(language, InstitutionDetailPage.objects.all())

    if not page:
        return render(request, '404.html')

    page.tef_report_link = page.tef_report_link.replace(
        '{{institution_name}}', institution.pub_ukprn_name)

    full_path = '%s?%s' % (request.path, request.environ.get('QUERY_STRING'))
    welsh_url = '/cy' + full_path if language == enums.languages.ENGLISH else full_path
    english_url = full_path.replace('/cy/', '/')

    context = {
        'page': page,
        'institution': institution,
        'english_url': english_url,
        'welsh_url': welsh_url,
        'cookies_accepted': request.COOKIES.get('discoverUniCookies')
    }

    return render(request, 'institutions/institution_detail_page.html',
                  context)
Example #3
0
def institution_detail(request, institution_id, language=enums.languages.ENGLISH):
    institution, error = Institution.find(institution_id, language)

    if error:
        redirect_page = get_new_landing_page_for_language(language)
        #redirect_page = get_page_for_language(language, SearchLandingPage.objects.all()).url
        return redirect(redirect_page + '?load_error=true&error_type=0')

    page = get_page_for_language(language, InstitutionDetailPage.objects.all())

    if not page:
        return render(request, '404.html')

    page.tef_report_link = page.tef_report_link.replace('{{institution_name}}', institution.pub_ukprn_name)

    full_path = '%s?%s' % (request.path, request.environ.get('QUERY_STRING'))
    if language == enums.languages.ENGLISH:
        translated_url = '/cy' + request.path if language == enums.languages.ENGLISH else request.path
    else:
        translated_url = request.path.replace('/cy/', '/')

    context = page.get_context(request)
    context.update({
        'page': page,
        'institution': institution,
        'translated_url': translated_url,
        'cookies_accepted': request.COOKIES.get('discoverUniCookies')
    })

    return render(request, 'institutions/institution_detail_page.html', context)
Example #4
0
    def get_context_data(self, **kwargs):
        context = super(InstitutionMostActiveListView,
                        self).get_context_data(**kwargs)

        types = Institution.report_by_kind()

        if self.institution_kind:
            current_institution_kind = InstitutionKind.objects.filter(
                pk=self.institution_kind).first().name
        else:
            current_institution_kind = 'Todas las instituciones'

        context.update({
            'institution_types': types,
            'institutions': self.all_institutions,
            'current_institution': current_institution_kind,
            'by': self.paginate_by,
            'ordering': self.ordering,
        })
        return context
Example #5
0
 def test_institution_find_returns_a_institution_object_if_institution_found(
         self):
     institution, error = Institution.find(1, 1)
     self.assertIsNone(error)
     self.assertIsNotNone(institution)
     self.assertEquals(type(institution), Institution)
Example #6
0
 def test_institution_find_returns_api_error_if_institution_not_found(
         self, mock_response):
     institution, error = Institution.find(1, 'en')
     self.assertIsNone(institution)
     self.assertIsNotNone(error)
     self.assertEquals(type(error), ApiError)
Example #7
0
def instituicao():
    with open('/maladireta/database/instituicoes.csv') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        line_count = 0
        for row in csv_reader:
            if line_count == 0:
                print(f'Column names are {", ".join(row)}')
                line_count += 1
            else:
                telefone = None
                if row[2]:
                    telefone = ''.join((filter(
                        lambda x: x in [
                            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                            '0', '(', ')', '-', '/'
                        ], row[2])))
                institution = Institution()
                institution.name = row[1]
                query = Institution.objects.search(institution.name)
                if not query:
                    institution.phone_number = telefone
                    institution.street = row[3]
                    institution.city = row[4]
                    institution.number = row[5]
                    institution.neighborhood = row[7]
                    institution.cep = row[8]
                    institution.state = row[9]
                    institution.note = row[11]
                    institution.save()
                    #print(f'\tNome: {row[1]}\nTelefones {telefone}\nEndereço: {row[3]}\nCidade: {row[4]}\nNumero: {row[5]}\nComplemento: {row[6]}\nBairro: {row[7]}\nCEP: {row[8]}\nUF: {row[9]}\nOBS: {row[11]}')
                    line_count += 1
    print(f'{line_count} instituições adicionadas.')
Example #8
0
def autoridade():
    with open('/maladireta/database/autoridades.csv') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        line_count = 0
        position_count = 0
        institution_count = 0
        authoritie_count = 0
        for row in csv_reader:
            if line_count == 0:
                print(f'Column names are {", ".join(row)}')
                line_count += 1
            else:
                if row[3]:
                    ### Position
                    if not row[4]:
                        row[4], row[5] = "Vossa Senhoria", "V. S.ª"

                    position = Position()
                    position.position, position.handling, position.abbreviation = row[
                        3], row[4], row[5]
                    position_query = Position.objects.search(position.position)
                    if not position_query:
                        position.save()
                        position_count += 1

                    ## Institution
                    if row[6]:
                        telefone = None
                        if row[7]:
                            telefone = ''.join((filter(
                                lambda x: x in [
                                    '0', '1', '2', '3', '4', '5', '6', '7',
                                    '8', '9', '0', '(', ')', '-', '/'
                                ], row[7])))

                        institution = Institution()
                        institution.name = row[6]
                        institution.phone_number = telefone
                        institution.city = row[8]
                        institution.street = row[9]
                        institution.number = row[10]
                        institution.complement = row[11]
                        institution.neighborhood = row[12]
                        institution.cep = row[13]
                        institution.state = row[14]
                        institution.note = row[15]
                        institution_query = Institution.objects.search(
                            institution.name)
                        if not institution_query:
                            institution.save()
                            institution_count += 1

                    ### Authoritie
                    if row[16]:
                        authoritie = Authoritie()
                        authoritie.name = row[16]
                        if row[19]:
                            authoritie.birth = to_datetime_inverted(
                                row[19].split(' ')[0])
                        authoritie.position = Position.objects.search(
                            position.position)[0]
                        authoritie.institution = Institution.objects.search(
                            institution.name)[0]
                        authoritie_query = Authoritie.objects.search(
                            authoritie.name)
                        if not authoritie_query:
                            authoritie.save()
                            authoritie_count += 1

    return authoritie_count, institution_count, position_count