Skip to content

Commit

Permalink
Merge pull request #285 from RTIInternational/dev_fix_timezone
Browse files Browse the repository at this point in the history
fix broken timezone issue and some linting
  • Loading branch information
AstridKery authored Dec 15, 2023
2 parents 4630628 + 5d52d1f commit 6cc78e3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 32 deletions.
6 changes: 5 additions & 1 deletion backend/django/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def read_data_file(data_file):
elif data_file.content_type.startswith(
"application/vnd"
) and data_file.name.endswith(".xlsx"):
data = pd.read_excel(data_file, dtype=str).dropna(axis=0, how="all").replace(r'\n',' ', regex=True)
data = (
pd.read_excel(data_file, dtype=str)
.dropna(axis=0, how="all")
.replace(r"\n", " ", regex=True)
)
else:
raise ValidationError(
"File type is not supported. Received {0} but only {1} are supported.".format(
Expand Down
4 changes: 2 additions & 2 deletions backend/django/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Meta:
class DataLabelModelSerializer(serializers.ModelSerializer):
profile = serializers.StringRelatedField(many=False, read_only=True)
timestamp = serializers.DateTimeField(
default_timezone=pytz.timezone(TIME_ZONE_FRONTEND), format="%Y-%m-%d, %I:%m %p"
default_timezone=pytz.timezone(TIME_ZONE_FRONTEND), format="%Y-%m-%d, %I:%M %p"
)
verified = serializers.StringRelatedField(many=False, read_only=True)

Expand All @@ -103,7 +103,7 @@ class Meta:
class IRRLogModelSerializer(serializers.ModelSerializer):
profile = serializers.StringRelatedField(many=False, read_only=True)
timestamp = serializers.DateTimeField(
default_timezone=pytz.timezone(TIME_ZONE_FRONTEND), format="%Y-%m-%d, %I:%m %p"
default_timezone=pytz.timezone(TIME_ZONE_FRONTEND), format="%Y-%m-%d, %I:%M %p"
)

class Meta:
Expand Down
15 changes: 7 additions & 8 deletions backend/django/core/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,18 +630,18 @@ def get_labeled_data(project, unverified=True):
temp["Description"] = label.description
temp["Profile"] = str(d.profile.user)
if d.timestamp:
temp["Timestamp"] = pytz.timezone(TIME_ZONE_FRONTEND).normalize(
d.timestamp
temp["Timestamp"] = d.timestamp.astimezone(
pytz.timezone(TIME_ZONE_FRONTEND)
)
else:
temp["Timestamp"] = None
if hasattr(d, "verified"):
v = VerifiedDataLabel.objects.get(data_label=d)
temp["Verified"] = "Yes"
temp["Verified By"] = str(v.verified_by.user)
temp["Verified Timestamp"] = pytz.timezone(
TIME_ZONE_FRONTEND
).normalize(v.verified_timestamp)
temp["Verified Timestamp"] = v.verified_timestamp.astimezone(
pytz.timezone(TIME_ZONE_FRONTEND)
)
else:
temp["Verified"] = "No"
temp["Verified By"] = None
Expand Down Expand Up @@ -749,8 +749,7 @@ def get_projects_umbrellas(self):


def get_unlabelled_data_objs(project_id: int) -> int:
"""
Function to retrieve the total count of unlabelled data objects for a project.
"""Function to retrieve the total count of unlabelled data objects for a project.
This SQL query is comprised of 5 subqueries, each of which retrieves the ids of
data objects that are in a particular table. The first sub-query is the total list
Expand Down Expand Up @@ -799,7 +798,7 @@ def get_unlabelled_data_objs(project_id: int) -> int:
)
SELECT COUNT(*)
FROM (
SELECT p.id
SELECT p.id
FROM project_ids p
LEFT JOIN queue_ids q ON p.id = q.id
LEFT JOIN irr_log_ids irr ON p.id = irr.id
Expand Down
19 changes: 0 additions & 19 deletions backend/django/core/views/api_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,22 +1109,3 @@ def modify_metadata_values(request, data_pk):
metadata.value = m["value"]
metadata.save()
return Response({})


@api_view(["GET"])
@permission_classes((IsCoder,))
def get_labels(request, project_pk):
"""Grab data using get_assignments and send it to the frontend react app.
Args:
request: The request to the endpoint
project_pk: Primary key of project
Returns:
labels: The project labels
data: The data in the queue
"""
project = Project.objects.get(pk=project_pk)
labels = Label.objects.all().filter(project=project)

return Response({"labels": LabelSerializer(labels, many=True).data,})

8 changes: 7 additions & 1 deletion backend/django/smart/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ class Dev(Configuration):
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["0.0.0.0", "localhost", "backend", "smart-coding.rti.org", "cds-mallard.rtp.rti.org"]
ALLOWED_HOSTS = [
"0.0.0.0",
"localhost",
"backend",
"smart-coding.rti.org",
"cds-mallard.rtp.rti.org",
]

# Application definition

Expand Down
3 changes: 2 additions & 1 deletion backend/django/smart/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
1. Import the include() function: from django.urls import re_path, include
2. Add a URL to urlpatterns: re_path(r'^blog/', include('blog.urls'))
"""
from django.urls import include, re_path
from django.contrib import admin
from django.http import HttpResponseRedirect
from django.urls import include, re_path

# from rest_framework_swagger.views import get_swagger_view

urlpatterns = [
Expand Down

0 comments on commit 6cc78e3

Please sign in to comment.