Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion data/ShoeExpert/ShoeExpert/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
path('join/', app1_views.join),
path('login/', app1_views.user_login),
path('logout/', app1_views.user_logout),
path('blog/', app1_views.blog)
path('blog/', app1_views.blog),
path('filter2/', app1_views.filter2),
path('filter/<str:userShoe>', app1_views.filter)
]

for url_path in Url_Paths:
Expand Down
21 changes: 21 additions & 0 deletions data/ShoeExpert/app1/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,24 @@ class Meta():
class LoginForm(forms.Form):
username = forms.CharField()
password = forms.CharField(widget=forms.PasswordInput())

SHOE_CHOICES= [
('Running', 'Running'),
('Basketball', 'Basketball'),
('Approach', 'Approach'),
('Climbing', 'Climbing'),
('Crossfit', 'Crossfit'),
('Cycling', 'Cycling'),
('Football', 'Football'),
]

#CUSHIONING_CHOICES= [
# ('All', 'All'),
# ('Plush', 'Plush'),
# ('Firm', 'Firm'),
# ('Balanced', 'Balanced'),
# ]

class FilterForm(forms.Form):
Shoe = forms.CharField(widget=forms.Select(choices=SHOE_CHOICES))
# Cushioning = forms.CharField(widget=forms.Select(choices=CUSHIONING_CHOICES))
23 changes: 23 additions & 0 deletions data/ShoeExpert/app1/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
from django.test import TestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

service = ChromeService(executable_path=ChromeDriverManager().install())

driver = webdriver.Chrome(service=service)

# Create your tests here.

class LoginFormTest(testCase):
def testform(self):
selenium.get('http://127.0.0.1:8000/')
username=selenium.find_element_by_id('username')
password=selenium.find_element_by_id('password')

submit = selenium.find_element_by_id('submit_button')

username.send_keys('docker')
password.send_keys('docker')

submit.send_keys(Keys.RETURN)

assert 'docker' in selenium.page_source

driver.quit();
62 changes: 61 additions & 1 deletion data/ShoeExpert/app1/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aggregate import Url_Paths
from app1.forms import JoinForm, LoginForm

from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
Expand Down Expand Up @@ -78,10 +78,13 @@ def home(request):
@login_required(login_url='/login/')
def generic_shoe(request, url_path):
page_sizes = [5, 10, 15, 20, 30, 40, 50]
brands = ['All', 'Adidas', 'Nike', 'Aky']
brands_per_page = request.GET.get('brands_per_page', brands[0])
shoes_per_page = int(request.GET.get('shoes_per_page', page_sizes[0]))
queryset = globals()[url_path.name.capitalize()].objects.all().order_by('shoe_name')
paginator = Paginator(queryset, shoes_per_page)
page = request.GET.get('page')
brand = request.GET.get('brand')
shoes = paginator.get_page(page)
headers = []
fields = []
Expand Down Expand Up @@ -111,3 +114,60 @@ def about(request):
@login_required(login_url='/login/')
def blog(request):
return render(request, 'app1/blog.html')


@login_required(login_url='/login/')
def filter3(request, url_path):
page_sizes = [5, 10, 15, 20, 30, 40, 50]
brands = [All, Adidas, Nike, Aky]
brands_per_page = request.GET.get('brands_per_page', brands[0])
shoes_per_page = int(request.GET.get('shoes_per_page', page_sizes[10]))
queryset = globals()[url_path.name.capitalize()].objects.all().order_by('shoe_name')
paginator = Paginator(queryset, shoes_per_page, brands_per_page)
page = request.GET.get('page')
shoes = paginator.get_page(page)
headers = []
fields = []
for column in url_path.get_django_available_columns():
headers.append({
'has_modal': column.has_modal(),
'modal_body': column.get_modal_body(),
'modal_title': url_path.get_column_name(column, display_units = False),
'modal_id': url_path.get_column_name(column, attribute = True),
'column_title': url_path.get_column_name(column)
})
fields.append(url_path.get_column_name(column, attribute = True))
return render(request, 'app1/filter3.html', {
'shoes': shoes,
'headers': headers,
'fields': fields,
'shoes_per_page': shoes_per_page,
'page_sizes': page_sizes,
'title': url_path.name.replace('_', ' ').title()
})

