def answer_quiz(quiz_id): db_connection = database.create_database_connection() try: body = request.get_json() user_id = extract_field_from_body('user_id', body) option_id = extract_field_from_body('option_id', body) database.answer(db_connection, quiz_id, user_id, option_id) database.result(db_connection, quiz_id) except: return Response("Bad request.", status=400, mimetype='application/json') finally: database.close_connection(db_connection) return Response('Answer added.', status=201, mimetype='application/json')
def drupal_is_denied(ip): """ Check to see if an IP address has been blocked. Blocked IP addresses are stored in the database by default. However for performance reasons we allow an override in settings.php. This allows us to avoid querying the database at this critical stage of the bootstrap if an administrative interface for IP address blocking is not required. @param $ip string IP address to check. @return bool TRUE if access is denied, FALSE if access is allowed. """ # Because this function is called on every page request, we first check # for an array of IP addresses in settings.php before querying the # database. blocked_ips = variable_get('blocked_ips', None) if (blocked_ips != None and php.is_array(blocked_ips)): return php.in_array(ip, blocked_ips) else: sql = "SELECT 1 FROM {blocked_ips} WHERE ip = '%s'" return (lib_database.result(lib_database.query(sql, ip)) != False)
def drupal_is_denied(ip): """ Check to see if an IP address has been blocked. Blocked IP addresses are stored in the database by default. However for performance reasons we allow an override in settings.php. This allows us to avoid querying the database at this critical stage of the bootstrap if an administrative interface for IP address blocking is not required. @param $ip string IP address to check. @return bool TRUE if access is denied, FALSE if access is allowed. """ # Because this function is called on every page request, we first check # for an array of IP addresses in settings.php before querying the # database. blocked_ips = variable_get("blocked_ips", None) if blocked_ips != None and php.is_array(blocked_ips): return php.in_array(ip, blocked_ips) else: sql = "SELECT 1 FROM {blocked_ips} WHERE ip = '%s'" return lib_database.result(lib_database.query(sql, ip)) != False
def drupal_get_filename(type_, name, filename=None): """ Returns and optionally sets the filename for a system item (plugin, theme, etc.). The filename, whether provided, cached, or retrieved from the database, is only returned if the file exists. This def plays a key role in allowing Drupal's resources (plugins and themes) to be located in different places depending on a site's configuration. For example, a plugin 'foo' may legally be be located in any of these three places: plugins/foo/__init__.py sites/all/plugins/foo/__init__.py sites/example.com/plugins/foo/__init__.py Calling drupal_get_filename('plugin', 'foo') will give you one of the above, depending on where the plugin is located. @param type The type of the item (i.e. theme, theme_engine, plugin). @param name The name of the item for which the filename is requested. @param filename The filename of the item if it is to be set explicitly rather than by consulting the database. @return The filename of the requested item. """ php.static(drupal_get_filename, 'files', {}) file = lib_database.result(lib_database.query(\ "SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", \ name, type_)) if (not php.isset(drupal_get_filename.files, type_)): drupal_get_filename.files[type_] = {} if (filename is not None and php.file_exists(filename)): drupal_get_filename.files[type_][name] = filename elif (php.isset(drupal_get_filename.files[type_], name)): # nothing pass # Verify that we have an active database connection, before querying # the database. This is required because this def is called both # before we have a database connection (i.e. during installation) and # when a database connection fails. elif (lib_database.is_active() and (file and php.file_exists(file))): drupal_get_filename.files[type_][name] = file else: # Fallback to searching the filesystem if the database connection is # not established or the requested file is not found. config = conf_path() if type_ == 'theme_engine': dir_ = 'themes/engines' file = "%s.engine" % name else: dir_ = '%ss' % type_ file = "__init__.py" fileVals = { 'name': name, 'file': file, 'dir': dir_, 'config': config } fileChecker = ( # DRUPY: This is not used # "%(config)s/%(dir)s/%(file)s" % fileVals, "%(config)s/%(dir)s/%(name)s/%(file)s" % fileVals, # DRUPY: This is not used #"%(dir)s/%(file)s" % fileVals, "%(dir)s/%(name)s/%(file)s" % fileVals) for file_ in fileChecker: if (php.file_exists(file_)): drupal_get_filename.files[type_][name] = file_ break if (php.isset(drupal_get_filename.files[type_], name)): return drupal_get_filename.files[type_][name]
import sys from database import result from pymongo import MongoClient from datetime import datetime import threading import time client = MongoClient("localhost", 27017) db = client["BTP"] col1 = db["userInformation"] result1 = result(0, 1, 2, 3, 4, "1") print(result1.get_object_json()) db.userInformation.update( {"id": "a"}, {"$set": { "queries.$[0].results": result1.get_object_json() }}) # print result1.get_object_json() # db.userInformation.update({"id.queries": "a"}, {"$push": # { # "queries[0].result1s": --> PLACE # result1.get_object_json() --> WHAT # }
def drupal_get_filename(type_, name, filename=None): """ Returns and optionally sets the filename for a system item (plugin, theme, etc.). The filename, whether provided, cached, or retrieved from the database, is only returned if the file exists. This def plays a key role in allowing Drupal's resources (plugins and themes) to be located in different places depending on a site's configuration. For example, a plugin 'foo' may legally be be located in any of these three places: plugins/foo/__init__.py sites/all/plugins/foo/__init__.py sites/example.com/plugins/foo/__init__.py Calling drupal_get_filename('plugin', 'foo') will give you one of the above, depending on where the plugin is located. @param type The type of the item (i.e. theme, theme_engine, plugin). @param name The name of the item for which the filename is requested. @param filename The filename of the item if it is to be set explicitly rather than by consulting the database. @return The filename of the requested item. """ php.static(drupal_get_filename, "files", {}) file = lib_database.result( lib_database.query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", name, type_) ) if not php.isset(drupal_get_filename.files, type_): drupal_get_filename.files[type_] = {} if filename is not None and php.file_exists(filename): drupal_get_filename.files[type_][name] = filename elif php.isset(drupal_get_filename.files[type_], name): # nothing pass # Verify that we have an active database connection, before querying # the database. This is required because this def is called both # before we have a database connection (i.e. during installation) and # when a database connection fails. elif lib_database.is_active() and (file and php.file_exists(file)): drupal_get_filename.files[type_][name] = file else: # Fallback to searching the filesystem if the database connection is # not established or the requested file is not found. config = conf_path() if type_ == "theme_engine": dir_ = "themes/engines" file = "%s.engine" % name else: dir_ = "%ss" % type_ file = "__init__.py" fileVals = {"name": name, "file": file, "dir": dir_, "config": config} fileChecker = ( # DRUPY: This is not used # "%(config)s/%(dir)s/%(file)s" % fileVals, "%(config)s/%(dir)s/%(name)s/%(file)s" % fileVals, # DRUPY: This is not used # "%(dir)s/%(file)s" % fileVals, "%(dir)s/%(name)s/%(file)s" % fileVals, ) for file_ in fileChecker: if php.file_exists(file_): drupal_get_filename.files[type_][name] = file_ break if php.isset(drupal_get_filename.files[type_], name): return drupal_get_filename.files[type_][name]