-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Rides db, rrides view, routes db, routes view and mapping
- Loading branch information
Showing
12 changed files
with
363 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,117 @@ | ||
from http.client import HTTPResponse | ||
from django.shortcuts import render,redirect | ||
from numpy import dtype | ||
import requests | ||
import json | ||
from django.contrib.auth import login, authenticate | ||
from django.contrib import messages | ||
from django.contrib.auth.forms import UserCreationForm | ||
|
||
from publish.forms import CreateNewRide | ||
from publish.forms import RideForm | ||
from user.views import userDB, index | ||
from utils import get_client | ||
# from django.http import HttpResponse | ||
|
||
# Create your views here. | ||
# from django.http import HttpResponse | ||
client = get_client() | ||
db = client.SEProject | ||
ridesDB = db.rides | ||
routesDB = db.routes | ||
|
||
def publish_index(request): | ||
return render(request, 'publish/publish.html') | ||
|
||
def route(request): | ||
return render(request, 'publish/route.html') | ||
|
||
def createNewRide(request): | ||
if request.method == "POST": | ||
form = CreateNewRide(request.POST) | ||
if form.is_valid(): | ||
userObj = { | ||
"destination": form.cleaned_data["destination"], | ||
"rideDate": form.cleaned_data["rideDate"] | ||
if not request.session.has_key('username'): | ||
request.session['alert'] = "Please login to create a ride." | ||
return redirect('index') | ||
return render(request, 'publish/publish.html', {"username": request.session['username']}) | ||
|
||
def display_ride(request): | ||
ride = request.session['ride'] | ||
ride_id = ride['_id'] | ||
routes = get_routes(ride) | ||
ride = ridesDB.find_one({'_id': ride['_id']}) | ||
context = { | ||
"username": request.session['username'], | ||
"ride": ride, | ||
"routes": routes | ||
} | ||
return render(request, 'publish/route.html', context) | ||
|
||
def get_routes(ride): | ||
routes = [] | ||
if 'routes' not in ride: | ||
return None | ||
route_ids = ride['routes'] | ||
for route_id in route_ids: | ||
route = routesDB.find_one({'_id': route_id}) | ||
route['id'] = route.pop('_id') | ||
routes.append(route) | ||
return routes | ||
|
||
def create_ride(request): | ||
if request.method == 'POST': | ||
ride = { | ||
"_id": | ||
request.POST.get('name')+"_"+request.POST.get('destination') | ||
+"_"+request.POST.get("date")+"_"+ | ||
request.POST.get("hour")+"_"+ | ||
request.POST.get("minute")+"_"+ | ||
request.POST.get("ampm") | ||
, | ||
"name": request.POST.get('name'), | ||
"destination": request.POST.get('destination'), | ||
"date": request.POST.get("date"), | ||
"hour": request.POST.get("hour"), | ||
"minute": request.POST.get("minute"), | ||
"ampm": request.POST.get("ampm") | ||
} | ||
userDB.insert_one(userObj) | ||
request.session['destination'] = userObj["destination"] | ||
request.session['rideDate'] = userObj["rideDate"] | ||
return redirect(index, username=request.session["username"]) | ||
else: | ||
print(form.errors.as_data()) | ||
else: | ||
if request.session.has_key('username'): | ||
return index(request,request.session['username']) | ||
form = CreateNewRide() | ||
return render(request, 'user/register.html', {"form": form}) | ||
request.session['ride'] = ride | ||
if ridesDB.find_one({'_id': ride['_id']})== None: | ||
ridesDB.insert_one(ride) | ||
return redirect(display_ride) | ||
|
||
return render(request, 'publish/publish.html', {"username": request.session['username']}) | ||
|
||
def add_route(request): | ||
if request.method == 'POST': | ||
|
||
ride = request.POST.get('ride') | ||
ride = ride.replace("\'", "\"") | ||
ride = json.loads(ride) | ||
ride_id = ride['_id'] | ||
ride = ridesDB.find_one({'_id': ride['_id']}) | ||
route = { | ||
"_id": str(ride_id) | ||
+"_"+request.POST.get('type') | ||
+"_"+request.POST.get('spoint') | ||
+"_"+request.POST.get("hour") | ||
+"_"+request.POST.get("minute") | ||
+"_"+request.POST.get("duration") | ||
+"_"+request.POST.get("details") | ||
+"_"+request.POST.get("ampm"), | ||
|
||
"type": request.POST.get('type'), | ||
"spoint": request.POST.get('spoint'), | ||
"hour": request.POST.get("hour"), | ||
"minute": request.POST.get("minute"), | ||
"duration": request.POST.get("duration"), | ||
"details": request.POST.get("details"), | ||
"ampm": request.POST.get("ampm"), | ||
"users": [request.session['username']] | ||
} | ||
request.session["route"] = route | ||
request.session["ride"] = ride | ||
#check if route is unique | ||
if routesDB.find_one({'_id': route["_id"]})== None: | ||
routesDB.insert_one(route) | ||
if 'routes' not in ride: | ||
ridesDB.update_one({"_id": ride_id}, {"$set": {"routes": [route['_id']]}}) | ||
else: | ||
ride['routes'].append(route['_id']) | ||
ridesDB.update_one({"_id": ride_id}, {"$set": {"routes": ride['routes']}}) | ||
return redirect(display_ride) | ||
|
||
return render(request, 'publish/publish.html', {"username": request.session['username']}) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,11 @@ | |
|
||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous"> | ||
</head> | ||
<script> | ||
{% if alertmsg %} | ||
$(document).ready(function() { alert({{alertmsg}});}); | ||
{% endif %} | ||
</script> | ||
<style> | ||
.btn-blue{ | ||
background-color: #5b3be9 !important; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,62 @@ | ||
<!DOCTYPE html>{% load static %} | ||
<html lang="en"> | ||
|
||
<head> | ||
|
||
|
||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<head><meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<title>New PackTravel</title> | ||
|
||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous"> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> | ||
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet"> | ||
|
||
</head> | ||
|
||
<body style="background-color: #3A3B3C;"> | ||
|
||
{% include 'nav.html' %} | ||
|
||
|
||
|
||
<div class="card mx-auto shadow-2-strong bg-white rounded" style="width: 60%; margin: 50px; padding: 50px;"> | ||
<h3>Create a New Ride</h3> | ||
<h3>New Ride</h3> | ||
<hr> | ||
<form method="POST" class="form-group"> | ||
<form action="/create_ride/" method="POST" class="form-group"> | ||
{% csrf_token %} | ||
<div class="row"> | ||
<div class="col-sm-6"> | ||
<div class="form-group"> | ||
<span class="form-label">Destination</span> | ||
<input class="form-control" type="text" placeholder="Enter your start destination"> | ||
<span class="form-label">Ride Name</span> | ||
<input name="name" required class="form-control" type="text" placeholder="Enter a name for the ride"> | ||
</div> | ||
</div> | ||
<br> | ||
</div> | ||
<br> | ||
<div class="row"> | ||
<div class="col-sm-5"> | ||
<div class="col-sm-6"> | ||
<div class="form-group"> | ||
<span class="form-label">Ride Date</span> | ||
<input class="form-control" type="date" required placeholder="Enter ride date"> | ||
<span class="form-label">Destination</span> | ||
<input name="destination" required class="form-control" type="text" placeholder="Enter your start destination"> | ||
</div> | ||
</div> | ||
<br> | ||
</div> | ||
<br> | ||
<div class="form-group"> | ||
<span class="form-label">Ride Date</span> | ||
<input class="form-control" name="date" type="date" required placeholder="Enter ride date"> | ||
</div> | ||
<br> | ||
Enter the Time to Reach | ||
<div class="row" | ||
<div class="col-sm-7"> | ||
<div class="row"> | ||
Enter the Time to Reach | ||
|
||
<div class="col-sm-4"> | ||
<div class="form-group"> | ||
<span class="form-label">Hour</span> | ||
<select class="form-control"> | ||
<select name="hour" required class="form-control"> | ||
<option>1</option> | ||
<option>2</option> | ||
<option>3</option> | ||
|
@@ -67,7 +76,7 @@ <h3>Create a New Ride</h3> | |
<div class="col-sm-4"> | ||
<div class="form-group"> | ||
<span class="form-label">Min</span> | ||
<select class="form-control"> | ||
<select name="minute" required class="form-control"> | ||
<option>00</option> | ||
<option>05</option> | ||
<option>10</option> | ||
|
@@ -87,20 +96,25 @@ <h3>Create a New Ride</h3> | |
<div class="col-sm-4"> | ||
<div class="form-group"> | ||
<span class="form-label">AM/PM</span> | ||
<select class="form-control"> | ||
<select name="ampm" class="form-control"> | ||
<option>AM</option> | ||
<option>PM</option> | ||
</select> | ||
<span class="select-arrow"></span> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
<br><br> | ||
<div class="form-btn"> | ||
<button style="float: right;" class="btn btn-info btn-lg submit-btn">Next: Add a route</button> | ||
<br> | ||
</div> | ||
|
||
|
||
</div> | ||
<br><br> | ||
<div class="form-btn"> | ||
<button class="btn btn-dark submit-btn">CREATE</button> | ||
</div> | ||
</form> | ||
<!-- <form method="POST" class="form-group"> | ||
{% csrf_token %} | ||
|
@@ -117,6 +131,7 @@ <h3>Create a New Ride</h3> | |
<button type="submit" class="btn btn-dark" >Login</button> | ||
</form> --> | ||
</div> | ||
|
||
|
||
|
||
</body> | ||
|
Oops, something went wrong.