Пример #1
0
    def update_members(self, year):
        with in_database(str(year), write=True):
            try:
                members = ws.get(url=self.WS_URL_DETAIL % (self.code, year),
                                 use_redis=False)[0]['miembros']
            except KeyError:
                logger.warn(self.type + " " + self.code +
                            " does not exist in WS_URL_DETAIL for year " +
                            year)
                return  # This happens if the webservices are not that good.
            for member in members:
                try:

                    up = UserProfile.objects.get(
                        rrhh_code=member['cod_persona'])
                except UserProfile.DoesNotExist:
                    response = ws.get(st.WS_DOCUMENT % member['cod_persona'])
                    document = response['numero_documento'] + response['letra']
                    up = UserProfile.get_or_create_user(document,
                                                        document)[0].profile
                    up.rrhh_code = member['cod_persona']
                    up.save()
                    up.user.first_name = member['cod_persona__nombre']
                    up.user.last_name = (member['cod_persona__apellido1'] +
                                         " " +
                                         member['cod_persona__apellido2'])[:30]
                    up.user.save()
                    ReportMember.objects.get_or_create(user_profile=up)

                setattr(up.reportmember, self.type, self)
                up.reportmember.cce = member['cod_cce__descripcion']
                up.reportmember.save()
Пример #2
0
 def get_investigadores(self, unit, title):
     if unit is None:
         return NotImplemented
     unit_content = ws.get(self.WS_URL_DETAIL % (unit, self.year))[0]
     if unit_content["unidad"] == {}:
         try:
             unit_name = filter(lambda x: x['code'] == unit,
                                self.unit_names)[0]['name']
         except (AttributeError, KeyError):
             unit_name = unicode(unit)
         logger.warn(u"La unidad " + unit_name +
                     u" no tiene información en " + unicode(self.year))
         return [], [], unit_name
     investigadores = []
     usuarios = []
     for inv in unit_content['miembros']:
         inv = self._check_inves(inv)
         investigadores.append(inv)
         try:
             up = UserProfile.objects.get(rrhh_code=inv['cod_persona'])
         except UserProfile.DoesNotExist:
             response = ws.get(st.WS_DOCUMENT % inv['cod_persona'])
             document = response['numero_documento'] + response['letra']
             up = UserProfile.get_or_create_user(document,
                                                 document)[0].profile
             up.rrhh_code = inv['cod_persona']
             up.save()
             up.user.first_name = inv['cod_persona__nombre']
             up.user.last_name = (inv['cod_persona__apellido1'] + " " +
                                  inv['cod_persona__apellido2'])[:30]
             up.user.save()
         usuarios.append(up)
     if title is None:
         title = unit_content['unidad']['nombre']
     return investigadores, usuarios, title
    def handle(self, *args, **options):
        database = (options['database']
                    if options['database'] is not None else 'default')
        with in_database(database, write=True):
            cvn_file = os.path.join(st_cvn.MIGRATION_ROOT,
                                    'users_to_migrate.csv')
            with open(cvn_file, 'rb') as csvfile:
                lines = csv.reader(csvfile, dialect=st.CSV_DIALECT)
                for line in lines:
                    user, created = UserProfile.get_or_create_user(
                        username=unicode(line[0]), documento=unicode(line[1]))
                    if created:
                        user.first_name = line[3]
                        user.last_name = line[4]
                        user.save()

                    # Reload user to have profile updated
                    user = User.objects.get(pk=user.profile.user.pk)
                    try:
                        pdf_file = os.path.join(st_cvn.MIGRATION_ROOT, line[2])
                        upload_file = open(pdf_file)
                    except IOError:
                        print(
                            u'[%s] \t \t ERROR: CVN No encontrado (%s - %s)' %
                            (lines.line_num, line[0], line[2]))
                        continue
                    cvn_file = SimpleUploadedFile(
                        upload_file.name,
                        upload_file.read(),
                        content_type="application/pdf")
                    upload_file.close()
                    try:
                        user.profile.cvn.remove()
                        user.profile.cvn.delete()
                    except ObjectDoesNotExist:
                        pass
                    form = UploadCVNForm(initial={'cvn_file': cvn_file},
                                         user=user)
                    if form.is_valid():
                        cvn = form.save()
                        cvn.insert_xml()
                        print u'[%s] Usuario: %s - CVN: %s \t \t OK' % (
                            lines.line_num, line[0], line[2])
                    else:
                        print u'[%s] \t \t ERROR: CVN No válido (%s - %s)' % (
                            lines.line_num, line[0], line[2])
