Skip to content

Commit 2f23667

Browse files
committed
Refactor populate.py for improved formatting and readability; minor adjustments in restapis.py and views.py for consistency
1 parent 7db4ae3 commit 2f23667

File tree

5 files changed

+108
-30
lines changed

5 files changed

+108
-30
lines changed

server/djangoapp/populate.py

Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,96 @@ def initiate():
2121

2222
# Create CarModel instances with the corresponding CarMake instances
2323
car_model_data = [
24-
{"name": "Pathfinder", "type": "SUV", "year": 2023, "car_make": car_make_instances[0]},
25-
{"name": "Qashqai", "type": "SUV", "year": 2023, "car_make": car_make_instances[0]},
26-
{"name": "XTRAIL", "type": "SUV", "year": 2023, "car_make": car_make_instances[0]},
27-
{"name": "A-Class", "type": "SUV", "year": 2023, "car_make": car_make_instances[1]},
28-
{"name": "C-Class", "type": "SUV", "year": 2023, "car_make": car_make_instances[1]},
29-
{"name": "E-Class", "type": "SUV", "year": 2023, "car_make": car_make_instances[1]},
30-
{"name": "A4", "type": "SUV", "year": 2023, "car_make": car_make_instances[2]},
31-
{"name": "A5", "type": "SUV", "year": 2023, "car_make": car_make_instances[2]},
32-
{"name": "A6", "type": "SUV", "year": 2023, "car_make": car_make_instances[2]},
33-
{"name": "Sorrento", "type": "SUV", "year": 2023, "car_make": car_make_instances[3]},
34-
{"name": "Carnival", "type": "SUV", "year": 2023, "car_make": car_make_instances[3]},
35-
{"name": "Cerato", "type": "Sedan", "year": 2023, "car_make": car_make_instances[3]},
36-
{"name": "Corolla", "type": "Sedan", "year": 2023, "car_make": car_make_instances[4]},
37-
{"name": "Camry", "type": "Sedan", "year": 2023, "car_make": car_make_instances[4]},
38-
{"name": "Kluger", "type": "SUV", "year": 2023, "car_make": car_make_instances[4]},
24+
{
25+
"name": "Pathfinder",
26+
"type": "SUV",
27+
"year": 2023,
28+
"car_make": car_make_instances[0],
29+
},
30+
{
31+
"name": "Qashqai",
32+
"type": "SUV",
33+
"year": 2023,
34+
"car_make": car_make_instances[0],
35+
},
36+
{
37+
"name": "XTRAIL",
38+
"type": "SUV",
39+
"year": 2023,
40+
"car_make": car_make_instances[0],
41+
},
42+
{
43+
"name": "A-Class",
44+
"type": "SUV",
45+
"year": 2023,
46+
"car_make": car_make_instances[1],
47+
},
48+
{
49+
"name": "C-Class",
50+
"type": "SUV",
51+
"year": 2023,
52+
"car_make": car_make_instances[1],
53+
},
54+
{
55+
"name": "E-Class",
56+
"type": "SUV",
57+
"year": 2023,
58+
"car_make": car_make_instances[1],
59+
},
60+
{
61+
"name": "A4",
62+
"type": "SUV",
63+
"year": 2023,
64+
"car_make": car_make_instances[2],
65+
},
66+
{
67+
"name": "A5",
68+
"type": "SUV",
69+
"year": 2023,
70+
"car_make": car_make_instances[2],
71+
},
72+
{
73+
"name": "A6",
74+
"type": "SUV",
75+
"year": 2023,
76+
"car_make": car_make_instances[2],
77+
},
78+
{
79+
"name": "Sorrento",
80+
"type": "SUV",
81+
"year": 2023,
82+
"car_make": car_make_instances[3],
83+
},
84+
{
85+
"name": "Carnival",
86+
"type": "SUV",
87+
"year": 2023,
88+
"car_make": car_make_instances[3],
89+
},
90+
{
91+
"name": "Cerato",
92+
"type": "Sedan",
93+
"year": 2023,
94+
"car_make": car_make_instances[3],
95+
},
96+
{
97+
"name": "Corolla",
98+
"type": "Sedan",
99+
"year": 2023,
100+
"car_make": car_make_instances[4],
101+
},
102+
{
103+
"name": "Camry",
104+
"type": "Sedan",
105+
"year": 2023,
106+
"car_make": car_make_instances[4],
107+
},
108+
{
109+
"name": "Kluger",
110+
"type": "SUV",
111+
"year": 2023,
112+
"car_make": car_make_instances[4],
113+
},
39114
# Add more CarModel instances as needed
40115
]
41116

