Skip to content

Commit

Permalink
Improve to readme, fix bug in goals and emails
Browse files Browse the repository at this point in the history
  • Loading branch information
Heibert committed Jun 21, 2024
1 parent b8de0a7 commit 83009fa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
23 changes: 11 additions & 12 deletions INSIGHTSAPI/INSIGHTSAPI/custom/custom_email_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Custom Email Backend for Django using our own SMTP server"""

import sys
import ssl
import logging
Expand All @@ -8,6 +6,7 @@
from imaplib import IMAP4_SSL
from django.conf import settings
from django.core.mail.backends.smtp import EmailBackend
from django.core.mail import EmailMultiAlternatives


logger = logging.getLogger("requests")
Expand Down Expand Up @@ -68,8 +67,8 @@ def add_signature(self, message):
Mensaje generado automáticamente, por favor no responder.
"""

# Ensure HTML signature is added to the HTML alternative part
if message.alternatives:
if isinstance(message, EmailMultiAlternatives):
# Ensure HTML signature is added to the HTML alternative part
has_html_alternative = False
for i, (content, mime_type) in enumerate(message.alternatives):
if mime_type == "text/html":
Expand All @@ -82,14 +81,14 @@ def add_signature(self, message):
else:
# If no alternatives, ensure a plain text alternative is added
if message.content_subtype == "html":
message.alternatives.append(
message.alternatives = [
(message.body.replace("\n", "<br>") + html_signature, "text/html")
)
]
else:
message.alternatives.append(
(message.body.replace("\n", "<br>") + html_signature, "text/html")
)
message.alternatives.append((message.body, "text/plain"))
message.alternatives = [
(message.body.replace("\n", "<br>") + html_signature, "text/html"),
(message.body, "text/plain")
]

# Add the appropriate signature based on content_subtype
if message.content_subtype == "html":
Expand All @@ -98,7 +97,7 @@ def add_signature(self, message):
message.body += plain_signature

# Ensure the message body is plain text if alternatives exist
if message.content_subtype == "html" and message.alternatives:
if message.content_subtype == "html" and isinstance(message, EmailMultiAlternatives):
message.body = (
message.body.replace(html_signature, "").strip() + plain_signature
)
Expand All @@ -119,7 +118,7 @@ def open(self):
if not self.fail_silently:
raise e

# Override the send_messages method without changing his working
# Override the send_messages method without changing its functionality
def send_messages(self, email_messages):
if not email_messages:
return
Expand Down
4 changes: 2 additions & 2 deletions INSIGHTSAPI/INSIGHTSAPI/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ def str_to_bool(value: str) -> bool:
"HOST": os.environ["SERVER_DB"],
"PORT": "3306",
"USER": "INSIGHTSUSER",
"PASSWORD": os.environ["INSIGHTSMYSQL"],
"PASSWORD": os.environ["INSIGHTS_DB_PASS"],
"NAME": "insights",
},
"staffnet": {
"ENGINE": "django.db.backends.mysql",
"HOST": os.environ["SERVER_DB"],
"PORT": "3306",
"USER": "INSIGHTSUSER",
"PASSWORD": os.environ["INSIGHTSMYSQL"],
"PASSWORD": os.environ["INSIGHTS_DB_PASS"],
"NAME": "staffnet",
"TEST": {"MIRROR": "staffnet"},
},
Expand Down
28 changes: 14 additions & 14 deletions INSIGHTSAPI/goals/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ def partial_update(self, request, *args, **kwargs):
Información de la meta:
- Cedula: {instance['cedula']}
- Nombres: {instance['name']}
- Campaña: {instance['campaign_goal']}
- Cargo: {instance['job_title_goal']}
- Coordinador: {instance['coordinator_goal']}
- Mes: {instance['goal_date']}
- Cedula: {instance.cedula}
- Nombres: {instance.name}
- Campaña: {instance.campaign_goal}
- Cargo: {instance.job_title_goal}
- Coordinador: {instance.coordinator_goal}
- Mes: {instance.goal_date}
Descripción de la Variable a medir | Cantidad
---------------------------------- | --------
{instance['criteria_goal']:<33} | {instance['quantity_goal']}
{instance.criteria_goal:<33} | {instance.quantity_goal}
""",
None,
[user.email],
Expand Down Expand Up @@ -194,16 +194,16 @@ def partial_update(self, request, *args, **kwargs):
Información de la ejecución de la meta:
- Cedula: {instance['cedula']}
- Nombres: {instance['name']}
- Campaña: {instance['campaign_execution']}
- Cargo: {instance['job_title_execution']}
- Coordinador: {instance['coordinator_execution']}
- Mes: {instance['execution_date']}
- Cedula: {instance.cedula}
- Nombres: {instance.name}
- Campaña: {instance.campaign_execution}
- Cargo: {instance.job_title_execution}
- Coordinador: {instance.coordinator_execution}
- Mes: {instance.execution_date}
Clean Desk | Evaluación | Resultado | Calidad | Total
------------- | ---------- | --------- | ------- | -----
{instance['clean_desk']:<13} | {instance['evaluation']:<10} | {instance['result']:<9} | {instance['quality']:<7} | {instance['total']}
{instance.clean_desk:<13} | {instance.evaluation:<10} | {instance.result:<9} | {instance.quality:<7} | {instance.total}
""",
None,
[user.email],
Expand Down
1 change: 1 addition & 0 deletions INSIGHTSAPI/pqrs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def create(self, request, *args, **kwargs):
if not "description" in self.request.data:
return Response({"error": "La descripción es requerida"}, status=400)
response = super().create(request, *args, **kwargs)

if response.status_code == status.HTTP_201_CREATED:
options = {
"TEST": settings.EMAIL_FOR_TEST,
Expand Down
13 changes: 13 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ export default ShoppingCart;
EMAIL_HOST=your.smtp.server.com
EMAIL_PORT=your smtp port usually 587
EMAIL_HOST_PASSWORD=your smtp password
EMAILS_ETHICAL_LINE= List of emails separated by commas that will receive the emails (e.g. "email1@example.com", "email2@example.com", etc)
EMAIL_FOR_TEST=The email that will receive the test emails (e.g. "email@example.com")
TEST_CEDULA=The cedula that will be used for testing purposes (It have to be register in StaffNet) (e.g. "123456789")
SERVER_DB=YOUR_DB_SERVER_IP (e.g. "173.16.0.22")
INSIGHTS_DB_PASS=YOUR_DB_PASSWORD (e.g. "password")
AdminLDAPPassword=YOUR_LDAP_PASSWORD (e.g. "password")
```
5. In the `settings.py` file, change the `ENV_PATH` variable to the path of the `.env` file
6. Run the following command to realize the migrations: `python manage.py migrate`
7. Verify that all has been set up correctly by running the following command: `python manage.py test`
8. Run the following command to start the backend server: `python manage.py runserver`
9. The backend server will start running on port 8000 that is to say, you can access the backend by going to `http://server_ip:8000`
## Migration
### Frontend:
Expand Down

0 comments on commit 83009fa

Please sign in to comment.