示例#1
0
def estimulos(request):
    sisben = Sisben.objects.all()
    estrato = Estrato.objects.all()

    if request.method == 'POST':
        validators = Validator(request.POST)
        validators.required = ['nombre','apellido','documento','carrera','genero','sisben','estrato','direccion','contacto','nacimiento','email']
        if validators.is_valid():
            estudiante = Estudiante()
            estudiante.nombres = request.POST['nombre']
            estudiante.apellidos = request.POST['apellido']
            estudiante.documento = request.POST['documento']
            estudiante.carrera = request.POST['carrera']
            estudiante.genero= request.POST['genero']
            estudiante.sisben = request.POST['sisben']
            estudiante.estrato_id = request.POST['estrato']
            estudiante.direccion = request.POST['direccion']
            estudiante.contacto = request.POST['contacto']
            estudiante.nacimiento = request.POST['nacimiento']
            estudiante.email = request.POST['email']
            estudiante.save()

        else:
            return render_to_response('inicio.html' , context_instance = RequestContext(request))
    return render_to_response('estimulos.html', {'estrato':estrato } ,context_instance = RequestContext(request))
示例#2
0
def matriculas(request):
    grad = Grado.objects.all()
    #sisben = Sisben.objects.all()
    estrato = Estrato.objects.all()

    if request.method == 'POST':
        validators = Validator(request.POST)
        validators.required = ['nombre','apellido','documento','grado','genero','sisben','estrato','trasporte','direccion','familias','alimentacion','desplazado','contacto','nacimiento','email','credo']
        if validators.is_valid():
            alumno = Alumno()
            alumno.nombres = request.POST['nombre']
            alumno.apellidos = request.POST['apellido']
            alumno.documento = request.POST['documento']
            alumno.grado_id = request.POST['grado']
            alumno.genero= request.POST['genero']
            alumno.sisben = request.POST['sisben']
            alumno.estrato_id = request.POST['estrato']
            alumno.transporte = request.POST['trasporte']
            alumno.direccion = request.POST['direccion']
            alumno.familias = request.POST['familias']
            alumno.alimentacion = request.POST['alimentacion']
            alumno.desplazado = request.POST['desplazado']
            alumno.contacto = request.POST['contacto']
            alumno.nacimiento = request.POST['nacimiento']
            alumno.email = request.POST['email']
            alumno.credo = request.POST['credo']
            alumno.save()


            print(alumno.nombres)
        else:
            return render_to_response('matriculas.html' , context_instance = RequestContext(request))
    return render_to_response('matriculas.html', {'gradoss':grad,'estrato':estrato } ,context_instance = RequestContext(request))
示例#3
0
        def authorize(self, user, act_as, resource, data, content_type, action = None):
            if not action:
                action = 'GET'
            if not user or not act_as or not resource:
                return AuthorizeResult(False)

            if user not in self.data.keys() or act_as not in self.data.keys():
                logger.warning("Invalid user [{}] or act as user [{}]".format(user, act_as))
                return AuthorizeResult(False)

            if user != act_as:
                if 'can_act_as' not in self.data[user]:
                    logger.warning("User {} not authorized to act as {}".format(user, act_as))
                    return AuthorizeResult(False)

            allowed_users_list = self._get_act_as_list(user)

            if act_as not in allowed_users_list:
                logger.warning("User {} not authorized to act as {}".format(user, act_as))
                return AuthorizeResult(False)

            allowed_users_list = []
            allowed_actions = []
            if 'action' in self.data[act_as] and self.data[act_as]['action'] != None:
                for item in self.data[act_as]['action'][action]:
                    temp_item = {}
                    if type(item) == str:
                        temp_item = {}
                        temp_item[item] = {}
                    else:
                        if type(item) == dict:
                            temp_item = item

                    if not temp_item in allowed_actions:
                        allowed_actions.append(temp_item)

            self._get_merged_data(act_as, allowed_users_list, allowed_actions, self.data, action)

            result = self.resource_check(resource, data, allowed_actions, content_type)
            if result == False:
                logger.warning("User {} acting as {} is not authorized to access [{}]".format(user, act_as, resource))
                return AuthorizeResult(False)

            try:
                validator = Validator()
                framework = FrameworkUtils().getFramework(resource)
                if not validator.validate(act_as, resource, action, data, framework):
                    logger.warning("Validation failed. Reasons - {}".format(validator.messages))
                    return AuthorizeResult(False, validator.messages)
            except (Exception) as e:
                logger.error("Failed in request validation - {}".format(str(e)))
                return AuthorizeResult(False)

            return AuthorizeResult(True)
示例#4
0
def persona(request):
    if request.method == 'POST':
        validators = Validator(request.POST)
        validators.required = ['nombre','apellido','documento','email','sexo']
        if validators.is_valid():
            alumno = Alumno()
            alumno.nombres = request.POST['nombre']
            alumno.apellidos = request.POST['apellido']
            alumno.documento = request.POST['documento']
            alumno.email = request.POST['email']
            alumno.sexo = request.POST['sexo']
            alumno.save()
            print(alumno.nombres)
        else:
            return render_to_response('registrarse.html', {'error': validator.getMessage() } , context_instance = RequestContext(request))
    return render_to_response('formulario.html',context_instance = RequestContext(request))
