Esempio n. 1
0
    def __request_hash_map(self):
        """ Get from request.form the hash map values and check it """
        form = request.form
        self.hash_map['name'] = form['name']
        self.hash_map['value'] = {}

        # Check that the name hash map has between 2 and 20 characters
        if not check.length(self.hash_map['name'], 2, 20):
            self.message = g.hash_table_msg('error_1')

        # Verify that the format of the name is correct
        elif not check.username(self.hash_map['name']):
            self.message = g.hash_table_msg('error_2')

        # Get list labels added
        list_label = [
            int(x.split('_')[3]) for x in form if x.startswith('label_name_')
        ]

        # If there exists at least one field,
        # I can continue the adventure.
        if len(list_label) > 0:
            len_label = max(list_label) + 1

            # I look for fields that contain the keys,
            # then I browse to the field until the larger number.
            for i in range(len_label):
                label_key = 'label_name_{}_{}'.format(g.lan, i)

                # Check there is label in request.form
                if label_key in form:
                    key = form[label_key].strip()

                    # Check that the key has between 2 and 30 characters
                    if not check.length(key, 2, 30):
                        self.message = g.hash_table_msg('error_11')

                    # Verify that the format of the key is correct
                    elif not check.username(key):
                        self.message = g.hash_table_msg('error_12')

                    # It doesn't take into dictionary the empty keys
                    if check.length(key, 2, 30):
                        # Initial language values
                        self.hash_map['value'][key] = {}

                        for code in self.languages:
                            label_key = 'label_name_{}_{}'.format(code, i)
                            label_value = 'label_{}_{}'.format(code, i)

                            # Check there is label in request.form
                            # with this specific language
                            if label_key in form:
                                value = form[label_value]
                                self.hash_map['value'][key][code] = value
                            else:
                                self.hash_map['value'][key][code] = ''
Esempio n. 2
0
 def __request_hash_map(self):
     """ Get from request.form the hash map values and check it """
     form                     = request.form
     self.hash_map['name']    = form['name']
     self.hash_map['value']   = {}
     
     # Check that the name hash map has between 2 and 20 characters
     if not check.length(self.hash_map['name'], 2, 20):
         self.message = g.hash_table_msg('error_1')
     
     # Verify that the format of the name is correct
     elif not check.username(self.hash_map['name']):
         self.message = g.hash_table_msg('error_2')
     
     # Get list labels added
     list_label = [ int(x.split('_')[3]) for x in form if x.startswith('label_name_') ]
     
     # If there exists at least one field, 
     # I can continue the adventure.
     if len(list_label) > 0:
         len_label = max(list_label) + 1
         
         # I look for fields that contain the keys, 
         # then I browse to the field until the larger number.
         for i in range(len_label):
             label_key = 'label_name_{}_{}'.format(g.lan, i)
             
             # Check there is label in request.form
             if label_key in form:
                 key = form[label_key].strip()
                 
                 # Check that the key has between 2 and 30 characters
                 if not check.length(key, 2, 30):
                     self.message = g.hash_table_msg('error_11')
                     
                 # Verify that the format of the key is correct
                 elif not check.username(key):
                     self.message = g.hash_table_msg('error_12')
                 
                 # It doesn't take into dictionary the empty keys
                 if check.length(key, 2, 30):
                     # Initial language values
                     self.hash_map['value'][key] = {}
                     
                     for code in self.languages:
                         label_key   = 'label_name_{}_{}'.format(code, i)
                         label_value = 'label_{}_{}'.format(code, i)
                         
                         # Check there is label in request.form 
                         # with this specific language
                         if label_key in form:
                             value = form[label_value]
                             self.hash_map['value'][key][code] = value
                         else:
                             self.hash_map['value'][key][code] = ''
Esempio n. 3
0
 def update(self, _id):
     """ Update hash map """
     if g.my['rank'] < 15:
         self.__request_hash_map()
     else:
         self.__request_hash_map_user()
     
     if self.message is None:
         try:
             g.db.hash_table.update({ '_id' : ObjectId(_id)}, self.hash_map )
             self.status = 'msg msg-success'
             self.message = g.hash_table_msg('hash_updated')
         except PyMongoError:
             self.message = g.hash_table_msg('error_mongo_update')
Esempio n. 4
0
    def update(self, _id):
        """ Update hash map """
        if g.my['rank'] < 15:
            self.__request_hash_map()
        else:
            self.__request_hash_map_user()

        if self.message is None:
            try:
                g.db.hash_table.update({'_id': ObjectId(_id)}, self.hash_map)
                self.status = 'msg msg-success'
                self.message = g.hash_table_msg('hash_updated')
            except PyMongoError:
                self.message = g.hash_table_msg('error_mongo_update')