@@ -45,4 +120,4 @@ def initiate():
45120
car_make=data['car_make'],
46121
type=data['type'],
47122
year=data['year'],
48-
)
123+
)

server/djangoapp/restapis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ def post_review(data_dict):
5959
return response.json()
6060
except Exception:
6161
print("Network exception occurred")
62-
# Add code for posting review
62+
# Add code for posting review

server/djangoapp/views.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Uncomment the required imports before adding the code
22

3-
from django.shortcuts import render, redirect
43
from django.contrib.auth.models import User
54
from django.contrib.auth import logout, login, authenticate
65
from django.http import JsonResponse
@@ -51,17 +50,14 @@ def login_user(request):
5150

5251

5352
# Create a `logout_request` view to handle sign out request
54-
5553
def logout_request(request):
5654
logout(request) # Terminate user session
5755
data = {"userName": ""} # Return empty username
5856
return JsonResponse(data)
59-
# ...
6057

6158

6259
# Create a `registration` view to handle sign up request
6360
@csrf_exempt
64-
6561
def registration(request):
6662
# Load JSON data from the request body
6763
data = json.loads(request.body)
@@ -96,11 +92,10 @@ def registration(request):
9692
else:
9793
data = {"userName": username, "error": "Already Registered"}
9894
return JsonResponse(data)
99-
# ...
95+
10096

10197
# Update the `get_dealerships` render list of dealerships all by default,
10298
# particular state if state is passed
103-
10499
def get_dealerships(request, state="All"):
105100
if state == "All":
106101
endpoint = "/fetchDealers"
@@ -131,11 +126,13 @@ def add_review(request):
131126
if request.user.is_anonymous is False:
132127
data = json.loads(request.body)
133128
try:
134-
response = post_review(data)
135-
# response is not used; only status returned
129+
post_review(data)
136130
return JsonResponse({"status": 200})
137131
except Exception:
138-
return JsonResponse({"status": 401, "message": "Error in posting review"})
132+
return JsonResponse({
133+
"status": 401,
134+
"message": "Error in posting review",
135+
})
139136
else:
140137
return JsonResponse({"status": 403, "message": "Unauthorized"})
141138

@@ -155,4 +152,4 @@ def get_dealer_reviews(request, dealer_id):
155152
review_detail['sentiment'] = response['sentiment']
156153
return JsonResponse({"status": 200, "reviews": reviews})
157154
else:
158-
return JsonResponse({"status": 400, "message": "Bad Request"})
155+
return JsonResponse({"status": 400, "message": "Bad Request"})

server/djangoproj/settings.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@
3131

3232
ALLOWED_HOSTS = [
3333
'localhost',
34-
'https://baamranemoua-8000.theiadockernext-0-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai',
34+
(
35+
'https://baamranemoua-8000.theiadockernext-0-labs-prod-'
36+
'theiak8s-4-tor01.proxy.cognitiveclass.ai'
37+
),
3538
]
3639
CSRF_TRUSTED_ORIGINS = [
37-
'https://baamranemoua-8000.theiadockernext-0-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai',
40+
(
41+
'https://baamranemoua-8000.theiadockernext-0-labs-prod-'
42+
'theiak8s-4-tor01.proxy.cognitiveclass.ai'
43+
),
3844
]
3945

4046
REST_FRAMEWORK = {

server/djangoproj/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
TemplateView.as_view(template_name="index.html"),
3131
),
3232
path('register/', TemplateView.as_view(template_name="index.html")),
33-
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
33+
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

0 commit comments

Comments
 (0)