#@login_required(login_url='/login/')
def filter(request, userShoe):
context_list = []
for url_path in Url_Paths:
tmp_dict = {}
tmp_dict['shoes'] = globals()[url_path.name.capitalize()].objects.all().order_by('?')[:3]
tmp_dict['title'] = url_path.name.replace('_', ' ').title()
tmp_dict['redirect'] = url_path.name.lower()
tmp_dict['headers'] = []
tmp_dict['fields'] = []
for column in url_path.get_django_available_columns():
tmp_dict['headers'].append(url_path.get_column_name(column))
tmp_dict['fields'].append(url_path.get_column_name(column, attribute = True))
context_list.append(tmp_dict)
return render(request, 'app1/filter.html', { 'context_list': context_list })

@login_required(login_url='/login/')
def filter2(request):
if (request.method == "POST"):
filter_form = FilterForm(request.POST)
if filter_form.is_valid():
userShoe = filter_form.cleaned_data["Shoe"]
return redirect(filter, userShoe)
return render(request, 'app1/filter2.html', {'filter_form': FilterForm})

2 changes: 1 addition & 1 deletion data/ShoeExpert/templates/app1/blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<body>
<div class="container">
<h1> Test about </h1>
<h1> Blog Page </h1>
</div>
</body>

Expand Down
47 changes: 47 additions & 0 deletions data/ShoeExpert/templates/app1/filter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

{% load getattribute %}
<html>

{% include "app1/head.html" %}

<body>
<div class="container-fluid" style="height: 90%; overflow-y: scroll;">

{% for shoe_dict in context_list %}
<div class="card mb-3" style="background-color: rgba(150, 165, 210, 0.8);">
<div class="card-body">
<div class="card-title">
<a class="btn btn-outline-dark btn-lg" href="/{{ shoe_dict.redirect }}"> {{ shoe_dict.title }} </a>
</div>
<div class="table-responsive">
<table class="table table-sm">
<thead>
<tr>
<th scope="col">Shoe Name</th>
{% for header in shoe_dict.headers %}
<th scope="col">{{header}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for value in shoe_dict.shoes %}
<tr>
<td>{{value.shoe_name}}</td>
{% for field in shoe_dict.fields %}
<td>{{ value|getattribute:field }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endfor %}

</div>
</body>

</html>


24 changes: 24 additions & 0 deletions data/ShoeExpert/templates/app1/filter2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

<html>

{% include "app1/head.html" %}

<body>
<div class="container">
<h1>Filter</h1>
<form method="POST">
{% csrf_token %}
<table>
{{ filter_form.as_table }}
<tr>
<td>
<input type="submit" class="btn btn-primary" value="Search" />
</td>
</tr>
</table>
</form>
</div>
</body>

</html>

129 changes: 129 additions & 0 deletions data/ShoeExpert/templates/app1/filter3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{% load getattribute %}
<html>

{% include "app1/head.html" %}

<body>
<div class="container-fluid" style="height: 90%; overflow-y: scroll;">
<div class="card" style="background-color: rgba(150, 165, 210, 0.8);">
<div class="card-body">

<form id="page_size_form" class="float-right" method="get">
<label for="id_page_size">shoes per page:</label>
<select id="id_page_size" name="shoes_per_page" class="form-control form-control-sm"
onchange="this.form.submit()">
{% for size in page_sizes %}
{% if size == shoes_per_page %}
<option value="{{ size }}" selected>{{ size }}</option>
{% else %}
<option value="{{ size }}">{{ size }}</option>
{% endif %}
{% endfor %}
</select>
</form>

<form id="brand_form" class="float-right" method="get">
<label for="id_brand">brand:</label>
<select id="id_brand" name="brand" class="form-control form-control-sm"
onchange="this.form.submit()">
{% for brand in userBrand %}
{% if brand == userBrand %}
<option value="{{ brand }}" selected>{{ brand }}</option>
{% else %}
<option value="{{ brand }}">{{ brand }}</option>
{% endif %}
{% endfor %}
</select>
</form>

