Skip to content

Commit

Permalink
Bus cancellation view amended to allow cancellation by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskomo committed Sep 7, 2019
1 parent 4581b5e commit c0e4b4f
Show file tree
Hide file tree
Showing 48 changed files with 328 additions and 89 deletions.
Binary file added media/default.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/profile_pics/Travel1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/profile_pics/bus6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/profile_pics/bus8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/profile_pics/gym.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/profile_pics/komo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/profile_pics/komo_qAnC8EU.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified myapp/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file modified myapp/__pycache__/views.cpython-36.pyc
Binary file not shown.
8 changes: 8 additions & 0 deletions myapp/templates/myapp/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "myapp/base.html" %}
{% block content %}
<div class="jumbotron">
<h3>
This is a simple Python Django Booking Reservation system that allows users create an account and log in, logout, search Buses, Book buses, Cancel reservation and view all Booking related information. It is still work in progress especially the UI.
</h3>
</div>
{% endblock content %}
9 changes: 5 additions & 4 deletions myapp/templates/myapp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@
</button>
<div class="collapse navbar-collapse" id="navbarToggle">
<div class="navbar-nav mr-auto">
<a class="nav-item nav-link" href="{% url 'findbus' %}">About Us</a>
<a class="nav-item nav-link" href="{% url 'about' %}">About Us</a>
<a class="nav-item nav-link" href="{% url 'findbus' %}">Find Bus</a>
<a class="nav-item nav-link" href="{% url 'seebookings' %}">See Bookings</a>
</div>
<!-- Navbar Right Side -->
<div class="navbar-nav">
{% if user.is_authenticated %}
<a class="nav-item nav-link" href="{% url 'signout' %}">Logout</a>
<a class="nav-item nav-link" href="{% url 'profile' %}">Profile</a>
<a class="nav-item nav-link" href="{% url 'logout' %}">Logout</a>
{% else %}
<a class="nav-item nav-link" href="{% url 'signin' %}">Login</a>
<a class="nav-item nav-link" href="{% url 'signup' %}">Register</a>
<a class="nav-item nav-link" href="{% url 'login' %}">Login</a>
<a class="nav-item nav-link" href="{% url 'register' %}">Register</a>
{% endif %}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion myapp/templates/myapp/findbus.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h1>Find a Bus</h1>
<button class="submit-btn">Search Bus</button>
</div>
<div class="form-btn">
<a href="{% url 'seebookings' %}">View Bookings</a>
<a href="{% url 'home' %}">View Bookings</a>
</div>
<h3 style="color: red;">{{error}}</h3>

Expand Down
33 changes: 0 additions & 33 deletions myapp/templates/myapp/signin.html

This file was deleted.

37 changes: 0 additions & 37 deletions myapp/templates/myapp/signup.html

This file was deleted.

5 changes: 2 additions & 3 deletions myapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
path('bookings', views.bookings, name="bookings"),
path('cancellings', views.cancellings, name="cancellings"),
path('seebookings', views.seebookings, name="seebookings"),
path('signup', views.signup, name="signup"),
path('signin', views.signin, name="signin"),
path('about/', views.about, name='about'),
path('success', views.success, name="success"),
path('signout', views.signout, name="signout"),
# path('signout', views.signout, name="signout"),

]
23 changes: 13 additions & 10 deletions myapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ def home(request):
if request.user.is_authenticated:
return render(request, 'myapp/base.html')
else:
return render(request, 'myapp/signin.html')
return render(request, 'users/login.html')

def about(request):
return render(request, 'myapp/about.html', {'title': 'About'})

@login_required(login_url='signin')

@login_required(login_url='login')
def findbus(request):
context = {}
if request.method == 'POST':
Expand All @@ -36,7 +39,7 @@ def findbus(request):
return render(request, 'myapp/findbus.html')


@login_required(login_url='signin')
@login_required(login_url='login')
def bookings(request):
context = {}
if request.method == 'POST':
Expand Down Expand Up @@ -73,7 +76,7 @@ def bookings(request):
return render(request, 'myapp/findbus.html')


@login_required(login_url='signin')
@login_required(login_url='login')
def cancellings(request):
context = {}
if request.method == 'POST':
Expand All @@ -96,7 +99,7 @@ def cancellings(request):
return render(request, 'myapp/findbus.html')


@login_required(login_url='signin')
@login_required(login_url='login')
def seebookings(request,new={}):
context = {}
id_r = request.user.id
Expand All @@ -120,9 +123,9 @@ def signup(request):
return render(request, 'myapp/thank.html')
else:
context["error"] = "Provide valid credentials"
return render(request, 'myapp/signup.html', context)
return render(request, 'users/registers.html', context)
else:
return render(request, 'myapp/signup.html', context)
return render(request, 'users/signup.html', context)


