Skip to content

Commit

Permalink
refactor and remove unused code script and files
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed May 27, 2024
1 parent 73eaadd commit e419ee4
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 210 deletions.
9 changes: 4 additions & 5 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

basedir = os.path.abspath(os.path.dirname(__file__))
UPLOAD_FOLDER = "app/tmp/data/"
UPLOAD_IMAGE_FOLDER = "app/uploads/images"
MAX_TOKENS = 200000

if not os.path.isdir(UPLOAD_FOLDER):
Expand Down Expand Up @@ -46,7 +47,7 @@ class DevelopmentConfig(Config):
cert_bytes = open(fname, 'rb').read()
PKEY = load_pem_private_key(cert_bytes, None)

PROJECT_IMAGE_FOLDER = "app/uploads/images"
PROJECT_IMAGE_FOLDER = UPLOAD_IMAGE_FOLDER
UPLOAD_IMAGE_EXTENSIONS = ['.jpg', '.png', '.gif', '.jpeg']


Expand All @@ -64,7 +65,7 @@ class TestingConfig(Config):
basedir = os.path.dirname(os.path.abspath(__file__))
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'arborator_test.sqlite')

PROJECT_IMAGE_FOLDER = "app/uploads/images"
PROJECT_IMAGE_FOLDER = UPLOAD_IMAGE_FOLDER
UPLOAD_IMAGE_EXTENSIONS = ['.jpg', '.png', '.gif', '.jpeg']


Expand All @@ -86,12 +87,10 @@ class ProductionConfig(Config):
ENV = 'prod'
fname = 'keys/arborator-grew.pem'
APP_ID = open('keys/arborator-grew-appid.txt').read()
# INSTALATION_ID = int(open('keys/arborator-grew-installationid.txt').read())
cert_bytes = open(fname, 'rb').read()
PKEY = load_pem_private_key(cert_bytes, None)

## WARNING : specify the DIST folder, not the quasar source code in prod
PROJECT_IMAGE_FOLDER = "app/uploads/images"
PROJECT_IMAGE_FOLDER = UPLOAD_IMAGE_FOLDER
UPLOAD_IMAGE_EXTENSIONS = ['.jpg', '.png', '.gif', '.jpeg']


Expand Down
Binary file removed app/public/favicon.ico
Binary file not shown.
Binary file removed app/public/tmp.xlsx
Binary file not shown.
44 changes: 0 additions & 44 deletions app/shared/decorator.py

This file was deleted.

31 changes: 0 additions & 31 deletions app/shared/model.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
import base64
import json

from sqlalchemy.ext.declarative import DeclarativeMeta


class BaseM(object):
def as_json(self, exclude=[], include={}):
json_rep = dict()
for k in vars(self):
# print(getattr(self, k))
if k in exclude:
# print(k)
continue
elif k[0] == "_":
continue
elif type(getattr(self, k)) is bytes:
# print('yay')
# print(getattr(self, k))
json_rep[k] = str(base64.b64encode(getattr(self, k)))
# json_rep[k] = str(getattr(self, k))
else:
json_rep[k] = getattr(self, k)
for k in include:
json_rep[k] = include[k]
return json_rep


# TODO : can remove this class
class AlchemyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj.__class__, DeclarativeMeta):
# an SQLAlchemy class
fields = {}
for field in [
x for x in dir(obj) if not x.startswith("_") and x != "metadata"
]:
data = obj.__getattribute__(field)
try:
# this will fail on non-encodable values, like other classes
json.dumps(data)
fields[field] = data
except TypeError:
fields[field] = None
# a json-encodable dict
return fields

return json.JSONEncoder.default(self, obj)
5 changes: 2 additions & 3 deletions app/tags/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ def get(self, project_name, username):
project = ProjectService.get_by_name(project_name)
ProjectService.check_if_project_exist(project)
user = UserService.get_by_username(username)
if(user is not None):
if UserTagsService.get_by_user_id(user.id):
return UserTagsService.get_by_user_id(user.id).tags
if user is not None and UserTagsService.get_by_user_id(user.id):
return UserTagsService.get_by_user_id(user.id).tags


