from website.data.database import connect_to_db, database import rethinkdb articles = database.table("articles") 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()) def get_all_undeleted_articles() -> list: connect_to_db() query = articles.get_all(False, index="deleted") return list(query.run()) def get_all_deleted_articles() -> list: connect_to_db() query = articles.get_all(True, index="deleted") return list(query.run()) def get_latest_articles(start: int = 0, end: int = None, unit="", all=False):
from website.data.database import connect_to_db, database users = database.table("users") 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
from website.data.database import connect_to_db, database import os from PIL import Image import rethinkdb import hashlib from werkzeug.datastructures import FileStorage from website import app images_table = database.table("images") def save_image(file: FileStorage): thumbnail_size = 240, 240 directory = app.config["IMAGE_DIRECTORY"] # Compute hash file_hash = hashlib.md5(file.read()).hexdigest() file.seek(0) file_name = file_hash + ".jpg" file_path = os.path.join(directory, file_name) thumbnail_name = file_hash + "_thumb.jpg" thumbnail_path = os.path.join(directory, thumbnail_name) image = Image.open(file) size = image.size
from website.data.database import connect_to_db, database programs = database.table("programs") def get_program_list(): connect_to_db() return list(programs.run()) 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] def get_programs() -> list: """Return list of all programs""" result = program_db.all() print("programs", result) return result
from website.data.database import connect_to_db, database import os from PIL import Image import rethinkdb import hashlib from werkzeug.datastructures import FileStorage from website import app images_table = database.table("images") def save_image(file: FileStorage): thumbnail_size = 240, 240 directory = app.config["IMAGE_DIRECTORY"] # Compute hash file_hash = hashlib.md5(file.read()).hexdigest() file.seek(0) file_name = file_hash + ".jpg" file_path = os.path.join(directory, file_name) thumbnail_name = file_hash + "_thumb.jpg" thumbnail_path = os.path.join(directory, thumbnail_name) image = Image.open(file) size = image.size
from website.data.database import connect_to_db, database users = database.table("users") 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