Skip to content

Commit c423cdd

Browse files
committed
CI/CD2
1 parent 83fe0e3 commit c423cdd

File tree

6 files changed

+132
-48
lines changed

6 files changed

+132
-48
lines changed

server/djangoapp/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class CarModel(models.Model):
2525
# Add more choices as required
2626
]
2727
type = models.CharField(max_length=10, choices=CAR_TYPES, default='SUV')
28-
year = models.IntegerField(default=2023,
29-
validators=[MaxValueValidator(2023),MinValueValidator(2015)])
30-
# Other fields as needed
28+
year = models.IntegerField(default=2023,
29+
validators=[MaxValueValidator(2023), MinValueValidator(2015)])
30+
3131

3232
def __str__(self):
3333
return self.name # Return the name as the string representation

server/djangoapp/populate.py

Lines changed: 95 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,103 @@ def initiate():
1212

1313
car_make_instances = []
1414
for data in car_make_data:
15-
car_make_instances.append(CarMake.objects.create(name=data['name'], description=data['description']))
15+
car_make_instances.append(CarMake.objects.create(
16+
name=data['name'], description=data['description']))
1617

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

39112
for data in car_model_data:
40-
CarModel.objects.create(name=data['name'], car_make=data['car_make'], type=data['type'], year=data['year'])
113+
CarModel.objects.create(name=data['name'],
114+
car_make=data['car_make'], type=data['type'], year=data['year'])

server/djangoapp/urls.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@
66

77
app_name = 'djangoapp'
88
urlpatterns = [
9-
path(route='get_cars', view=views.get_cars, name ='getcars'),
9+
path(route='get_cars', view=views.get_cars, name='getcars'),
1010
# # path for registration
1111
path('register', views.registration, name='register'),
1212
# path for login
1313
path(route='login', view=views.login_user, name='login'),
1414
path('logout', views.logout_request, name='logout'),
1515
# path for dealer reviews view
1616
path(route='get_dealers/', view=views.get_dealerships, name='get_dealers'),
17-
path(route='get_dealers/<str:state>/',
18-
view=views.get_dealerships, name='get_dealers_by_state'),
17+
path(route='get_dealers/<str:state>/',
18+
view=views.get_dealerships,
19+
name='get_dealers_by_state'),
1920
path(route='dealer/<int:dealer_id>',
20-
view=views.get_dealer_details, name='dealer_details'),
21+
view=views.get_dealer_details,
22+
name='dealer_details'),
2123
path(route='reviews/dealer/<int:dealer_id>',
22-
view=views.get_dealer_reviews, name='dealer_reviews'),
24+
view=views.get_dealer_reviews,
25+
name='dealer_reviews'),
2326

2427
# path for add a review view
2528
path(route='add_review', view=views.add_review, name='add_review'),

server/djangoapp/views.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Uncomment the required imports before adding the code
2-
3-
from django.shortcuts import render
42
from django.contrib.auth.models import User
53
from django.contrib.auth import logout
64

@@ -11,7 +9,7 @@
119
from django.views.decorators.csrf import csrf_exempt
1210
from .populate import initiate
1311
from .models import CarMake, CarModel
14-
from .restapis import get_request, analyze_review_sentiments, post_review
12+
from .restapis import get_request, analyze_review_sentiments
1513

1614

1715
# Get an instance of a logger
@@ -39,7 +37,7 @@ def login_user(request):
3937

4038
# Create a `logout_request` view to handle sign out request
4139
def logout_request(request):
42-
logout(request) # Terminate user session
40+
logout(request) # Terminate user session
4341
data = {"userName": ""} # Return empty username
4442
return JsonResponse(data)
4543

@@ -59,15 +57,20 @@ def registration(request):
5957
# Check if user already exists
6058
User.objects.get(username=username)
6159
username_exist = True
62-
except Exception as e:
60+
except Exception:
6361
# If not, simply log this is a new user
6462
logger.debug("{} is new user".format(username))
6563

6664
# If it is a new user
6765
if not username_exist:
6866
# Create user in auth_user table
69-
user = User.objects.create_user(username=username,
70-
first_name=first_name, last_name=last_name, password=password, email=email)
67+
user = User.objects.create_user(
68+
username=username,
69+
first_name=first_name,
70+
last_name=last_name,
71+
password=password,
72+
email=email
73+
)
7174
# Login the user and redirect to list page
7275
login(request, user)
7376
data = {"userName": username, "status": "Authenticated"}
@@ -128,10 +131,9 @@ def get_dealer_details(request, dealer_id):
128131
# Create a `add_review` view to submit a review
129132
def add_review(request):
130133
if(request.user.is_anonymous is False):
131-
data = json.loads(request.body)
132134
try:
133135
return JsonResponse({"status": 200})
134-
except:
136+
except Exception:
135137
return JsonResponse({"status": 401, "message": "Error in posting review"})
136138
else:
137139
return JsonResponse({"status": 403, "message": "Unauthorized"})

server/djangoproj/settings.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
# SECURITY WARNING: don't run with debug turned on in production!
2929
DEBUG = True
3030

31-
ALLOWED_HOSTS = ['localhost',
32-
'https://rundhmo-8000.theiadockernext-1-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai']
31+
ALLOWED_HOSTS = [
32+
'localhost',
33+
'https://rundhmo-8000.theiadockernext-1-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai']
3334
CSRF_TRUSTED_ORIGINS = [
3435
'https://rundhmo-8000.theiadockernext-1-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai']
3536

@@ -64,8 +65,8 @@
6465
{
6566
'BACKEND': 'django.template.backends.django.DjangoTemplates',
6667
'DIRS': [os.path.join(BASE_DIR, 'frontend/static'),
67-
os.path.join(BASE_DIR, 'frontend/build'),
68-
os.path.join(BASE_DIR, 'frontend/build/static'),],
68+
os.path.join(BASE_DIR, 'frontend/build'),
69+
os.path.join(BASE_DIR, 'frontend/build/static'),],
6970
'APP_DIRS': True,
7071
'OPTIONS': {
7172
'context_processors': [
@@ -139,5 +140,5 @@
139140
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
140141

141142
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'frontend/static'),
142-
os.path.join(BASE_DIR, 'frontend/build'),
143-
os.path.join(BASE_DIR, 'frontend/build/static'),]
143+
os.path.join(BASE_DIR, 'frontend/build'),
144+
os.path.join(BASE_DIR, 'frontend/build/static'),]

server/djangoproj/urls.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
path('login/', TemplateView.as_view(template_name="index.html")),
2929
path('register/', TemplateView.as_view(template_name="index.html")),
3030
path('dealers/', TemplateView.as_view(template_name="index.html")),
31-
path('dealer/<int:dealer_id>',
32-
TemplateView.as_view(template_name="index.html")),
33-
path('postreview/<int:dealer_id>',
34-
TemplateView.as_view(template_name="index.html")),
31+
path(
32+
'dealer/<int:dealer_id>',
33+
TemplateView.as_view(template_name="index.html")
34+
),
35+
path(
36+
'postreview/<int:dealer_id>',
37+
TemplateView.as_view(template_name="index.html")
38+
),
3539
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

0 commit comments

Comments
 (0)