diff --git a/server/db.sqlite3 b/server/db.sqlite3 new file mode 100644 index 0000000000..3d1c9c07a6 Binary files /dev/null and b/server/db.sqlite3 differ diff --git a/server/djangoapp/models.py b/server/djangoapp/models.py index 27d96f4eff..961dc9af7c 100644 --- a/server/djangoapp/models.py +++ b/server/djangoapp/models.py @@ -9,6 +9,13 @@ # - Description # - Any other fields you would like to include in car make model # - __str__ method to print a car make object +class CarMake(models.Model): + name = models.CharField(null=False, max_length=30, default='Name') + description = models.CharField(null=False, max_length=30, default='Description') + + # Create a toString method for object string representation + def __str__(self): + return self.name + " " + self.description # Create a Car Model model `class CarModel(models.Model):`: @@ -19,6 +26,31 @@ # - Year (DateField) # - Any other fields you would like to include in car model # - __str__ method to print a car make object +class CarModel(models.Model): + SEDAN = 'Sedan' + SUV = 'SUV' + WAGON = 'WAGON' + TYPE_CHOICES = [ + (SEDAN, 'Sedan'), + (SUV, 'SUV'), + (WAGON, 'WAGON') + ] + dealer_id = models.IntegerField() + name = models.CharField(null=False, max_length=100, default='name') + description = models.CharField(max_length=500) + type = models.CharField( + null=False, + max_length=20, + choices=TYPE_CHOICES, + default=SEDAN + ) + year = models.IntegerField() + carMade = models.ManyToManyField(CarMake) + + # Create a toString method for object string representation + def __str__(self): + return "Name: " + self.name + "," + \ + "Description: " + self.type # Create a plain Python class `CarDealer` to hold dealer data diff --git a/server/djangoapp/templates/djangoapp/about.html b/server/djangoapp/templates/djangoapp/about.html new file mode 100644 index 0000000000..f78e6cd8d1 --- /dev/null +++ b/server/djangoapp/templates/djangoapp/about.html @@ -0,0 +1,87 @@ + + + + + Dealership Review + + + + + + + + + + + + + + + +

+ Welcome to Best Cars dealership, home to the best cars in North America. We sell domestic and imported cars at reasonable prices. +

+ + + + diff --git a/server/djangoapp/templates/djangoapp/contact.html b/server/djangoapp/templates/djangoapp/contact.html new file mode 100644 index 0000000000..268af6e3f6 --- /dev/null +++ b/server/djangoapp/templates/djangoapp/contact.html @@ -0,0 +1,139 @@ + + + + + Dealership Review + + + + + + + + + + + + + + + +
+
+
+
+ +
+
+
+
+ image +

Contact Us

+

We would love to hear from you !

+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+
+ +
+ +
+
+
+ + + + diff --git a/server/djangoapp/templates/djangoapp/custom_template.html b/server/djangoapp/templates/djangoapp/custom_template.html new file mode 100644 index 0000000000..9e64f279ae --- /dev/null +++ b/server/djangoapp/templates/djangoapp/custom_template.html @@ -0,0 +1,104 @@ + + + + + Dealership Review + + + + + + + + + + + + + + + +
+
+
+
+
Special title treatment
+

With supporting text below as a natural lead-in to additional content.

+ Go somewhere +
+
+
+
+
+
+
Special title treatment
+

With supporting text below as a natural lead-in to additional content.

+ Go somewhere +
+
+
+
+ + + + diff --git a/server/djangoapp/templates/djangoapp/dealer_details.html b/server/djangoapp/templates/djangoapp/dealer_details.html index 25bd9a223d..6be3523825 100644 --- a/server/djangoapp/templates/djangoapp/dealer_details.html +++ b/server/djangoapp/templates/djangoapp/dealer_details.html @@ -10,6 +10,67 @@ + diff --git a/server/djangoapp/templates/djangoapp/index.html b/server/djangoapp/templates/djangoapp/index.html index 1a9ee6e39a..7ada791ed7 100644 --- a/server/djangoapp/templates/djangoapp/index.html +++ b/server/djangoapp/templates/djangoapp/index.html @@ -14,9 +14,68 @@ - - This is the index page of your Django app! + diff --git a/server/djangoapp/templates/djangoapp/registration.html b/server/djangoapp/templates/djangoapp/registration.html index ae11ea4b71..e9e9306cfe 100644 --- a/server/djangoapp/templates/djangoapp/registration.html +++ b/server/djangoapp/templates/djangoapp/registration.html @@ -4,8 +4,109 @@ {% load static %} + + + + + + + + +
+
+
+
+ +
+ {% csrf_token %} +