示例#5
0
def registro(request):
    if request.method == 'POST':
        validators = Validator(request.POST)
        validators.required = ['nombre','user','password']
        if validators.is_valid():
            usuario = Usuario()
            usuario.first_name = request.POST['nombre']
            usuario.last_name = request.POST['apellido']
            usuario.username = request.POST['user']
            usuario.email = request.POST['email']
            usuario.password = make_password(request.POST['password'])
            usuario.is_active = True
            usuario.save()
            return render_to_response('portada.html',context_instance = RequestContext(request))
        else:
            return render_to_response('registrarse.html', {'error': validator.getMessage() } , context_instance = RequestContext(request))
    return render_to_response('formulario.html',context_instance = RequestContext(request))
示例#6
0
def docentes(request):
    if request.method == 'POST':
        validators = Validator(request.POST)
        validators.required = ['nombre','apellido','documento','email']
        if validators.is_valid():
            docentes = docente()
            docentes.nombres = request.POST['nombre']
            docentes.apellidos = request.POST['apellido']
            docentes.documento = request.POST['documento']
            docentes.email = request.POST['email']
            docentes.asignatura = request.POST['asignatura']
            docentes.contacto = request.POST['contacto']
            docentes.save()
            print(docentes.nombres)
        else:
            return render_to_response('docentes.html', {'error': validator.getMessage() } , context_instance = RequestContext(request))
    return render_to_response('docentes.html',context_instance = RequestContext(request))
示例#7
0
def registro(request):
    """view del profile
    """
    error = False
    if request.method == 'POST':
        validator = Validator(request.POST)
        validator.required = ['nombre', 'apellidos', 'email']

        if validator.is_valid():
            usuario = Usuario()
            #p = Persona.objects.get(documento = '123123123321')
            usuario.first_name = request.POST['nombre']
            usuario.last_name = request.POST['apellidos']
            usuario.username = request.POST['email']
            usuario.password = make_password(request.POST['password1'])
            #TODO: ENviar correo electronico para confirmar cuenta
            usuario.is_active = True
            usuario.save()
        else:
            return render_to_response('registrarse.html', {'error': validator.getMessage() } , context_instance = RequestContext(request))
        # Agregar el usuario a la base de datos
    return render_to_response('registrarse.html', context_instance = RequestContext(request))
示例#8
0
文件: views.py 项目: andrea016/ICBF
def unidadservicio(request):

    direcciones=Ubicacion.objects.all()
    departamentos = Departamento.objects.all()
    ciudades = Ciudad.objects.none()
    error = False
    if request.method == 'POST':
        validator = Validator(request.POST)
        validator.required = ['Nombre', 'Modalidades', 'departamentos', 'ciudades', 'direccion']

        if validator.is_valid():
            usuario = Operario()

            usuario.nombre_unidad_servicio = request.POST['Nombre']
            usuario.modalidad_de_servicio = request.POST['Modalidades']
            usuario.departamentos = request.POST['departamentos']
            usuario.ciudades = request.POST['ciudades']
            usuario.direccion = request.POST['direccion']
        else:
            return render_to_response('UDS.html', {'error': validator.getMessage()},
                                      context_instance=RequestContext(request))

    return render_to_response('UDS.html', {'dir':direcciones,'mod':mod_servicio1, 'departamentos': departamentos,
                                           'ciudades': ciudades}, context_instance=RequestContext(request))
示例#9
0
def startup():
    validators['uid'] = Validator("UID/TOKEN validator", r"^[0-9a-f]{32}$")
    validators['token'] = validators['uid']
    validators['slot'] = Validator("PORT/SLOT validator", r"^[0-9]+$")
    validators['port'] = validators['slot']
    validators['config'] = Validator("CONFIG validator", r".*")