def signin(request):
Expand All @@ -140,17 +143,17 @@ def signin(request):
# return HttpResponseRedirect('success')
else:
context["error"] = "Provide valid credentials"
return render(request, 'myapp/signin.html', context)
return render(request, 'users/login.html', context)
else:
context["error"] = "You are not logged in"
return render(request, 'myapp/signin.html', context)
return render(request, 'users/login.html', context)


def signout(request):
context = {}
logout(request)
context['error'] = "You have been logged out"
return render(request, 'myapp/signin.html', context)
return render(request, 'users/login.html', context)


def success(request):
Expand Down
Binary file modified myproject/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file modified myproject/__pycache__/urls.cpython-36.pyc
Binary file not shown.
8 changes: 7 additions & 1 deletion myproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
'users',
'bootstrap4',
'crispy_forms',
"django_static_fontawesome",
Expand Down Expand Up @@ -132,12 +133,12 @@

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# configuring the location for media
MEDIA_URL = '/media/'
Expand All @@ -146,3 +147,8 @@

CRISPY_TEMPLATE_PACK = 'bootstrap4'

LOGIN_REDIRECT_URL = 'home'
LOGIN_URL = 'login'

# Configure Django App for Heroku.
# django_heroku.settings(locals())
10 changes: 10 additions & 0 deletions myproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@
"""
from django.urls import path,include
from django.contrib import admin
from users import views as user_views
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views

urlpatterns = [
path('admin/', admin.site.urls),
path('register/', user_views.register, name='register'),
path('profile/', user_views.profile, name='profile'),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('', include('myapp.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
29 changes: 29 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
beautifulsoup4==4.8.0
dj-database-url==0.5.0
Django==2.0.7
django-authtools==1.7.0
django-booking==0.7.2
django-bootstrap==0.2.4
django-bootstrap4==1.0.1
django-braces==1.13.0
django-countries==5.4
django-crispy-forms==1.7.2
django-fontawesome==1.0
django-heroku==0.3.1
django-hosts==3.0
django-hvad==1.8.0
django-libs==2.0.2
django-static-fontawesome==5.0.8.1
django-widget-tweaks==1.4.2
djangorestframework==3.10.3
gunicorn==19.9.0
Pillow==6.1.0
psycopg2==2.7.5
psycopg2-binary==2.8.3
python-dateutil==2.8.0
pytz==2018.5
PyYAML==5.1.2
six==1.12.0
soupsieve==1.9.3
sqlparse==0.3.0
whitenoise==3.3.1
1 change: 1 addition & 0 deletions users/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'users.apps.UsersConfig'
Binary file added users/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added users/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file added users/__pycache__/apps.cpython-36.pyc
Binary file not shown.
Binary file added users/__pycache__/choices.cpython-36.pyc
Binary file not shown.
Binary file added users/__pycache__/forms.cpython-36.pyc
Binary file not shown.
Binary file added users/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file added users/__pycache__/signals.cpython-36.pyc
Binary file not shown.
Binary file added users/__pycache__/tests.cpython-36.pyc
Binary file not shown.
Binary file added users/__pycache__/views.cpython-36.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions users/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Profile

admin.site.register(Profile)
8 changes: 8 additions & 0 deletions users/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig


class UsersConfig(AppConfig):
name = 'users'

def ready(self):
import users.signals
31 changes: 31 additions & 0 deletions users/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from .models import Profile



class UserRegisterForm(UserCreationForm):
email = forms.EmailField()


class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']


class UserUpdateForm(forms.ModelForm):
email = forms.EmailField()



class Meta:
model = User
fields = ['username', 'email',]


class ProfileUpdateForm(forms.ModelForm):

class Meta:
model = Profile
fields = ['image',]
25 changes: 25 additions & 0 deletions users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.0.7 on 2019-09-07 11:36

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.ImageField(default='default.jpg', upload_to='profile_pics')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file added users/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file added users/migrations/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
21 changes: 21 additions & 0 deletions users/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import models
from django.contrib.auth.models import User
from PIL import Image


class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default='default.jpg', upload_to='profile_pics')

def __str__(self):
return f'{self.user.username} Profile'

def save(self, *args, **kwargs):
super().save(*args, **kwargs)

img = Image.open(self.image.path)

if img.height > 300 or img.width > 300:
output_size = (300, 300)
img.thumbnail(output_size)
img.save(self.image.path)
Loading

0 comments on commit c0e4b4f

Please sign in to comment.