Esempio n. 5
0
    def __request_hash_map(self):
        """ Get from request.form the hash map values and check it """
        form = self.params
        old_name = self.hash_map['name']
        self.hash_map['name'] = form['name']
        self.hash_map['value'] = {}

        # Check that the name hash map has between 2 and 20 characters
        if not check.length(self.hash_map['name'], 2, 20):
            self.message = g.hash_table_msg('error_1')

        # Verify that the format of the name is correct
        elif not check.username(self.hash_map['name']):
            self.message = g.hash_table_msg('error_2')

        # Check that the name is new
        if not self.message and old_name != self.hash_map['name']:
            hash_map = g.db.hash_table.find_one(
                {'name': self.hash_map['name']})
            if hash_map:
                self.message = g.hash_table_msg('error_5')

        # Get len label
        len_label = int(form["len"])

        # I look for fields that contain the keys,
        # then I browse to the field until the larger number.
        for i in range(len_label):
            label_key = 'label-name-{}'.format(i)
            key = form[label_key].strip()

            # Check that the key has between 2 and 30 characters
            if not check.length(key, 2, 30):
                self.message = g.hash_table_msg('error_3')

            # Verify that the format of the key is correct
            elif not check.username(key):
                self.message = g.hash_table_msg('error_4')

            # It doesn't take into dictionary the empty keys
            if check.length(key, 2, 30):
                # Initial language values
                self.hash_map['value'][key] = {}

                for code in self.languages:
                    label_value = 'label-{}-{}'.format(code, i)

                    value = form[label_value]
                    self.hash_map['value'][key][code] = value
Esempio n. 6
0
 def new(self):
     """ Add hash map """
     self.__request_hash_map()
     
     if not self.message:
         try:
             g.db.hash_table.insert( self.hash_map )
             self.success = True
             self.status = 'msg msg-success'
             self.message = g.hash_table_msg('hash_created')
         except PyMongoError:
             self.message = g.hash_table_msg('error_mongo_new')
             return False
             
     return False
Esempio n. 7
0
    def new(self):
        """ Add hash map """
        self.__request_hash_map()

        if not self.message:
            try:
                g.db.hash_table.insert(self.hash_map)
                self.success = True
                self.status = 'msg msg-success'
                self.message = g.hash_table_msg('hash_created')
            except PyMongoError:
                self.message = g.hash_table_msg('error_mongo_new')
                return False

        return False
Esempio n. 8
0
    def __request_hash_map(self):
        """ Get from request.form the hash map values and check it """
        form = self.params
        old_name = self.hash_map['name']
        self.hash_map['name'] = form['name']
        self.hash_map['value'] = {}
        
        # Check that the name hash map has between 2 and 20 characters
        if not check.length(self.hash_map['name'], 2, 20):
            self.message = g.hash_table_msg('error_1')
        
        # Verify that the format of the name is correct
        elif not check.username(self.hash_map['name']):
            self.message = g.hash_table_msg('error_2')

        # Check that the name is new
        if not self.message and old_name != self.hash_map['name']:
            hash_map = g.db.hash_table.find_one({ 'name' : self.hash_map['name'] })
            if hash_map:
                self.message = g.hash_table_msg('error_5')
        
        # Get len label
        len_label = int(form["len"])
            
        # I look for fields that contain the keys, 
        # then I browse to the field until the larger number.
        for i in range(len_label):
            label_key = 'label-name-{}'.format(i)
            key = form[label_key].strip()
                
            # Check that the key has between 2 and 30 characters
            if not check.length(key, 2, 30):
                self.message = g.hash_table_msg('error_3')
                
            # Verify that the format of the key is correct
            elif not check.username(key):
                self.message = g.hash_table_msg('error_4')
            
            # It doesn't take into dictionary the empty keys
            if check.length(key, 2, 30):
                # Initial language values
                self.hash_map['value'][key] = {}
                
                for code in self.languages:
                    label_value = 'label-{}-{}'.format(code, i)
                    
                    value = form[label_value]
                    self.hash_map['value'][key][code] = value
Esempio n. 9
0
 def new(self):
     """ Add hash map """
     self.__request_hash_map()
     
     if self.message is None:
         try:
             g.db.hash_table.insert( self.hash_map )
             return True
         except PyMongoError:
             self.message = g.hash_table_msg('error_mongo_new')
             return False
             
     return False
Esempio n. 10
0
    def new(self):
        """ Add hash map """
        self.__request_hash_map()

        if self.message is None:
            try:
                g.db.hash_table.insert(self.hash_map)
                return True
            except PyMongoError:
                self.message = g.hash_table_msg('error_mongo_new')
                return False

        return False