Sign Up

+

Please fill in this form to create an account!

+
+
+
+
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+
+
+ \ No newline at end of file diff --git a/server/djangoapp/templates/djangoapp/user_login.html b/server/djangoapp/templates/djangoapp/user_login.html new file mode 100644 index 0000000000..f877965710 --- /dev/null +++ b/server/djangoapp/templates/djangoapp/user_login.html @@ -0,0 +1,119 @@ + + + + + Dealership Review + + + + + + + + + + + + + + +
+
+
+

Login Form

+
Made with bootstrap
+
+ +
+ + {% csrf_token %} +
+ profile +
+ +
+ +
+
+ +
+
+ +
+ {% if message %} +
+ {{ message }} +
+ {% endif %} +
+
+ +
+
+
+ + + + diff --git a/server/djangoapp/urls.py b/server/djangoapp/urls.py index 37b1c89d01..05c4a3cf0f 100644 --- a/server/djangoapp/urls.py +++ b/server/djangoapp/urls.py @@ -10,19 +10,25 @@ # name the URL # path for about view + path(route='about', view=views.about, name='about'), # path for contact us view + path(route='contact', view=views.contact, name='contact'), # path for registration + path('registration/', views.registration_request, name='registration'), # path for login + path('login/', views.login_request, name='login'), # path for logout + path('logout/', views.logout_request, name='logout'), path(route='', view=views.get_dealerships, name='index'), # path for dealer reviews view # path for add a review view + path(route='profile', view=views.custom_profile, name='profile'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/server/djangoapp/views.py b/server/djangoapp/views.py index 61cc664da0..a704fb1e93 100644 --- a/server/djangoapp/views.py +++ b/server/djangoapp/views.py @@ -15,27 +15,90 @@ # Create your views here. - +def custom_profile(request): + context = {} + if request.method == "GET": + return render(request, 'djangoapp/custom_template.html', context) # Create an `about` view to render a static about page # def about(request): # ... +def about(request): + context = {} + if request.method == "GET": + return render(request, 'djangoapp/about.html', context) # Create a `contact` view to return a static contact page #def contact(request): +def contact(request): + context = {} + if request.method == "GET": + return render(request, 'djangoapp/contact.html', context) # Create a `login_request` view to handle sign in request # def login_request(request): -# ... +def login_request(request): + context = {} + # Handles POST request + if request.method == "POST": + # Get username and password from request.POST dictionary + username = request.POST['username'] + password = request.POST['psw'] + # Try to check if provide credential can be authenticated + user = authenticate(username=username, password=password) + if user is not None: + # If user is valid, call login method to login current user + login(request, user) + return redirect('djangoapp:index') + else: + # If not, return to login page again + return render(request, 'djangoapp/user_login.html', context) + else: + return render(request, 'djangoapp/user_login.html', context) # Create a `logout_request` view to handle sign out request # def logout_request(request): -# ... +def logout_request(request): + # Get the user object based on session id in request + print("Log out the user `{}`".format(request.user.username)) + # Logout user in the request + logout(request) + # Redirect user back to course list view + return redirect('djangoapp:index') # Create a `registration_request` view to handle sign up request # def registration_request(request): -# ... +def registration_request(request): + context = {} + # If it is a GET request, just render the registration page + if request.method == 'GET': + return render(request, 'djangoapp/registration.html', context) + # If it is a POST request + elif request.method == 'POST': + # Get user information from request.POST + username = request.POST['username'] + password = request.POST['psw'] + first_name = request.POST['firstname'] + last_name = request.POST['lastname'] + user_exist = False + try: + # Check if user already exists + User.objects.get(username=username) + user_exist = True + except: + # If not, simply log this is a new user + logger.debug("{} is new user".format(username)) + # If it is a new user + if not user_exist: + # Create user in auth_user table + user = User.objects.create_user(username=username, first_name=first_name, last_name=last_name, + password=password) + # Login the user and redirect to course list page + login(request, user) + return redirect("djangoapp:index") + else: + return render(request, 'djangoapp/registration.html', context) # Update the `get_dealerships` view to render the index page with a list of dealerships def get_dealerships(request): diff --git a/server/requirements.txt b/server/requirements.txt index 2851cca128..a3e766f47a 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -1,6 +1,6 @@ requests Django==3.1.3 -Pillow==8.0.1 +Pillow==10.1.0 gunicorn==20.1.0 ibm-cloud-sdk-core==3.10.0 ibm-watson==5.2.2