Skip to content

Feature/text extract #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ dmypy.json
.pyre/

# mac env
.DS_Store
bin

# register stuff
Expand Down
1 change: 0 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* PureDreamer - Developer
* ShiZinDle - Developer
* YairEn - Developer
* LiranCaduri - Developer
* IdanPelled - Developer

# Special thanks to
Expand Down
3 changes: 2 additions & 1 deletion app/babel_mapping.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Extraction from Python source files
[python: **.py]

# Extraction from Jinja2 HTML and text templates
# Extraction from Jinja2 HTML and j2 templates
[jinja2: **/templates/**.html]
[jinja2: **/templates/**.j2]
extensions = jinja2.ext.i18n,jinja2.ext.autoescape,jinja2.ext.with_
1 change: 0 additions & 1 deletion app/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ email_conf = ConnectionConfig(
JWT_KEY = "JWT_KEY_PLACEHOLDER"
JWT_ALGORITHM = "HS256"
JWT_MIN_EXP = 60 * 24 * 7

templates = Jinja2Templates(directory=os.path.join("app", "templates"))

# application name
Expand Down
3 changes: 1 addition & 2 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ class User(Base):
back_populates="user",
)
comments = relationship("Comment", back_populates="user")
tasks = relationship(
"Task", cascade="all, delete", back_populates="owner")
tasks = relationship("Task", cascade="all, delete", back_populates="owner")

features = relationship("Feature", secondary=UserFeature.__tablename__)
oauth_credentials = relationship(
Expand Down
47 changes: 10 additions & 37 deletions app/database/schemas.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
from datetime import datetime
from typing import Optional, Union

from pydantic import BaseModel, EmailError, EmailStr, Field, validator
from pydantic import BaseModel, EmailError, EmailStr, validator

EMPTY_FIELD_STRING = "field is required"
MIN_FIELD_LENGTH = 3
MAX_FIELD_LENGTH = 20


def fields_not_empty(field: Optional[str]) -> str:
def fields_not_empty(field: Optional[str]) -> Union[ValueError, str]:
"""Global function to validate fields are not empty."""
if not field:
raise ValueError(EMPTY_FIELD_STRING)
return field


class UserModel(BaseModel):
username: str
password: str
email: str = Field(regex="^\\S+@\\S+\\.\\S+$")
language: str
language_id: int


class UserBase(BaseModel):
"""
Validating fields types
Expand Down Expand Up @@ -69,30 +60,32 @@ class UserCreate(UserBase):
)

@validator("confirm_password")
def passwords_match(cls, confirm_password: str, values: UserBase) -> str:
def passwords_match(
cls,
confirm_password: str,
values: UserBase,
) -> Union[ValueError, str]:
"""Validating passwords fields identical."""
if "password" in values and confirm_password != values["password"]:
raise ValueError("doesn't match to password")
return confirm_password

@validator("username")
def username_length(cls, username: str) -> str:
def username_length(cls, username: str) -> Union[ValueError, str]:
"""Validating username length is legal"""
if not (MIN_FIELD_LENGTH < len(username) < MAX_FIELD_LENGTH):
raise ValueError("must contain between 3 to 20 charactars")
if username.startswith("@"):
raise ValueError("username can not start with '@'")
return username

@validator("password")
def password_length(cls, password: str) -> str:
def password_length(cls, password: str) -> Union[ValueError, str]:
"""Validating username length is legal"""
if not (MIN_FIELD_LENGTH < len(password) < MAX_FIELD_LENGTH):
raise ValueError("must contain between 3 to 20 charactars")
return password

@validator("email")
def confirm_mail(cls, email: str) -> str:
def confirm_mail(cls, email: str) -> Union[ValueError, str]:
"""Validating email is valid mail address."""
try:
EmailStr.validate(email)
Expand All @@ -109,23 +102,3 @@ class User(UserBase):

id: int
is_active: bool


class NoteSchema(BaseModel):
title: str
description: Optional[str] = None
timestamp: Optional[datetime]
creator: Optional[User]

class Config:
orm_mode = True
schema_extra = {
"example": {
"title": "Foo",
"description": "Bar",
},
}


class NoteDB(NoteSchema):
id: int
1 change: 0 additions & 1 deletion app/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
templates = Jinja2Templates(directory=TEMPLATES_PATH)
templates.env.add_extension("jinja2.ext.i18n")


# Configure logger
logger = LoggerCustomizer.make_logger(
config.LOG_PATH,
Expand Down
51 changes: 26 additions & 25 deletions app/internal/agenda_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@
from sqlalchemy.orm import Session

from app.database.models import Event
from app.internal.user import user
from app.routers.event import sort_by_date
from app.routers.user import get_all_user_events


def get_events_per_dates(
session: Session,
user_id: int,
start: Optional[date],
end: Optional[date],
session: Session,
user_id: int,
start: Optional[date],
end: Optional[date]
) -> Union[Iterator[Event], list]:
"""Read from the db. Return a list of all
the user events between the relevant dates."""

if start > end:
return []

return filter_dates(
sort_by_date(user.get_all_user_events(session, user_id)),
start,
end,
return (
filter_dates(
sort_by_date(
get_all_user_events(session, user_id)
),
start,
end,
)
)


Expand All @@ -50,17 +54,15 @@ def get_time_delta_string(start: date, end: date) -> str:
diff = end - start
granularity = build_arrow_delta_granularity(diff)
duration_string = arrow_end.humanize(
arrow_start,
only_distance=True,
granularity=granularity,
arrow_start, only_distance=True, granularity=granularity
)
return duration_string


def filter_dates(
events: List[Event],
start: Union[None, date] = None,
end: Union[None, date] = None,
events: List[Event],
start: Union[None, date] = None,
end: Union[None, date] = None,
) -> Iterator[Event]:
"""Returns all events in a time frame.

Expand All @@ -80,25 +82,24 @@ def filter_dates(


def get_events_in_time_frame(
start_date: Union[date, None],
end_date: Union[date, None],
user_id: int,
db: Session,
start_date: Union[date, None],
end_date: Union[date, None],
user_id: int, db: Session
) -> Iterator[Event]:
"""Yields all user's events in a time frame."""
events = user.get_all_user_events(db, user_id)
events = get_all_user_events(db, user_id)
yield from filter_dates(events, start_date, end_date)


def get_events_for_the_week(
db: Session,
user_id: int,
) -> Tuple[Union[Iterator[Event], list], Dict]:
def get_events_for_the_week(db: Session, user_id: int
) -> Tuple[Union[Iterator[Event], list], Dict]:
WEEK_DAYS = 7
start_date = date.today()
end_date = start_date + timedelta(days=WEEK_DAYS - 1)

events_this_week = get_events_per_dates(db, user_id, start_date, end_date)
events_this_week = get_events_per_dates(
db, user_id, start_date, end_date
)
events_for_graph = {
str(start_date + timedelta(i)): 0 for i in range(WEEK_DAYS)
}
Expand Down
Loading