Esempio n. 1
0
    def __init__(self, protocol, settings):
        """
		"""
        # 		""" The constructor does not only take the protocol but also
        # 		the house_code, the group_code and the unit_code of the newly
        # 		discovered remote as arguments since they will always remain
        # 		the same.
        #
        # 		"""

        super(NexaBaseSwitch, self).__init__()
        self.protocol = protocol

        self.set(settings)

        self.id = self.protocol.id + '_' + self.device_key + '_' + str(
            self.settings['house_code']) + '_' + str(
                self.settings['unit_code'])

        self.state = Information('state',
                                 True,
                                 'bool', {
                                     'name': '',
                                     'description': ''
                                 },
                                 device=self)

        self.informations = [self.state]
        self.actions = []
Esempio n. 2
0
def register():
    if request.method == "GET":
        return render_template('register.html')
    else:
        email = request.form.get('email')
        username = request.form.get('username')
        password1 = request.form.get('password1')
        password2 = request.form.get('password2')
        #check whether the email is already registered
        user = User.query.filter(User.email == email).first()

        if user:
            return u'This email is already registered. Please change another one'
        else:
            # check whether two passwords are the same
            if password1 != password2:
                return u'Passwords are not the same.'
            else:
                password = generate_password_hash(password1)
                user = User(email=email,
                            username=username,
                            password=password,
                            number_of_post=0,
                            number_of_comment=0,
                            point=0,
                            grade=1,
                            photo="images/default.png",
                            confirmed=False,
                            admin=0,
                            report_time=datetime.now() + timedelta(days=-100))

                info = Information(user_id=user.id,
                                   number_of_followed=0,
                                   number_of_following=0)
                info.owner = user
                db.session.add(user)
                db.session.add(info)
                db.session.commit()
                token = generate_confirmation_token(user.email)

                confirm_url = url_for('confirm_email',
                                      token=token,
                                      _external=True)
                html = render_template('activate.html',
                                       confirm_url=confirm_url)
                subject = "Please confirm your email"
                send_email(user.email, subject, html)

                login_user(user)

                return redirect(url_for("unconfirmed"))
Esempio n. 3
0
def postProfileBusiness(id):
    info_supplier = json.loads(request.data)
    info_old = Information.query.filter_by(business_id=info_supplier["business_id"], business_legal_name=info_supplier["business_legal_name"]).filter_by(supplier_id=id).first()
    if info_old is None:
        information = Information(
            business_legal_name=info_supplier["business_legal_name"], 
            business_id=info_supplier["business_id"],
            card_name=info_supplier["card_name"], 
            card_number=info_supplier["card_number"], 
            cvv=info_supplier["cvv"],
            date=info_supplier['date'],
            address=info_supplier["address"], 
            comuna=info_supplier["comuna"],
            region=info_supplier["region"],
            supplier_id=id
        )
        db.session.add(information)
        db.session.commit()
        return jsonify({"exitoso": True}), 200
    if info_old is not None:
        info_old = Information.query.filter_by(supplier_id=id).first()
        info_old.business_legal_name = request.json.get('business_legal_name', info_old.business_legal_name)
        info_old.business_id = request.json.get('business_id', info_old.business_id)
        info_old.card_name = request.json.get('card_name', info_old.card_name)
        info_old.card_number = request.json.get('card_number', info_old.card_number)
        info_old.cvv = request.json.get('cvv', info_old.cvv)
        info_old.date = request.json.get('year', info_old.date)
        info_old.address = request.json.get('address', info_old.address) 
        info_old.comuna = request.json.get('comuna', info_old.comuna) 
        info_old.region = request.json.get('region', info_old.region)
        db.session.commit()
        return jsonify({"msge": "Actualizacion de pefil realizado"}), 200
Esempio n. 4
0
def index():
    # 初始化 user 模型,并设置数据并添加到数据库
    info = Information()
    data = info.query.all()

    # 返回注册结果
    return jsonify({'data': data})
Esempio n. 5
0
def index():
    from models import Information
    # 初始化 user 模型,并设置数据并添加到数据库
    info = Information()
    data = info.query.all()
    print(data)

    # 返回注册结果
    return jsonify({'name': '123', 'words': '132'})
