-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/shareable event #44
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
Merged
yammesicka
merged 37 commits into
PythonFreeCourse:develop
from
IdanPelled:feature/shareable-event
Jan 23, 2021
Merged
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
8928b17
update ORM and added export for an event
IdanPelled 79874a7
update ORM and added export for an event
IdanPelled bc53da7
Merge branch 'main' of https://github.com/PythonFreeCourse/calendar i…
IdanPelled 8f4e690
Added in app shareable events
IdanPelled 25d1b80
upstream merge
IdanPelled 8fb1035
docs: add type annotation and fix folder structure
IdanPelled 149b571
docs: add type annotation and fix folder structure
IdanPelled be96e5d
docs: fix documentation
IdanPelled 9b2a861
add: tests
IdanPelled aa654ac
add: timezone support
IdanPelled 5227c11
add: session management
IdanPelled 56877c6
fix bug
IdanPelled eda3c31
split conftest file
IdanPelled c24830a
split conftest file
IdanPelled 69f81e1
move "utils" folder into "internal" folder
IdanPelled 0dc1ae6
change file structure
IdanPelled 868ba44
Merge branch 'develop' into feature/shareable-event
IdanPelled 7c2edd0
Merge branch 'develop' feature/shareable-event
IdanPelled 3883d5e
feat: enable invited users to view events
IdanPelled e39c43d
Merge branch 'develop into feature/shareable-event
IdanPelled 6add784
feat: flake8 changes
IdanPelled cccd7b7
fix: requirements bug
IdanPelled 5faf0ba
fix: requirements bug
IdanPelled bdd4d8b
feat: flake8 changes
IdanPelled d629a25
add: tests
IdanPelled 046162d
feat: flake8 changes
IdanPelled 0bcbff8
add: tests
IdanPelled 9462602
feat: flake8 changes
IdanPelled 053b156
edit: file structure
IdanPelled 7684719
edit: file structure
IdanPelled 8b97c29
feat: add route tests
IdanPelled ba09ff0
fix: test bug
IdanPelled 44f30a0
Merge branch 'develop' into feature/shareable-event
IdanPelled 3400fe9
remove: config.py
IdanPelled e0c75f5
fix: type annotation
IdanPelled 3ec5f37
add: minor changes
IdanPelled b9198d5
feat: flake8 changes
IdanPelled File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import os | ||
IdanPelled marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| from fastapi_mail import ConnectionConfig | ||
| # flake8: noqa | ||
|
|
||
| # general | ||
| DOMAIN = 'Our-Domain' | ||
|
|
||
| # DATABASE | ||
| DEVELOPMENT_DATABASE_STRING = "sqlite:///./dev.db" | ||
|
|
||
| # MEDIA | ||
| MEDIA_DIRECTORY = 'media' | ||
| PICTURE_EXTENSION = '.png' | ||
| AVATAR_SIZE = (120, 120) | ||
|
|
||
| # export | ||
| ICAL_VERSION = '2.0' | ||
| PRODUCT_ID = '-//Our product id//' | ||
|
|
||
| email_conf = ConnectionConfig( | ||
| MAIL_USERNAME=os.getenv("MAIL_USERNAME") or "user", | ||
| MAIL_PASSWORD=os.getenv("MAIL_PASSWORD") or "password", | ||
| MAIL_FROM=os.getenv("MAIL_FROM") or "a@a.com", | ||
| MAIL_PORT=587, | ||
| MAIL_SERVER="smtp.gmail.com", | ||
| MAIL_TLS=True, | ||
| MAIL_SSL=False, | ||
| USE_CREDENTIALS=True, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,76 @@ | ||
| from datetime import datetime | ||
|
|
||
| from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String | ||
| from sqlalchemy.orm import relationship | ||
|
|
||
| from .database import Base | ||
| from app.database.database import Base | ||
|
|
||
|
|
||
| class UserEvent(Base): | ||
| __tablename__ = "user_event" | ||
|
|
||
| id = Column(Integer, primary_key=True, index=True) | ||
| user_id = Column('user_id', Integer, ForeignKey('users.id')) | ||
| event_id = Column('event_id', Integer, ForeignKey('events.id')) | ||
|
|
||
| events = relationship("Event", back_populates="participants") | ||
| participants = relationship("User", back_populates="events") | ||
|
|
||
| def __repr__(self): | ||
| return f'<UserEvent ({self.participants}, {self.events})>' | ||
|
|
||
|
|
||
| class User(Base): | ||
| __tablename__ = "users" | ||
|
|
||
| id = Column(Integer, primary_key=True, index=True) | ||
| username = Column(String, unique=True) | ||
| email = Column(String, unique=True) | ||
| password = Column(String) | ||
| username = Column(String, unique=True, nullable=False) | ||
| email = Column(String, unique=True, nullable=False) | ||
| password = Column(String, nullable=False) | ||
| full_name = Column(String) | ||
| description = Column(String, default="Happy new user!") | ||
| avatar = Column(String, default="profile.png") | ||
| is_active = Column(Boolean, default=False) | ||
|
|
||
| is_active = Column(Boolean, default=True) | ||
| events = relationship("UserEvent", back_populates="participants") | ||
|
|
||
| events = relationship( | ||
| "Event", cascade="all, delete", back_populates="owner") | ||
| def __repr__(self): | ||
| return f'<User {self.id}>' | ||
|
|
||
|
|
||
| class Event(Base): | ||
| __tablename__ = "events" | ||
|
|
||
| id = Column(Integer, primary_key=True, index=True) | ||
| title = Column(String) | ||
| content = Column(String) | ||
| title = Column(String, nullable=False) | ||
| start = Column(DateTime, nullable=False) | ||
| end = Column(DateTime, nullable=False) | ||
| content = Column(String) | ||
| location = Column(String) | ||
|
|
||
| owner = relationship("User") | ||
| owner_id = Column(Integer, ForeignKey("users.id")) | ||
| participants = relationship("UserEvent", back_populates="events") | ||
|
|
||
| def __repr__(self): | ||
| return f'<Event {self.id}>' | ||
|
|
||
|
|
||
| class Invitation(Base): | ||
| __tablename__ = "invitations" | ||
|
|
||
| id = Column(Integer, primary_key=True, index=True) | ||
| status = Column(String, nullable=False, default="unread") | ||
| recipient_id = Column(Integer, ForeignKey("users.id")) | ||
| event_id = Column(Integer, ForeignKey("events.id")) | ||
| creation = Column(DateTime, default=datetime.now) | ||
|
|
||
| recipient = relationship("User") | ||
| event = relationship("Event") | ||
|
|
||
| owner = relationship("User", back_populates="events") | ||
| def __repr__(self): | ||
| return ( | ||
| f'<Invitation ' | ||
| f'({self.event.owner}' | ||
| f'to {self.recipient})>' | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from operator import attrgetter | ||
| from typing import List | ||
|
|
||
| from app.database.models import Event | ||
|
|
||
|
|
||
| def sort_by_date(events: List[Event]) -> List[Event]: | ||
|
||
| """Sorts the events by the start of the event.""" | ||
|
|
||
| temp = events.copy() | ||
| temp.sort(key=attrgetter('start')) | ||
| return temp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from sqlalchemy.orm import Session | ||
|
|
||
| from app.database.models import Base | ||
|
|
||
|
|
||
| def save(item, session: Session) -> bool: | ||
| """Commits an instance to the db. | ||
| source: app.database.database.Base""" | ||
|
|
||
| if issubclass(item.__class__, Base): | ||
| session.add(item) | ||
| session.commit() | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def create_model(session: Session, model_class, **kw): | ||
| """Creates and saves a db model.""" | ||
|
|
||
| instance = model_class(**kw) | ||
| save(instance, session) | ||
| return instance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.