示例#10
0
        def authorize(self,
                      user,
                      act_as,
                      resource,
                      data,
                      content_type,
                      action=None):
            if not action:
                action = 'GET'
            if not user or not act_as or not resource:
                return AuthorizeResult(False)

            if user not in self.data.keys() or act_as not in self.data.keys():
                logger.warning("Invalid user [{}] or act as user [{}]".format(
                    user, act_as))
                return AuthorizeResult(False)

            if user != act_as:
                if 'can_act_as' not in self.data[user]:
                    logger.warning(
                        "User {} not authorized to act as {}".format(
                            user, act_as))
                    return AuthorizeResult(False)

            allowed_users_list = self._get_act_as_list(user)

            if act_as not in allowed_users_list:
                logger.warning("User {} not authorized to act as {}".format(
                    user, act_as))
                return AuthorizeResult(False)

            allowed_users_list = []
            allowed_actions = []
            if 'action' in self.data[
                    act_as] and self.data[act_as]['action'] != None:
                for item in self.data[act_as]['action'][action]:
                    temp_item = {}
                    if type(item) == str:
                        temp_item = {}
                        temp_item[item] = {}
                    else:
                        if type(item) == dict:
                            temp_item = item

                    if not temp_item in allowed_actions:
                        allowed_actions.append(temp_item)

            self._get_merged_data(act_as, allowed_users_list, allowed_actions,
                                  self.data, action)

            result = self.resource_check(resource, data, allowed_actions,
                                         content_type)
            if result == False:
                logger.warning(
                    "User {} acting as {} is not authorized to access [{}]".
                    format(user, act_as, resource))
                return AuthorizeResult(False)

            try:
                validator = Validator()
                framework = FrameworkUtils().getFramework(resource)
                if not validator.validate(act_as, resource, action, data,
                                          framework):
                    logger.warning("Validation failed. Reasons - {}".format(
                        validator.messages))
                    return AuthorizeResult(False, validator.messages)
            except (Exception) as e:
                logger.error("Failed in request validation - {}".format(
                    str(e)))
                return AuthorizeResult(False)

            return AuthorizeResult(True)
示例#11
0
# Define Validators
########################################

#############
stop_validator = KeywordValidator('stop')
validators.append(stop_validator)


@stop_validator.set('action')
def validator_action(contact, message):
    print 'STOP messaging for {}'.format(contact)
    contact.set_status('stopped', 'Participant sent stop keyword')


############
validation_validator = Validator('validation')
validators.append(validation_validator)


@validation_validator.set('check')
def validator_action(contact, message):
    if re.match('^\d{5}$', message) and not contact.is_validated:
        if contact.validation_key == message.strip():
            message = 'Validation Code Correct: ' + message
            return True, {
                'topic': 'validation',
                'is_related': True,
                'is_viewed': True
            }, message
        else:
            message = 'Validation Code Incorrect: ' + message
 def test_validator_interface(self):
     with self.assertRaises(NotImplementedError) as context:
         Validator.validate(None)
示例#13
0
import json

import rlp
from casper_messages import PrepareMessage
from validators import Validator
from ethereum.utils import encode_hex

validators = [
    Validator(
        id=0,
        deposit=100000000000000000000,
        dynasty_start=0,
        dynasty_end=100000000000000000,
        withdrawal_time=100000000000000000000,
        withdrawal_addr='',
        addr='',
        max_prepared=0,
        max_committed=0
    )
]


class LevelDBStore(object):

    def __init__(self, db):
        self.db = db

        try:
            self.db.get('HEAD')
        except KeyError:
            self.init_db()
示例#14
0
from validators import Validator
username = '******'
validator = Validator()
if validator.username_is_valid(username):
    print("username is valid ")
else:
    print("username is invalid ")


if __name__ == "__main__":
    main = Main()
    communicator = Communicator()
    # import pydevd
    # port_mapping = [43777, 42797, 40239, 43883]
    # pydevd.settrace('localhost', port=port_mapping[communicator.rank], stdoutToServer=True, stderrToServer=True)

    if communicator.comm.rank == 0:
        beacon = Beacon()
        beacon.boot_beacon()
        beacon.send_acc_info()
    communicator.comm.barrier()
    if communicator.comm.rank != 0:
        validators = Validator()
        notarries = Nottaries()
    if communicator.rank == 1:  # one rank works as timer. First one, beacouse 0-th is more busy. Needed for examination
        time_list = [0]
        transactions_nb = [0]
        gg = True
    for tick in range(main.get__sim_time()):
        if communicator.rank == 0:
            if tick % 10 == 0:
                beacon.choose_rotated_nodes(beacon.notary_acc_info,
                                            beacon.nb_notary_migrates, 3)
            if tick % 25 == 0:
                beacon.choose_rotated_nodes(beacon.val_acc_info,
                                            beacon.nb_val_migrates, 4)
        communicator.comm.barrier()
        if communicator.rank != 0:
示例#16
0
import unittest
示例#17
0
@stop_validator.set('action')
def validator_action(message):
    print 'STOP messaging for {}'.format(message.contact)
    message.contact.set_status('stopped', 'Participant sent stop keyword')
    message.text += ' - participant withdrew'
    message.contact.send_automated_message(send_base='stop',
                                           send_offset=0,
                                           group='one-way',
                                           hiv_messaging=False,
                                           control=True)
    return False


###############
validation_validator = Validator('validation')
validators.append(validation_validator)


@validation_validator.set('check')
def validator_action(message):
    if re.match('^\d{5}$', message.text) and not message.contact.is_validated:
        message.topic = 'validation'
        message.is_related = True
        message.is_viewed = True
        if message.contact.validation_key == message.text.strip():
            message.text = 'Validation Code Correct: ' + message.text
            return True
        else:
            message.text = 'Validation Code Incorrect: ' + message.text
            return False