def dispatch_request(self, *args, **kwargs): if not check_ip(request): return objResponse = {} # Template information objResponse['template_tag'] = ("" if self.action.pi_api_template == "" else md5Checksum('templates/' + self.action.pi_api_template)) for attribute in (u'only_logged_user', u'only_member_user', u'only_admin_user', u'only_orga_member_user', u'only_orga_admin_user', # User restrictions u'cache_time', u'cache_by_user', # Cache information u'user_info', u'json_only', 'no_template'): # Requested user infos + JSON-only if hasattr(self.action, u'pi_api_' + attribute): objResponse[attribute] = getattr(self.action, u'pi_api_' + attribute) # Add the cache headers response = make_response(object2json(objResponse, include_properties=False)) expires = datetime.utcnow() + timedelta(seconds=PI_META_CACHE) expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") response.headers['Expire'] = expires response.headers['Cache-Control'] = 'public, max-age=' + str(PI_META_CACHE) # Return the final response return response
def add_a_book(book_path, file_name): file_hash = md5Checksum(book_path) in_db_book = connect()["books"].find_one({"hash": file_hash}) if in_db_book is not None: print "Error: file '%s' is already in the db with path '%s'" % (book_path, in_db_book["path"]) if book_path != in_db_book["path"]: print "Updating file path with new path" in_db_book["path"] = book_path connect()["books"].save(in_db_book) return None return connect()["books"].insert({"path": book_path, "name": file_name, "hash": file_hash})
def add_a_book(book_path, file_name): file_hash = md5Checksum(book_path) cursor = connect.execute('select * from books where hash=?', (file_hash,)) if cursor.rowcount == 1: row = cursor.fetchone() print "Error: file '%s' is already in the db with path '%s'" % (book_path, row[2]) if book_path != row[2]: print "Updating file path with new path" cursor.execute('update books set path=? where hash=?', (book_path, file_hash)) else: cursor.execute('insert into books (name, path, hash) values (?,?,?)', (file_name, book_path, file_hash)) connect.commit() return None
def dispatch_request(self, *args, **kwargs): if not check_ip(request): return objResponse = {} # Template information objResponse['template_tag'] = ( "" if self.action.pi_api_template == "" else md5Checksum('templates/' + self.action.pi_api_template)) for attribute in ( u'only_logged_user', u'only_member_user', u'only_admin_user', u'only_orga_member_user', u'only_orga_admin_user', # User restrictions u'cache_time', u'cache_by_user', # Cache information u'user_info', u'json_only', 'no_template'): # Requested user infos + JSON-only if hasattr(self.action, u'pi_api_' + attribute): objResponse[attribute] = getattr(self.action, u'pi_api_' + attribute) # Add the cache headers response = make_response(jsonify(objResponse)) expires = datetime.utcnow() + timedelta(seconds=PI_META_CACHE) expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") response.headers['Expire'] = expires response.headers['Cache-Control'] = 'public, max-age=' + str( PI_META_CACHE) # Return the final response return response