Ejemplo n.º 1
0
class PropertyForm(Form):
    def __repr__(self):
        return 'PropertyForm'

    def update_object(self, prop):
        prop.prop_type_id = self.prop_type_id.data
        prop.prop_operation_id = self.prop_operation_id.data
        prop.price_sell_currency = self.price_sell_currency.data
        prop.price_sell = to_float(self.price_sell.data)
        prop.price_rent_currency = self.price_rent_currency.data
        prop.price_rent = to_float(self.price_rent.data)
        prop.price_expensas = to_float(self.price_expensas.data)
        prop.rooms = to_int(self.rooms.data)
        prop.bedrooms = to_int(self.bedrooms.data)
        prop.bathrooms = to_int(self.bathrooms.data)
        prop.building_floors = to_int(self.building_floors.data)
        prop.year_built = self.year_built.data
        prop.area_indoor = to_int(self.area_indoor.data)
        prop.area_outdoor = to_int(self.area_outdoor.data)
        prop.prop_state_id = self.prop_state_id.data
        prop.appurtenance = to_int(self.appurtenance.data)
        prop.balcony = to_int(self.balcony.data)
        prop.doorman = to_int(self.doorman.data)
        prop.elevator = to_int(self.elevator.data)
        prop.fireplace = to_int(self.fireplace.data)
        prop.furnished = to_int(self.furnished.data)
        prop.garage = to_int(self.garage.data)
        prop.garden = to_int(self.garden.data)
        prop.grillroom = to_int(self.grillroom.data)
        prop.gym = to_int(self.gym.data)
        prop.live_work = to_int(self.live_work.data)
        prop.luxury = to_int(self.luxury.data)
        prop.pool = to_int(self.pool.data)
        prop.terrace = to_int(self.terrace.data)
        prop.washer_dryer = to_int(self.washer_dryer.data)
        prop.sum = to_int(self.sum.data)
        prop.main_description = self.main_description.data
        prop.country = self.country.data
        prop.state = self.state.data
        prop.city = self.city.data
        prop.neighborhood = self.neighborhood.data
        prop.street_name = self.street_name.data
        prop.street_number = to_int(self.street_number.data)
        prop.floor_number = self.floor_number.data
        prop.location = self.location.data
        prop.agua_corriente = to_int(self.agua_corriente.data)
        prop.gas_natural = to_int(self.gas_natural.data)
        prop.gas_envasado = to_int(self.gas_envasado.data)
        prop.luz = to_int(self.luz.data)
        prop.cloacas = to_int(self.cloacas.data)
        prop.telefono = to_int(self.telefono.data)
        prop.tv_cable = to_int(self.tv_cable.data)
        prop.internet = to_int(self.internet.data)
        prop.vigilancia = to_int(self.vigilancia.data)
        prop.monitoreo = to_int(self.monitoreo.data)

        #TODO: Sacar de donde va
        prop.prop_operation_state_id = to_int(
            self.prop_operation_state_id.data)
        prop.prop_owner_id = 1

        prop.cardinal_direction = self.cardinal_direction.data
        return prop

    def __init__(self, formdata=None, obj=None, **kwargs):
        super(PropertyForm, self).__init__(formdata=formdata,
                                           obj=obj,
                                           **kwargs)
        self.sell_yes.data = self.prop_operation_id.data != None and self.prop_operation_id.data & Property._OPER_SELL != 0
        self.rent_yes.data = self.prop_operation_id.data != None and self.prop_operation_id.data & Property._OPER_RENT != 0

        # HACKU: de marku para que no aparezca 0 cuando es 'sin dato' en los enteros
        int_fileds = [
            'area_indoor', 'area_outdoor', 'rooms', 'bedrooms', 'bathrooms',
            'building_floors', 'street_number'
        ]
        for int_filed in int_fileds:
            p = getattr(self, int_filed)
            if str(getattr(p, 'data')) == '0':
                setattr(p, 'data', '')

    # --- type.html
    prop_type_id = SelectField(choices=[(str(hex(i + 1)[2:]), short_descs[i])
                                        for i in range(0, len(short_descs))])
    prop_operation_id = IntegerField('', [
        validators.required(
            message=u'Debe elegir al menos un tipo de operación')
    ],
                                     default=0)

    price_sell_currency = SelectField(choices=[('ARS', '$'), ('USD', 'USD')])
    price_sell = TextField()
    sell_yes = BooleanField('Venta', id='op_' + str(Property._OPER_SELL))

    price_rent_currency = SelectField(choices=[('ARS', '$'), ('USD', 'USD')])
    price_rent = TextField()
    rent_yes = BooleanField('Alquiler', id='op_' + str(Property._OPER_RENT))
    price_expensas = TextField()

    def validate_price_expensas(form, field):
        my_float_validator_simple(field)

    def validate_price_rent(form, field):
        my_float_validator(
            field, form.prop_operation_id.data & Property._OPER_RENT != 0)

    def validate_price_sell(form, field):
        my_float_validator(
            field, form.prop_operation_id.data & Property._OPER_SELL != 0)

    def validate_area_indoor(form, field):
        my_int_validator(field)

    def validate_area_outdoor(form, field):
        my_int_validator(field)

    def validate_rooms(form, field):
        my_int_validator(field)

    def validate_bedrooms(form, field):
        my_int_validator(field)

    def validate_bathrooms(form, field):
        my_int_validator(field)

    def validate_building_floors(form, field):
        my_int_validator(field)

    def validate_street_number(form, field):
        my_int_validator(field)

    # ---- features.html
    rooms = TextField('Ambientes')
    bedrooms = TextField('Dormitorios')
    bathrooms = TextField('Toilettes')
    building_floors = TextField('Plantas/Pisos')

    year_built = SelectField(
        u'Antigüedad',
        coerce=int,
        choices=[(0, 'Sin Datos')] +
        [(features['year_built']['rangos'][i],
          features['year_built']['descriptions'][i])
         for i in range(1, len(features['year_built']['rangos']))])
    area_indoor = TextField('Superficie Cubierta', description=u'm²')
    area_outdoor = TextField('Superficie Descubierta', description=u'm²')
    prop_state_id = SelectField(
        u'Estado General',
        coerce=int,
        choices=[(0, 'Sin Datos')] +
        [(features['prop_state_id']['rangos'][i],
          features['prop_state_id']['descriptions'][i])
         for i in range(1,
                        len(features['prop_state_id']['rangos']) - 1)])

    #cardinal_direction      =  SelectField(u'Orientación', choices=[(1, 'Norte'), (2, 'Noreste'), (3, 'Este'), (4, 'Sureste'), (5, 'Sur'), (6, 'Suroeste'), (7, 'Oeste'), (8, 'Noroeste')])
    cardinal_direction = SelectField(u'Orientación',
                                     choices=[('', 'No disponible'),
                                              ('Norte', 'Norte'),
                                              ('Noreste', 'Noreste'),
                                              ('Este', 'Este'),
                                              ('Sureste', 'Sureste'),
                                              ('Sur', 'Sur'),
                                              ('Suroeste', 'Suroeste'),
                                              ('Oeste', 'Oeste'),
                                              ('Noroeste', 'Noroeste')])

    prop_operation_state_id = SelectField(
        u'Etiqueta',
        coerce=int,
        choices=[(Property._OPER_STATE_NADA, '-ninguna-'),
                 (Property._OPER_STATE_RESERVADO, 'Reservado'),
                 (Property._OPER_STATE_SUSPENDIDO, 'Suspendido'),
                 (Property._OPER_STATE_VENDIDO, 'Vendido'),
                 (Property._OPER_STATE_ALQUILADO, 'Alquilado'),
                 (Property._OPER_STATE_OPORTUNIDAD, 'Oportunidad'),
                 (Property._OPER_STATE_DE_POZO, 'De pozo'),
                 (Property._OPER_STATE_APTO_CREDITO, u'Apto Crédito'),
                 (Property._OPER_STATE_IMPECABLE, 'Impecable'),
                 (Property._OPER_STATE_INVERSION, u'Inversión')])

    # --- more_features.html
    appurtenance = BooleanField('Dependencia')
    balcony = BooleanField(u'Balcón')
    doorman = BooleanField('Portero')
    elevator = BooleanField('Ascensor')
    fireplace = BooleanField('Estufa Hogar')
    furnished = BooleanField('Amoblado')
    garage = BooleanField('Garage')
    garden = BooleanField('Parque')
    grillroom = BooleanField('Parrilla')
    gym = BooleanField('Gimnasio')
    live_work = BooleanField('Apto Profesional')
    luxury = BooleanField('Lujo')
    pool = BooleanField('Piscina')
    terrace = BooleanField('Terraza')
    washer_dryer = BooleanField(u'Lavandería')
    sum = BooleanField('SUM')

    main_description = TextAreaField(u'Descripción de la propiedad', [
        validators.optional(),
        validators.length(
            max=5120,
            message=u'La descripción debe ser como maximo %(max)s caracteres')
    ])

    # --- location.html
    country = TextField(u'País')
    state = TextField(u'Región/Provincia')
    city = TextField('Localidad')
    neighborhood = TextField('Barrio')
    street_name = TextField('Calle')
    street_number = TextField('Altura', widget=MyTextInput())
    floor_number = TextField('Piso/Dpto.', widget=MyTextInput())
    location = GeoPtPropertyField()

    # --- services.html
    agua_corriente = BooleanField('Agua corriente')
    gas_natural = BooleanField('Gas natural')
    gas_envasado = BooleanField('Gas envasado')
    luz = BooleanField('Luz')
    cloacas = BooleanField('Cloacas')
    telefono = BooleanField(u'Teléfono')

    tv_cable = BooleanField(u'Televisión por Cable')
    internet = BooleanField('Internet')
    vigilancia = BooleanField('Vigilancia privada')
    monitoreo = BooleanField(u'Monitoreo electrónico')
Ejemplo n.º 2
0
def convert_GeoPtProperty(model, prop, kwargs):
    """Returns a form field for a ``db.GeoPtProperty``."""
    return GeoPtPropertyField(**kwargs)
Ejemplo n.º 3
0
 class GeoTestForm(Form):
     geo = GeoPtPropertyField()