Skip to content

Commit

Permalink
Merge pull request #1419 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
ig fix
  • Loading branch information
adnankattekaden authored Oct 24, 2023
2 parents b819454 + 095d632 commit b16fe51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions api/dashboard/ig/dash_ig_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get(self, request):
def post(self, request):
user_id = JWTUtils.fetch_user_id(request)

request_data = request.data.dict()
request_data = request.data

request_data["created_by"] = request_data["updated_by"] = user_id

Expand Down Expand Up @@ -83,7 +83,7 @@ def put(self, request, pk):

ig_old_name = ig.name

request_data = request.data.dict()
request_data = request.data
request_data["updated_by"] = user_id

serializer = InterestGroupCreateUpdateSerializer(
Expand Down
32 changes: 16 additions & 16 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
import datetime
import gzip
import io
from datetime import timedelta

import decouple
import openpyxl
import pytz
import requests
from decouple import config
from django.core.mail import EmailMessage
from django.core.mail import send_mail
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q
from django.db.models.query import QuerySet
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.core.mail import EmailMessage
from datetime import timedelta


class CommonUtils:
@staticmethod
def get_paginated_queryset(
queryset: QuerySet, request, search_fields, sort_fields: dict = None
) -> QuerySet:
) -> QuerySet:
if sort_fields is None:
sort_fields = { }
sort_fields = {}

page = int(request.query_params.get("pageIndex", 1))
per_page = int(request.query_params.get("perPage", 10))
Expand All @@ -34,7 +34,7 @@ def get_paginated_queryset(
if search_query:
query = Q()
for field in search_fields:
query |= Q(**{ f"{field}__icontains": search_query })
query |= Q(**{f"{field}__icontains": search_query})

queryset = queryset.filter(query)

Expand Down Expand Up @@ -64,8 +64,8 @@ def get_paginated_queryset(
"nextPage": queryset.next_page_number()
if queryset.has_next()
else None,
},
}
},
}

@staticmethod
def generate_csv(queryset: QuerySet, csv_name: str) -> HttpResponse:
Expand All @@ -79,7 +79,7 @@ def generate_csv(queryset: QuerySet, csv_name: str) -> HttpResponse:
compressed_response = HttpResponse(
gzip.compress(response.content),
content_type="text/csv",
)
)
compressed_response[
"Content-Disposition"
] = f'attachment; filename="{csv_name}.csv"'
Expand Down Expand Up @@ -124,7 +124,7 @@ def get_start_and_end_of_previous_month():
start_date = today.replace(day=1)
end_date = start_date.replace(
day=1, month=start_date.month % 12 + 1
) - timedelta(days=1)
) - timedelta(days=1)
return start_date, end_date


Expand Down Expand Up @@ -153,7 +153,7 @@ def general_updates(category, action, *values) -> str:
for value in values:
content = f"{content}<|=|>{value}"
url = config("DISCORD_WEBHOOK_LINK")
data = { "content": content }
data = {"content": content}
requests.post(url, json=data)


Expand All @@ -166,7 +166,7 @@ def read_excel_file(self, file_obj):
for row in sheet.iter_rows(values_only=True):
row_dict = {
header.value: cell_value for header, cell_value in zip(sheet[1], row)
}
}
rows.append(row_dict)
workbook.close()

Expand Down Expand Up @@ -194,8 +194,8 @@ def send_template_mail(
status = None

email_content = render_to_string(
f"mails/{'/'.join(map(str, address))}", { "user": context, "base_url": base_url }
)
f"mails/{'/'.join(map(str, address))}", {"user": context, "base_url": base_url}
)
if not (mail := getattr(context, "email", None)):
mail = context["email"]

Expand All @@ -207,17 +207,17 @@ def send_template_mail(
recipient_list=[mail],
html_message=email_content,
fail_silently=False,
)
)

else:
email = EmailMessage(
subject=subject,
body=email_content,
from_email=from_mail,
to=[context["email"]],
)
)
email.attach(attachment)
email.content_subtype = "html"
status = email.send()

return status
return status

0 comments on commit b16fe51

Please sign in to comment.