Skip to content
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

Issue 3 #16

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1b8f803
set up celery and rabbitmq
Joaquinecc Mar 26, 2021
f192655
Notify moderator that a new registration came in
Joaquinecc Mar 27, 2021
1a66bac
Notify registrants that theiy have been approved
Joaquinecc Mar 27, 2021
f1a453e
setting enviroment variable
Joaquinecc Mar 27, 2021
b9e1c29
add celery service
Joaquinecc Mar 28, 2021
7576cb2
Merge branch 'develop' into issue_3
Joaquinecc Mar 30, 2021
65aaf05
center Container 'Invesigadores del paraguay'
Joaquinecc Mar 30, 2021
1518a5a
Add new tools to Readme
Joaquinecc Mar 30, 2021
4aaab69
new template email registration
Joaquinecc Mar 30, 2021
3850061
new template approve registration
Joaquinecc Mar 31, 2021
4b3028f
add new raabbitmq .env.dev variable
Joaquinecc Mar 31, 2021
d99ada2
Change DEFAULT_APP_EMAIL_ADDRESS to ADMIN_EMAIL_AD
Joaquinecc Apr 1, 2021
685ece5
text changes on email templates
Joaquinecc Apr 1, 2021
f6dc1af
Modify Readme
Joaquinecc Apr 1, 2021
41a8313
Add new email env varables
Joaquinecc Apr 1, 2021
2936c55
specify version rabbit image
Joaquinecc Apr 1, 2021
067f41d
modify local variable name i=onnotify_user_appr
Joaquinecc Apr 1, 2021
c69d507
Modify readme
Joaquinecc Apr 1, 2021
6dc9dfa
modify readme
Joaquinecc Apr 1, 2021
86e34df
MODERATOR_EMAIL_ADDRESSES
Joaquinecc Apr 5, 2021
c1a9af9
send email with zoho
Joaquinecc Apr 6, 2021
60370ed
add more styling email templates
Joaquinecc Apr 6, 2021
d8c0c6e
move celery broker variable
Joaquinecc Apr 11, 2021
27de7df
Add more style[approved_email.html]
Joaquinecc Apr 11, 2021
7313549
Update Readme
Joaquinecc Apr 17, 2021
13a077d
remove unnecesary ADMIN_EMAIL_ADDRESS env variable
Joaquinecc May 5, 2021
d5c479c
remove $ on CELERY_BROKER_URL
Joaquinecc May 22, 2021
33777e6
reedit template email aproved
Joaquinecc May 25, 2021
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
22 changes: 22 additions & 0 deletions app/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

from django.template import Context
from django.template.loader import render_to_string
from django.core.mail import EmailMessage
from django.conf import settings

def send_new_email_registration(name, ci, email):
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved

context = {
'name': name,
'email': email,
'ci': ci,
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
}

email_subject = 'New registration (cipe)'
email_body = render_to_string('email/new_email_registration.txt', context)

email = EmailMessage(
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
email_subject, email_body,
settings.DEFAULT_FROM_EMAIL,settings.EMAILS_FROM_MODERATOR,
)
return email.send(fail_silently=False)
5 changes: 3 additions & 2 deletions app/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from app.constants import SEX, SCIENTIFIC_AREA, POSITION, COMMUNICATION_CHANNELS

from app.tasks import send_new_registration_email_task
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
SEX_EMPTY = [('','Indique su sexo')] + list(SEX)
SCI_AREA_EMPTY = [('','Seleccione un área')] + list(SCIENTIFIC_AREA)
POSITION_EMPTY = [('','Seleccione su nivel académico')] + list(POSITION)
Expand Down Expand Up @@ -144,7 +144,8 @@ class RegistrationForm(forms.Form):
location_name = forms.CharField(widget=forms.HiddenInput(), required=False)
location_lat = forms.CharField(widget=forms.HiddenInput(), required=False)
location_lng = forms.CharField(widget=forms.HiddenInput(), required=False)

def send_email(self):
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
send_new_registration_email_task.delay(self.cleaned_data['first_name']+self.cleaned_data['last_name'],self.cleaned_data['ci'],self.cleaned_data['email'])

class RegistrationEditForm(forms.Form):
first_name = forms.CharField(label='Nombre *', widget=forms.TextInput(
Expand Down
15 changes: 15 additions & 0 deletions app/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from celery import shared_task
from celery.decorators import task
from celery.utils.log import get_task_logger
from .email import send_new_email_registration

logger=get_task_logger(__name__)

@task(name="send_new_registration_email_task")
def send_new_registration_email_task(name,ci,email):
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
print("Sent new registration email")
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
logger.info("Sent new registration email")
return send_new_email_registration(name,ci,email)
@shared_task
def add(x, y):
return x + y
9 changes: 9 additions & 0 deletions app/templates/email/new_email_registration.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Hello Moderator
Just notify you {{name|safe}} join the community
Here some info from the new user:
Nombre completo : {{name|safe}}
CI : {{ci|safe}}
email : {{email|safe}}


Thank you!
7 changes: 7 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ def registration(request):
'institution': inst_obj})
msg = f"Registro exitoso! Luego de su aprobación, los datos podrán ser " \
f"visualizados en el mapa de investigadores."
#Notify moderator of the new register
try:
form.send_email()
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
print("Succesfuly sent email new regitration")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cambiar por print por logger

except:
print("Fail to sent email new registration")
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved

form = RegistrationForm()
registration_error = 0
else:
Expand Down
3 changes: 3 additions & 0 deletions cipe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .celery import app as celery_app

__all__ = ('celery_app',)
22 changes: 22 additions & 0 deletions cipe/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cipe.settings')

app = Celery('cipe')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
version: '3.7'

services:
rabbit:
hostname: rabbit
image: rabbitmq:3-management
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
environment:
- RABBITMQ_DEFAULT_USER=guest
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
- RABBITMQ_DEFAULT_PASS=guest
Joaquinecc marked this conversation as resolved.
Show resolved Hide resolved
ports:
- "5672:5672"
- "15672:15672"
app:
restart: always
build: .
Expand All @@ -25,4 +34,4 @@ services:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT}
- MYSQL_DATABASE=${SQL_DATABASE}
- MYSQL_USER=${SQL_USER}
- MYSQL_PASSWORD=${SQL_PASSWORD}
- MYSQL_PASSWORD=${SQL_PASSWORD}
17 changes: 16 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
amqp==5.0.5
billiard==3.6.3.0
celery==5.0.5
certifi==2019.6.16
chardet==3.0.4
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
Django==2.2.10
googlemaps==3.0.2
gunicorn==19.9.0
idna==2.8
importlib-metadata==3.7.3
kombu==5.0.2
mysqlclient==1.4.2.post1
prompt-toolkit==3.0.18
pytz==2019.1
requests==2.22.0
six==1.15.0
sqlparse==0.3.0
typing-extensions==3.7.4.3
urllib3==1.25.3
gunicorn==19.9.0
vine==5.0.0
wcwidth==0.2.5
zipp==3.4.1