<h1 class="card-title"> {{title}} </h1>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">Shoe Name</th>
{% for header in headers %}
<th scope="col">
{% if header.has_modal %}
{% include "app1/modal.html" with data=header %}
{% else %}
{{ header.column_title }}
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for value in shoes %}
<tr>
<td>{{value.shoe_name}}</td>
{% for field in fields %}
<td>{{ value|getattribute:field }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>

<!-- Add Bootstrap pagination links -->
<div class="d-flex justify-content-center mt-4">
<nav>
<ul class="pagination">
{% if shoes.has_previous %}
<li class="page-item">
<a class="btn btn-outline-dark" href="?page=1&amp;shoes_per_page={{ shoes_per_page }}">&laquo; first</a>
</li>
<li class="page-item">
<a class="btn btn-outline-dark"
href="?page={{ shoes.previous_page_number }}&amp;shoes_per_page={{ shoes_per_page }}">previous</a>
</li>
{% else %}
<li class="page-item disabled">
<span class="btn btn-outline-dark disabled" aria-disabled="true">&laquo; first</span>
</li>
<li class="page-item disabled">
<span class="btn btn-outline-dark disabled" aria-disabled="true">previous</span>
</li>
{% endif %}

{% for i in shoes.paginator.page_range %}
{% if i == shoes.number %}
<li class="page-item active">
<span class="btn btn-outline-dark active" aria-pressed="true">{{ i }} <span
class="sr-only">(current)</span></span>
</li>
{% elif i > shoes.number|add:-3 and i < shoes.number|add:3 %} <li class="page-item">
<a class="btn btn-outline-dark" href="?page={{ i }}&amp;shoes_per_page={{ shoes_per_page }}">{{ i }}</a>
</li>
{% endif %}
{% endfor %}

{% if shoes.has_next %}
<li class="page-item">
<a class="btn btn-outline-dark"
href="?page={{ shoes.next_page_number }}&amp;shoes_per_page={{ shoes_per_page }}">next</a>
</li>
<li class="page-item">
<a class="btn btn-outline-dark"
href="?page={{ shoes.paginator.num_pages }}&amp;shoes_per_page={{ shoes_per_page }}">last
&raquo;</a>
</li>
{% else %}
<li class="page-item disabled">
<span class="btn btn-outline-dark disabled" aria-disabled="true">next</span>
</li>
<li class="page-item disabled">
<span class="btn btn-outline-dark disabled" aria-disabled="true">last &raquo;</span>
</li>
{% endif %}
</ul>
</nav>
</div>

</div>
</div>
</div>
</body>

</html>
14 changes: 13 additions & 1 deletion data/ShoeExpert/templates/app1/generic_shoe.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@
{% endfor %}
</select>
</form>

</form>
<h1 class="card-title"> {{title}} </h1>
<form id="brand_form" class="float-right" method="get">
<label for="id_brand">Filter by Brand:</label>
<select id="id_brand" name="brands" class="form-control form-control-sm"
onchange="this.form.submit()">
{% for brand in brands %}
{% if brand == brands_per_page %}
<option value="{{ brand }}" selected>{{ brand }}</option>
{% else %}
<option value="{{ brand }}">{{ brand }}</option>
{% endif %}
{% endfor %}
</select>
<div class="table-responsive">
<table class="table">
<thead>
Expand Down
5 changes: 4 additions & 1 deletion data/ShoeExpert/templates/app1/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
<a class="nav-link" href="/about"> About </a>

</li>
{%if user.is_authenticated%}
<li class="nav-item">
<a class="nav-link" href="/blog"> Blog </a>
</li>
{%if user.is_authenticated%}
<li class="nav-item">
<a class="nav-link" href="/filter2"> Filter </a>
</li>
<li class="nav-item">
<a class="nav-link" href="/logout">Logout ({{user.username}})</a>
</li>
Expand Down