Esempio n. 6
0
 def upload_data(self, data):
     print('Uploading data into {0}.'.format(self.args.database))
     for row in self.db.batch_commit(data, 100):
         id = Information.create(**row)
         photos = []
         for photo in row['photos']:
             photos.append((id, photo))
         Photos.insert_many(photos, fields=[Photos.master_id,
                                            Photos.link]).execute()
Esempio n. 7
0
    def __init__(self, kernel, *args, **kwargs):
        super(InfoBlock, self).__init__(*args, **kwargs)

        self.kernel = kernel

        self.input = SimpleInputNode(self, 'input', 'in', 'bool')

        self.state = Information('state',
                                 False,
                                 'bool', {
                                     'name': '',
                                     'description': ''
                                 },
                                 block=self)

        self.kernel.infos.append(self.state)

        self.nodes = [self.input]

        self.set({'name': 'Info block', 'info_name': 'new virtual info'})
Esempio n. 8
0
class InfoBlock(Block):

    settings_format = Block.settings_format + [{
        'type': 'string',
        'title': 'Info name',
        'desc': 'Name of the new info',
        'key': 'info_name'
    }]

    def __init__(self, kernel, *args, **kwargs):
        super(InfoBlock, self).__init__(*args, **kwargs)

        self.kernel = kernel

        self.input = SimpleInputNode(self, 'input', 'in', 'bool')

        self.state = Information('state',
                                 False,
                                 'bool', {
                                     'name': '',
                                     'description': ''
                                 },
                                 block=self)

        self.kernel.infos.append(self.state)

        self.nodes = [self.input]

        self.set({'name': 'Info block', 'info_name': 'new virtual info'})

    def process(self, changed_input):
        self.state.update(self.input.get_value())

    def set(self, settings):
        super(InfoBlock, self).set(settings)

        if settings.has_key('info_name'):
            self.state.set({'name': settings['info_name']})

    def before_remove(self):
        self.kernel.remove(self.state)
def postProfileBusiness():
    info_supplier = json.loads(request.data)

    information = Information(
        business_legal_name=info_supplier["business_legal_name"],
        business_id=info_supplier["business_id"],
        card_name=info_supplier["card_name"],
        card_number=info_supplier["card_number"],
        cvv=info_supplier["cvv"],
        month=info_supplier["month"],
        year=info_supplier["year"],
        address=info_supplier["address"],
        comuna=info_supplier["comuna"],
        region=info_supplier["region"],
        supplier_id=info_supplier["supplier_id"])

    db.session.add(information)
    db.session.commit()
    return jsonify({"exitoso": True}), 200
Esempio n. 10
0
class NexaBaseSwitch(Device):

    # Ce sont des attributs de classe, qui sont donc independants de
    # toute instantiation de la classe
    device_key = 'NexaBaseSwitch'

    settings_format = [{
        'type': 'string',
        'title': 'Name',
        'desc': 'Name of the device',
        'key': 'name'
    }, {
        'type': 'string_long',
        'title': 'Description',
        'desc': 'Description of the device',
        'key': 'description'
    }, {
        'type': 'num_int',
        'title': 'House code',
        'desc': 'Must be between 0 and 67 108 863',
        'key': 'house_code',
        'disabled': True
    }, {
        'type': 'num_int',
        'title': 'Group code',
        'desc': 'Must be either 0 or 1',
        'key': 'group_code',
        'disabled': True
    }, {
        'type': 'num_int',
        'title': 'Unit code',
        'desc': 'Must be between 0 and 15',
        'key': 'unit_code',
        'disabled': True
    }]

    def __init__(self, protocol, settings):
        """
		"""
        # 		""" The constructor does not only take the protocol but also
        # 		the house_code, the group_code and the unit_code of the newly
        # 		discovered remote as arguments since they will always remain
        # 		the same.
        #
        # 		"""

        super(NexaBaseSwitch, self).__init__()
        self.protocol = protocol

        self.set(settings)

        self.id = self.protocol.id + '_' + self.device_key + '_' + str(
            self.settings['house_code']) + '_' + str(
                self.settings['unit_code'])

        self.state = Information('state',
                                 True,
                                 'bool', {
                                     'name': '',
                                     'description': ''
                                 },
                                 device=self)

        self.informations = [self.state]
        self.actions = []

    def update(self, unit_code, new_command):
        """ Method called to update the state of the device. 
		It updates the linked Information accordingly.		
		
		"""

        print unit_code
        # 		try:
        if unit_code == self.settings['unit_code']:
            if new_command == 1:
                self.state.update(True)
            elif new_command == 0:
                self.state.update(False)
            else:
                raise ValueError("The new state was neither 0 nor 1.")