def post(self, project_name, username):
Expand Down
14 changes: 6 additions & 8 deletions app/trees/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,14 @@ def get(self, project_name: str, sample_name: str):
return data

def post(self, project_name: str, sample_name: str):
parser = reqparse.RequestParser()
parser.add_argument(name="sent_id", type=str)
parser.add_argument(name="user_id", type=str)
parser.add_argument(name="conll", type=str)
args = parser.parse_args()


args = request.get_json()
user_id = args.get("user_id")
conll = args.get("conll")

project = ProjectService.get_by_name(project_name)
ProjectService.check_if_freezed(project)
user_id = args.user_id
conll = args.conll

if not conll:
abort(400)

Expand Down
16 changes: 0 additions & 16 deletions app/user/controller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,3 @@ def test_get(self, client: FlaskClient): # noqa
for r in results:
assert r in expected

# @patch.object(
# UserService, "create", lambda create_request: User(**create_request)
# )
# def test_post(self, client: FlaskClient): # noqa
# with client:

# payload = dict(username="Test user", first_name="test first name")
# result = client.post(f"/api/{BASE_ROUTE}/", json=payload).get_json()
# expected = (
# UserSchema()
# .dump(User(username=payload["username"], first_name=payload["first_name"]))

# )
# print("result", result)
# print("expected", expected)
# assert result == expected
20 changes: 10 additions & 10 deletions app/user/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ class UserSchema(Schema):
"""User schema"""

id = fields.String(attribute="id")
auth_provider = fields.String(attribute="auth_provider")
github_access_token = fields.String(attribute="github_access_token")
authProvider = fields.String(attribute="auth_provider")
githubAccessToken = fields.String(attribute="github_access_token")
username = fields.String(attribute="username")
first_name = fields.String(attribute="first_name")
family_name = fields.String(attribute="family_name")
firstName = fields.String(attribute="first_name")
familyName = fields.String(attribute="family_name")
email = fields.String(attribute="email")
not_share_email = fields.Boolean(attribute="not_share_email")
receive_newsletter = fields.Boolean(attribute="receive_newsletter")
picture_url = fields.String(attribute="picture_url")
super_admin = fields.Boolean(attribute="super_admin")
created_date = fields.DateTime(attribute="created_date")
last_seen = fields.DateTime(attribute="last_seen")
notShareEmail = fields.Boolean(attribute="not_share_email")
receiveNewsletter = fields.Boolean(attribute="receive_newsletter")
pictureUrl = fields.String(attribute="picture_url")
superAdmin = fields.Boolean(attribute="super_admin")
createdDate = fields.DateTime(attribute="created_date")
lastSeen = fields.DateTime(attribute="last_seen")
4 changes: 2 additions & 2 deletions app/user/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def login_by_id(id: str) -> User:
return User.query.get(id)

@staticmethod
def update(user: User, User_change_updates: UserInterface) -> User:
user.update(User_change_updates)
def update(user: User, user_change_updates: UserInterface) -> User:
user.update(user_change_updates)
db.session.commit()
return user

Expand Down
21 changes: 0 additions & 21 deletions commands/seed_command.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
from datetime import datetime
import pandas as pd
import numpy as np
from flask_script import Command

from app import db
# from app.widget import Widget
from app.projects.model import Project


# def seed_things():
# classes = [Widget]
# for klass in classes:
# seed_thing(klass)


# def seed_thing(cls):
# things =[
# {"name": "Pizza Slicer", "purpose": "Cut delicious pizza"},
# {"name": "Rolling Pin", "purpose": "Roll delicious pizza"},
# {"name": "Pizza Oven", "purpose": "Bake delicious pizza"},
# ]
# db.session.bulk_insert_mappings(cls, things)


class SeedCommand(Command):
""" Seed the DB."""
Expand Down
Binary file removed docs/site.png
Binary file not shown.
52 changes: 0 additions & 52 deletions manage_imgblob2path.py

This file was deleted.

18 changes: 0 additions & 18 deletions migrate_img.sh

This file was deleted.

Binary file removed tmp.xlsx
Binary file not shown.

0 comments on commit e419ee4

Please sign in to comment.