Пример #4
0
 def authenticate(self, ticket, service, request):
     """Verifies CAS ticket and gets or creates User object"""
     username, attributes = _verify(ticket, service)
     # If we don't have the user's document we'll not allow him to do login
     if (not attributes or not 'NumDocumento' in attributes
             or attributes['NumDocumento'] is None):
         st.CAS_RETRY_LOGIN = False
         return None
     # If type of account of the user isn't allow then
     # we will not allow him to do login
     if (attributes and 'TipoCuenta' in attributes
             and attributes['TipoCuenta'] in st.CAS_TIPO_CUENTA_NOAUT):
         st.CAS_RETRY_LOGIN = False
         return None
     request.session['attributes'] = attributes
     documento = attributes['NumDocumento']
     return UserProfile.get_or_create_user(username, documento)[0]
Пример #5
0
 def authenticate(self, ticket, service, request):
     """Verifies CAS ticket and gets or creates User object"""
     username, attributes = _verify(ticket, service)
     # If we don't have the user's document we'll not allow him to do login
     if (not attributes or not 'NumDocumento' in attributes
             or attributes['NumDocumento'] is None):
         st.CAS_RETRY_LOGIN = False
         return None
     # If type of account of the user isn't allow then
     # we will not allow him to do login
     if (attributes and 'TipoCuenta' in attributes
             and attributes['TipoCuenta'] in st.CAS_TIPO_CUENTA_NOAUT):
         st.CAS_RETRY_LOGIN = False
         return None
     request.session['attributes'] = attributes
     documento = attributes['NumDocumento']
     return UserProfile.get_or_create_user(username, documento)[0]
 def test_selenium_cambio_incorrecto_dni(self):
     user = UserProfile.get_or_create_user('invipas', '72693103Q')[0]
     user.set_password("pruebasINV1")
     user.is_staff = True
     user.is_superuser = True
     user.save()
     driver = self.driver
     driver.get(self.base_url + "/cas-1/login?service=http%3A%2F%2Flocalhost"
                                "%3A8081%2Finvestigacion%2Faccounts%2Flogin"
                                "%2F%3Fnext%3D%252Finvestigacion%252Fadmin"
                                "%252Flogin%252F%253Fnext%253D%252F"
                                "investigacion%252Fadmin%252F")
     driver.find_element_by_id("username").clear()
     driver.find_element_by_id("username").send_keys("invipas")
     driver.find_element_by_id("password").clear()
     driver.find_element_by_id("password").send_keys("pruebasINV1")
     driver.find_element_by_name("submit").click()
     driver.find_element_by_link_text("User profiles").click()
     driver.find_element_by_id("searchbar").clear()
     driver.find_element_by_id("searchbar").send_keys(user.username)
     driver.find_element_by_css_selector("input[type=\"submit\"]").click()
     driver.find_element_by_css_selector("tr.row1 > td.action-checkbox > "
                                         "input[name=\"_selected_action\"]"
                                         ).click()
     Select(driver.find_element_by_name("action")
            ).select_by_visible_text("Change user's DNI")
     driver.find_element_by_name("index").click()
     driver.find_element_by_id("id_new_dni").clear()
     driver.find_element_by_id("id_new_dni").send_keys("88888888B")
     driver.find_element_by_name("apply").click()
     try:
         result = driver.find_element_by_class_name("info").text
     except NoSuchElementException:
         result = ''
     self.assertFalse(u'Successfully changed dni.' in result)
     self.assertEqual("72693103Q", UserProfile.objects.get(
         user__username='******').documento)