# 		except Exception, e:
# 			raise e

    def set(self, settings):
        super(NexaBaseSwitch, self).set(settings)

        if settings.has_key('name') and hasattr(self, 'state'):
            self.state.set({'name': 'State of ' + self.settings['name']})
Esempio n. 11
0
    def __init__(self, protocol, settings):
        """ The constructor only takes the protocol to which
		the device is linked as argument.
		
		
		"""
        super(NexaDevice, self).__init__()

        self.protocol = protocol

        # Si on ne les spécifie pas, ce sont des valeurs aléatoires
        self.settings['house_code'] = int(random() * 67108863)
        self.settings['group_code'] = 0
        self.settings['unit_code'] = int(random() * 15)

        self.settings['name'] = ''
        self.settings['description'] = ''
        self.settings['location'] = ''

        # On construit l'ID de sorte qu'il soit unique
        self.id = self.protocol.id + '_' + self.device_key + '_' + str(
            self.settings['house_code']) + '_' + str(
                self.settings['unit_code'])

        # On nomme explicitement l'info pour qu'elle soit plus simple à
        # designer dans le code
        self.state = Information(key='state',
                                 primary=True,
                                 device=self,
                                 value_type='bool',
                                 settings={
                                     'name':
                                     "State of the Nexa device " +
                                     str(self.settings['house_code']) + "/" +
                                     str(self.settings['unit_code']),
                                     'description':
                                     "Gives the state of the device."
                                 })
        self.informations = [self.state]

        self.switch_on_action = Action(
            key='on',
            primary=True,
            device=self,
            callback=self.switch_on,
            arguments=[],
            settings={
                'name':
                "Switch Nexa " + str(self.settings['house_code']) + "/" +
                str(self.settings['unit_code']) + " on",
                'description':
                "Switch this device on."
            })
        self.switch_off_action = Action(
            key='off',
            primary=True,
            device=self,
            callback=self.switch_off,
            arguments=[],
            settings={
                'name':
                "Switch Nexa " + str(self.settings['house_code']) + "/" +
                str(self.settings['unit_code']) + " of",
                'description':
                "Switch this device off."
            })
        self.sync_action = Action(
            key='sync',
            primary=True,
            device=self,
            callback=self.sync,
            arguments=[],
            settings={
                'name':
                "Sync Nexa " + str(self.settings['house_code']) + "/" +
                str(self.settings['unit_code']),
                'description':
                "Sync this device with Yeah!"
            })
        self.unsync_action = Action(
            key='unsync',
            primary=True,
            device=self,
            callback=self.unsync,
            arguments=[],
            settings={
                'name':
                "Unsync Nexa " + str(self.settings['house_code']) + "/" +
                str(self.settings['unit_code']),
                'description':
                "Unsync this device from Yeah!"
            })
        self.actions = [
            self.switch_on_action, self.switch_off_action, self.sync_action,
            self.unsync_action
        ]

        self.set(settings)
