Run pre-commit

Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar>
Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
Santiago Lo Coco 2022-11-28 17:25:47 -03:00
parent 26cb63ba22
commit 958d658693
9 changed files with 29 additions and 18 deletions

View File

@ -2,8 +2,8 @@ from dotenv import load_dotenv
from fastapi import FastAPI from fastapi import FastAPI
from bsition.api.components.document import documents_routes from bsition.api.components.document import documents_routes
from bsition.api.components.user import users_routes
from bsition.api.components.table import tables_routes from bsition.api.components.table import tables_routes
from bsition.api.components.user import users_routes
from bsition.api.routes.auth import auth_routes from bsition.api.routes.auth import auth_routes
app = FastAPI() app = FastAPI()

View File

@ -4,9 +4,8 @@ from fastapi import APIRouter, Response, status
from pydantic import BaseModel from pydantic import BaseModel
from pydantic.types import Optional from pydantic.types import Optional
from bsition.backend import mongo
from bsition.backend import elastic
from bsition.api.middleware.verify_token import VerifyTokenRoute from bsition.api.middleware.verify_token import VerifyTokenRoute
from bsition.backend import elastic, mongo
documents_routes = APIRouter(route_class=VerifyTokenRoute) documents_routes = APIRouter(route_class=VerifyTokenRoute)

View File

@ -2,8 +2,8 @@ from fastapi import APIRouter, Response, status
from pydantic import BaseModel from pydantic import BaseModel
from pydantic.utils import Optional from pydantic.utils import Optional
from bsition.backend import postgres
from bsition.api.middleware.verify_token import VerifyTokenRoute from bsition.api.middleware.verify_token import VerifyTokenRoute
from bsition.backend import postgres
tables_routes = APIRouter(route_class=VerifyTokenRoute) tables_routes = APIRouter(route_class=VerifyTokenRoute)
@ -77,4 +77,3 @@ def add_filter(aux: Filter, name: str):
@tables_routes.get("/tables/{name}/filter") @tables_routes.get("/tables/{name}/filter")
def filter(name: str): def filter(name: str):
return postgres.filter(name) return postgres.filter(name)

View File

@ -1,8 +1,8 @@
from fastapi import APIRouter, Response, status from fastapi import APIRouter, Response, status
from pydantic import BaseModel from pydantic import BaseModel
from bsition.backend import postgres
from bsition.api.middleware.verify_token import VerifyTokenRoute from bsition.api.middleware.verify_token import VerifyTokenRoute
from bsition.backend import postgres
users_routes = APIRouter() users_routes = APIRouter()
@ -35,4 +35,3 @@ def get_by_id(id: str):
def edit_user(aux: User, id: str, response: Response): def edit_user(aux: User, id: str, response: Response):
postgres.edit_user(id, aux.username, aux.password) postgres.edit_user(id, aux.username, aux.password)
response.status_code = status.HTTP_202_ACCEPTED response.status_code = status.HTTP_202_ACCEPTED

View File

@ -1,7 +1,7 @@
from dotenv import load_dotenv from dotenv import load_dotenv
from bsition.backend.postgres import *
from bsition.backend.elastic import * from bsition.backend.elastic import *
from bsition.backend.postgres import *
def configure(): def configure():

View File

@ -54,6 +54,8 @@ def search(index, query):
print(resp["hits"]) print(resp["hits"])
print(hit["_source"]) print(hit["_source"])
print("%(name)s: %(data)s" % hit["_source"]) print("%(name)s: %(data)s" % hit["_source"])
hits.append(str(hit["highlight"]) + " ---- " + "%(name)s: %(data)s" % hit["_source"]) hits.append(
str(hit["highlight"]) + " ---- " + "%(name)s: %(data)s" % hit["_source"]
)
return hits return hits

View File

@ -14,7 +14,18 @@ def get_database():
def get_documents(): def get_documents():
dbname = get_database() dbname = get_database()
docs_coll = dbname["docs"] docs_coll = dbname["docs"]
pipeline = [{'$project': {"id": {'$toString': "$_id"}, "_id": 0, "data": 1, "name": 1, "access": 1, "owner": 1}}] pipeline = [
{
"$project": {
"id": {"$toString": "$_id"},
"_id": 0,
"data": 1,
"name": 1,
"access": 1,
"owner": 1,
}
}
]
return list(docs_coll.aggregate(pipeline)) return list(docs_coll.aggregate(pipeline))

View File

@ -1,7 +1,7 @@
import inspect import inspect
from os import getenv from os import getenv
from psycopg2 import sql, connect from psycopg2 import connect, sql
def get_connection(): def get_connection():
@ -55,7 +55,9 @@ def edit_columns(name, columns, data, id):
for column in columns: for column in columns:
cur.execute( cur.execute(
sql.SQL("UPDATE {table} SET {col} = %s WHERE row_number = {id}").format( sql.SQL("UPDATE {table} SET {col} = %s WHERE row_number = {id}").format(
table=sql.Identifier(name), col=sql.Identifier(column), id=sql.Literal(id) table=sql.Identifier(name),
col=sql.Identifier(column),
id=sql.Literal(id),
), ),
[data[i]], [data[i]],
) )
@ -255,9 +257,7 @@ def add_user(username, password):
def get_users(): def get_users():
conn = get_connection() conn = get_connection()
cur = conn.cursor() cur = conn.cursor()
cur.execute( cur.execute("SELECT * FROM users")
"SELECT * FROM users"
)
return list(cur.fetchall()) return list(cur.fetchall())
@ -296,8 +296,9 @@ def edit_user(id, username, password):
print(id) print(id)
cur.execute( cur.execute(
sql.SQL("UPDATE users SET {col} = {value} WHERE id = {id}").format( sql.SQL("UPDATE users SET {col} = {value} WHERE id = {id}").format(
col=sql.Identifier(column), value=sql.Literal(data[i]), id=sql.Literal(id) col=sql.Identifier(column),
value=sql.Literal(data[i]),
id=sql.Literal(id),
), ),
) )
conn.commit() conn.commit()