Beispiel #1
0
def get_user_details(user_id: str) -> dict:
	if user_id is None:
		return None

	connect_to_db()
	user = users.get(user_id).run()
	return user
Beispiel #2
0
def update_article(article_id, data):
	print("Update to article", article_id)
	print(data)
	date = rethinkdb.now()
	connect_to_db()
	articles.get(article_id).update(data).run()
	articles.get(article_id).update({"updated": date}).run()
Beispiel #3
0
def get_user_details(user_id: str) -> dict:
    if user_id is None:
        return None

    connect_to_db()
    user = users.get(user_id).run()
    return user
Beispiel #4
0
def get_sidebar_articles(unit=None) -> list:
	connect_to_db()
	query = articles.get_all([True, False], index="state")

	if unit is not None:
		query = query.filter({"unit": unit})

	return list(query.run())
Beispiel #5
0
def get_article_by_title(title: str):
	connect_to_db()
	result = articles.get_all(title, index="title").run()

	try:
		article = result.next()
		return article
	except rethinkdb.net.DefaultCursorEmpty:
		return None
Beispiel #6
0
def create_new_article():
	connect_to_db()

	date = rethinkdb.now()
	articles.insert({
		"created": date,
		"updated": None,
		"published": False,
		"deleted": False,
		"title": "New Article",
	}).run()
Beispiel #7
0
def get_program(name: str):
    print("Getting program named:", name)
    connect_to_db()

    result = programs.get_all(name, index="name").run()
    result = list(result)
    print(result)
    if len(result) == 0:
        # TODO none found case
        pass
    elif len(result) > 1:
        return result[0]
    else:
        return result[0]
Beispiel #8
0
def store_image(file_hash: str, size: tuple):
	""" Insert image into the database
	:param file_hash: hash of the file
	:param size: tuple of image size (x, y)
	"""

	connect_to_db()
	date = rethinkdb.now()

	images_table.insert({
		"file": file_hash,
		"date": date,
		"size": size,
		"name": ""
	}).run()
Beispiel #9
0
def store_image(file_hash: str, size: tuple):
    """ Insert image into the database
	:param file_hash: hash of the file
	:param size: tuple of image size (x, y)
	"""

    connect_to_db()
    date = rethinkdb.now()

    images_table.insert({
        "file": file_hash,
        "date": date,
        "size": size,
        "name": ""
    }).run()
Beispiel #10
0
def get_latest_articles(start: int = 0, end: int = None, unit="", all=False):
	connect_to_db()

	result = None
	if all:
		result = articles.order_by(index="created").run()
	elif unit == "":
		result = articles.get_all(True, index="published").run()
	else:
		result = articles.get_all(unit, index="unit").run()  # TODO and operation

	result = list(result)

	if end:
		return result[start:end]
	else:
		return result
Beispiel #11
0
def get_all_deleted_articles() -> list:
	connect_to_db()
	query = articles.get_all(True, index="deleted")

	return list(query.run())
Beispiel #12
0
def restore_article(article_id):
	connect_to_db()
	articles.get(article_id).update({"deleted": False}).run()
Beispiel #13
0
def delete_article(article_id):
	connect_to_db()
	articles.get(article_id).update({"deleted": True}).run()
Beispiel #14
0
def get_recent_images() -> list:
	connect_to_db()
	query = images_table.order_by("date")

	return list(query.run())
Beispiel #15
0
def get_article(article_id):
	connect_to_db()
	result = articles.get(article_id).run()
	return result
Beispiel #16
0
def get_program_list():
    connect_to_db()
    return list(programs.run())
Beispiel #17
0
def get_recent_images() -> list:
    connect_to_db()
    query = images_table.order_by("date")

    return list(query.run())