Esempio n. 12
0
class NexaDevice(Device):
    """ This is the class used to implement any Nexa-controlled device.
	 
	"""

    # Ce sont des attributs de classe, qui sont donc independants de
    # toute instantiation de la classe

    device_key = 'NexaDevice'

    settings_format = [{
        'type': 'string',
        'title': 'Name',
        'desc': 'Name of the device',
        'key': 'name'
    }, {
        'type': 'string_long',
        'title': 'Description',
        'desc': 'Description of the device',
        'key': 'description'
    }, {
        'type': 'string',
        'title': 'Location',
        'desc': 'The place where the device is located',
        'key': 'location'
    }, {
        'type': 'num_int',
        'title': 'House code',
        'desc': 'Must be between 0 and 67 108 863',
        'key': 'house_code'
    }, {
        'type': 'num_int',
        'title': 'Group code',
        'desc': 'Must be either 0 or 1',
        'key': 'group_code'
    }, {
        'type': 'num_int',
        'title': 'Unit code',
        'desc': 'Must be between 0 and 15',
        'key': 'unit_code'
    }]

    #
    def __init__(self, protocol, settings):
        """ The constructor only takes the protocol to which
		the device is linked as argument.
		
		
		"""
        super(NexaDevice, self).__init__()

        self.protocol = protocol

        # Si on ne les spécifie pas, ce sont des valeurs aléatoires
        self.settings['house_code'] = int(random() * 67108863)
        self.settings['group_code'] = 0
        self.settings['unit_code'] = int(random() * 15)

        self.settings['name'] = ''
        self.settings['description'] = ''
        self.settings['location'] = ''

        # On construit l'ID de sorte qu'il soit unique
        self.id = self.protocol.id + '_' + self.device_key + '_' + str(
            self.settings['house_code']) + '_' + str(
                self.settings['unit_code'])

        # On nomme explicitement l'info pour qu'elle soit plus simple à
        # designer dans le code
        self.state = Information(key='state',
                                 primary=True,
                                 device=self,
                                 value_type='bool',
                                 settings={
                                     'name':
                                     "State of the Nexa device " +
                                     str(self.settings['house_code']) + "/" +
                                     str(self.settings['unit_code']),
                                     'description':
                                     "Gives the state of the device."
                                 })
        self.informations = [self.state]

        self.switch_on_action = Action(
            key='on',
            primary=True,
            device=self,
            callback=self.switch_on,
            arguments=[],
            settings={
                'name':
                "Switch Nexa " + str(self.settings['house_code']) + "/" +
                str(self.settings['unit_code']) + " on",
                'description':
                "Switch this device on."
            })
        self.switch_off_action = Action(
            key='off',
            primary=True,
            device=self,
            callback=self.switch_off,
            arguments=[],
            settings={
                'name':
                "Switch Nexa " + str(self.settings['house_code']) + "/" +
                str(self.settings['unit_code']) + " of",
                'description':
                "Switch this device off."
            })
        self.sync_action = Action(
            key='sync',
            primary=True,
            device=self,
            callback=self.sync,
            arguments=[],
            settings={
                'name':
                "Sync Nexa " + str(self.settings['house_code']) + "/" +
                str(self.settings['unit_code']),
                'description':
                "Sync this device with Yeah!"
            })
        self.unsync_action = Action(
            key='unsync',
            primary=True,
            device=self,
            callback=self.unsync,
            arguments=[],
            settings={
                'name':
                "Unsync Nexa " + str(self.settings['house_code']) + "/" +
                str(self.settings['unit_code']),
                'description':
                "Unsync this device from Yeah!"
            })
        self.actions = [
            self.switch_on_action, self.switch_off_action, self.sync_action,
            self.unsync_action
        ]

        self.set(settings)

    def switch_on(self, args):
        """ *(Internal)* Method called when the "on" action is triggered. 
		On the one side, it sends the radio command accordingly.
		On the other side, it updates the Information which 
		reflects the state of the device.
		
		"""

        self.protocol.send_command(self, 1)
        self.state.update(True)

    def switch_off(self, args):
        """ *(Internal)* Method called when the "off" action is triggered. 
		On the one side, it sends the radio command accordingly.
		On the other side, it updates the Information which 
		reflects the state of the device.
		
		"""

        self.protocol.send_command(self, 0)
        self.state.update(False)

    def sync(self, args):
        """ *(Internal)* Method called when the "sync" action is triggered. 
		It sends a series of "on" commands.
		
		"""

        for i in range(5):
            self.switch_on({})
            sleep(0.1)
            i += 1
        self.state.update(True)

    def unsync(self, args):
        """ *(Internal)* Method called when the "unsync" action is triggered. 
		It sends a series of "off" commands.
		
		"""

        for i in range(5):
            self.switch_off({})
            sleep(0.1)
            i += 1
        self.state.update(False)

    def set(self, settings):
        super(NexaDevice, self).set(settings)

        if settings != None:
            if settings.has_key('name'):
                self.state.set({'name': 'State of ' + self.settings['name']})
                self.switch_on_action.set(
                    {'name': 'Switch on ' + self.settings['name']})
                self.switch_off_action.set(
                    {'name': 'Switch off ' + self.settings['name']})
                self.sync_action.set({'name': 'Sync ' + self.settings['name']})
                self.unsync_action.set(
                    {'name': 'Unsync ' + self.settings['name']})