Skip to content

Commit 44f30a0

Browse files
committed
Merge branch 'develop' into feature/shareable-event
2 parents ba09ff0 + 17a43c6 commit 44f30a0

File tree

11 files changed

+454
-9
lines changed

11 files changed

+454
-9
lines changed

.gitattributes

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
* text=auto
2+
3+
4+
*.pxd text diff=python
5+
*.py text diff=python
6+
*.py3 text diff=python
7+
*.pyw text diff=python
8+
*.pyx text diff=python
9+
*.pyz text diff=python
10+
*.pyi text diff=python
11+
12+
# Binary files
13+
# ============
14+
*.db binary
15+
*.p binary
16+
*.pkl binary
17+
*.pickle binary
18+
*.pyc binary
19+
*.pyd binary
20+
*.pyo binary
21+
22+
# Jupyter notebook
23+
*.ipynb text
24+
25+
# These files are text and should be normalized (Convert crlf => lf)
26+
.gitignore text
27+
28+
# Documents
29+
*.bibtex text diff=bibtex
30+
*.doc diff=astextplain
31+
*.DOC diff=astextplain
32+
*.docx diff=astextplain
33+
*.DOCX diff=astextplain
34+
*.dot diff=astextplain
35+
*.DOT diff=astextplain
36+
*.pdf diff=astextplain
37+
*.PDF diff=astextplain
38+
*.rtf diff=astextplain
39+
*.RTF diff=astextplain
40+
*.md text
41+
*.tex text diff=tex
42+
*.adoc text
43+
*.textile text
44+
*.mustache text
45+
*.csv text
46+
*.tab text
47+
*.tsv text
48+
*.txt text
49+
*.sql text
50+
51+
# Graphics
52+
*.png binary
53+
*.jpg binary
54+
*.jpeg binary
55+
*.gif binary
56+
*.tif binary
57+
*.tiff binary
58+
*.ico binary
59+
# SVG treated as an asset (binary) by default.
60+
*.svg text
61+
# If you want to treat it as binary,
62+
# use the following line instead.
63+
# *.svg binary
64+
*.eps binary
65+
66+
# Scripts
67+
*.bash text eol=lf
68+
*.fish text eol=lf
69+
*.sh text eol=lf
70+
# These are explicitly windows files and should use crlf
71+
*.bat text eol=crlf
72+
*.cmd text eol=crlf
73+
*.ps1 text eol=crlf
74+
75+
# Serialisation
76+
*.json text
77+
*.toml text
78+
*.xml text
79+
*.yaml text
80+
*.yml text
81+
82+
# Archives
83+
*.7z binary
84+
*.gz binary
85+
*.tar binary
86+
*.tgz binary
87+
*.zip binary
88+
89+
# Text files where line endings should be preserved
90+
*.patch -text
91+
92+
# Source code
93+
*.bash text eol=lf
94+
*.cmd text eol=crlf
95+
*.coffee text
96+
*.css text
97+
*.htm text diff=html
98+
*.html text diff=html
99+
*.inc text
100+
*.ini text
101+
*.js text
102+
*.json text
103+
*.jsx text
104+
*.less text
105+
*.ls text
106+
*.map text -diff
107+
*.od text
108+
*.onlydata text
109+
*.php text diff=php
110+
*.pl text
111+
*.ps1 text eol=crlf
112+
*.rb text diff=ruby
113+
*.sass text
114+
*.scm text
115+
*.scss text diff=css
116+
*.sh text eol=lf
117+
*.sql text
118+
*.styl text
119+
*.tag text
120+
*.ts text
121+
*.tsx text
122+
*.xml text
123+
*.xhtml text diff=html
124+
125+
# Docker
126+
Dockerfile text
127+
128+
# Documentation
129+
*.markdown text
130+
*.md text
131+
*.mdwn text
132+
*.mdown text
133+
*.mkd text
134+
*.mkdn text
135+
*.mdtxt text
136+
*.mdtext text
137+
*.txt text
138+
AUTHORS text
139+
CHANGELOG text
140+
CHANGES text
141+
CONTRIBUTING text
142+
COPYING text
143+
copyright text
144+
*COPYRIGHT* text
145+
INSTALL text
146+
license text
147+
LICENSE text
148+
NEWS text
149+
readme text
150+
*README* text
151+
TODO text
152+
153+
# Templates
154+
*.dot text
155+
*.ejs text
156+
*.haml text
157+
*.handlebars text
158+
*.hbs text
159+
*.hbt text
160+
*.jade text
161+
*.latte text
162+
*.mustache text
163+
*.njk text
164+
*.phtml text
165+
*.tmpl text
166+
*.tpl text
167+
*.twig text
168+
*.vue text
169+
170+
# Configs
171+
*.cnf text
172+
*.conf text
173+
*.config text
174+
.editorconfig text
175+
.env text
176+
.gitattributes text
177+
.gitconfig text
178+
.htaccess text
179+
*.lock text -diff
180+
package-lock.json text -diff
181+
*.toml text
182+
*.yaml text
183+
*.yml text
184+
browserslist text
185+
Makefile text
186+
makefile text
187+
188+
# Heroku
189+
Procfile text
190+
191+
# Graphics
192+
*.ai binary
193+
*.bmp binary
194+
*.eps binary
195+
*.gif binary
196+
*.gifv binary
197+
*.ico binary
198+
*.jng binary
199+
*.jp2 binary
200+
*.jpg binary
201+
*.jpeg binary
202+
*.jpx binary
203+
*.jxr binary
204+
*.pdf binary
205+
*.png binary
206+
*.psb binary
207+
*.psd binary
208+
# SVG treated as an asset (binary) by default.
209+
*.svg text
210+
# If you want to treat it as binary,
211+
# use the following line instead.
212+
# *.svg binary
213+
*.svgz binary
214+
*.tif binary
215+
*.tiff binary
216+
*.wbmp binary
217+
*.webp binary
218+
219+
# Audio
220+
*.kar binary
221+
*.m4a binary
222+
*.mid binary
223+
*.midi binary
224+
*.mp3 binary
225+
*.ogg binary
226+
*.ra binary
227+
228+
# Video
229+
*.3gpp binary
230+
*.3gp binary
231+
*.as binary
232+
*.asf binary
233+
*.asx binary
234+
*.fla binary
235+
*.flv binary
236+
*.m4v binary
237+
*.mng binary
238+
*.mov binary
239+
*.mp4 binary
240+
*.mpeg binary
241+
*.mpg binary
242+
*.ogv binary
243+
*.swc binary
244+
*.swf binary
245+
*.webm binary
246+
247+
# Archives
248+
*.7z binary
249+
*.gz binary
250+
*.jar binary
251+
*.rar binary
252+
*.tar binary
253+
*.zip binary
254+
255+
# Fonts
256+
*.ttf binary
257+
*.eot binary
258+
*.otf binary
259+
*.woff binary
260+
*.woff2 binary
261+
262+
# Executables
263+
*.exe binary
264+
*.pyc binary
265+
266+
# RC files (like .babelrc or .eslintrc)
267+
*.*rc text
268+
269+
# Ignore files (like .npmignore or .gitignore)
270+
*.*ignore text
271+
272+
tests/samples/* text=false
273+
274+
#
275+
# Exclude files from exporting
276+
#
277+
278+
.gitattributes export-ignore
279+
.gitignore export-ignore
280+
.gitkeep export-ignore

app/config.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import os
2+
3+
from fastapi_mail import ConnectionConfig
4+
# flake8: noqa
5+
16
# general
27
DOMAIN = 'Our-Domain'
38

4-
59
# DATABASE
610
DEVELOPMENT_DATABASE_STRING = "sqlite:///./dev.db"
711

@@ -13,3 +17,15 @@
1317
# export
1418
ICAL_VERSION = '2.0'
1519
PRODUCT_ID = '-//Our product id//'
20+
21+
# email
22+
email_conf = ConnectionConfig(
23+
MAIL_USERNAME=os.getenv("MAIL_USERNAME") or "user",
24+
MAIL_PASSWORD=os.getenv("MAIL_PASSWORD") or "password",
25+
MAIL_FROM=os.getenv("MAIL_FROM") or "a@a.com",
26+
MAIL_PORT=587,
27+
MAIL_SERVER="smtp.gmail.com",
28+
MAIL_TLS=True,
29+
MAIL_SSL=False,
30+
USE_CREDENTIALS=True,
31+
)

app/config.py.example

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import os
2+
3+
from fastapi_mail import ConnectionConfig
4+
# flake8: noqa
5+
16
# general
27
DOMAIN = 'Our-Domain'
38

4-
59
# DATABASE
610
DEVELOPMENT_DATABASE_STRING = "sqlite:///./dev.db"
711

@@ -13,3 +17,15 @@ AVATAR_SIZE = (120, 120)
1317
# export
1418
ICAL_VERSION = '2.0'
1519
PRODUCT_ID = '-//Our product id//'
20+
21+
# email
22+
email_conf = ConnectionConfig(
23+
MAIL_USERNAME=os.getenv("MAIL_USERNAME") or "user",
24+
MAIL_PASSWORD=os.getenv("MAIL_PASSWORD") or "password",
25+
MAIL_FROM=os.getenv("MAIL_FROM") or "a@a.com",
26+
MAIL_PORT=587,
27+
MAIL_SERVER="smtp.gmail.com",
28+
MAIL_TLS=True,
29+
MAIL_SSL=False,
30+
USE_CREDENTIALS=True,
31+
)

app/internal/email.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from app.config import email_conf
2+
from app.database.models import Event, User
3+
from fastapi import BackgroundTasks
4+
from fastapi_mail import FastMail, MessageSchema
5+
from sqlalchemy.orm.session import Session
6+
7+
mail = FastMail(email_conf)
8+
9+
10+
def send(
11+
session: Session, event_used: int, user_to_send: int,
12+
title: str, background_tasks: BackgroundTasks = BackgroundTasks
13+
) -> bool:
14+
"""This function is being used to send emails in the background.
15+
It takes an event and a user and it sends the event to the user.
16+
17+
Args:
18+
session(Session): The session to redirect to the database.
19+
title (str): Title of the email that is being sent.
20+
event_used (int): Id number of the event that is used.
21+
user_to_send (int): Id number of user that we want to notify.
22+
background_tasks (BackgroundTasks): Function from fastapi that lets
23+
you apply tasks in the background.
24+
25+
Returns:
26+
bool: Returns True if the email was sent, else returns False.
27+
"""
28+
event_used = session.query(Event).filter(
29+
Event.id == event_used).first()
30+
user_to_send = session.query(User).filter(
31+
User.id == user_to_send).first()
32+
if not user_to_send or not event_used:
33+
return False
34+
message = MessageSchema(
35+
subject=f"{title} {event_used.title}",
36+
recipients={"email": [user_to_send.email]}.get("email"),
37+
body=f"begins at:{event_used.start} : {event_used.content}",
38+
)
39+
background_tasks.add_task(mail.send_message, message)
40+
return True

app/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from app.database.database import engine
66
from app.dependencies import (
77
MEDIA_PATH, STATIC_PATH, templates)
8-
from app.routers import agenda, event, profile, invitation
8+
from app.routers import agenda, event, profile, email, invitation
99

1010
models.Base.metadata.create_all(bind=engine)
1111

@@ -16,6 +16,7 @@
1616
app.include_router(profile.router)
1717
app.include_router(event.router)
1818
app.include_router(agenda.router)
19+
app.include_router(email.router)
1920
app.include_router(invitation.router)
2021

2122

0 commit comments

Comments
 (0)