Commit b5df5582 authored by BERJON Matthieu's avatar BERJON Matthieu
Browse files

Update of the webapp list



I updated the webapp list by:

- Creating a paginated url to apps/
- Create a class based view
- Create a paginated template with cards

There are several things that need to be corrected such as the
pagination if many pages are created and card images.
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <matthieu.berjon@inria.fr>
parent ab5e1af9
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.conf.urls import url, include
# from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
url(r'^$', views.index, name="poc_home"),
url(r'^users/', views.user),
url(r'^webapps/', views.list_webapps, name='list_webapps'),
url(
r'^login/$',
auth_views.login,
{'template_name': 'login.html'},
name='login'),
url(r'^logout/$', auth_views.logout, name='logout'),
url('^signup/$', views.SignUp.as_view(), name='signup'),
url(r'^webapps/$', views.list_webapps, name='list_webapps'),
url(r'^apps/$', views.WebappList.as_view(), name='webapp_list'),
url('^auth/', include('django.contrib.auth.urls')),
# Registration
url(r'^auth/signup/$', views.SignUp.as_view(), name='signup'),
]
from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import render
from django.urls import reverse_lazy
from django.views import generic
from django.views.generic import CreateView, ListView
from django.contrib.auth.models import User
from .models import Webapp
......@@ -22,17 +22,14 @@ def list_webapps(request):
return render(request, "webapps.html", locals())
# def signup(request):
# if request.method == 'POST':
# form = UserCreationForm(request.POST)
# if form.is_valid():
# form.save()
# return redirect('poc_home')
# else:
# form = UserCreationForm()
#
# return render(request, 'signup.html', {'form': form})
class SignUp(generic.CreateView):
class WebappList(ListView):
model = Webapp
pattern_name = 'webapp_list'
paginate_by = 10
template_name = 'webapp_list.html'
class SignUp(CreateView):
form_class = UserCreationForm
success_url = reverse_lazy('login')
template_name = 'signup.html'
template_name = 'registration/signup.html'
......@@ -8,7 +8,7 @@
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="{% url 'list_webapps' %}"><i class="fas fa-cloud"></i> apps</a>
<a class="nav-link" href="{% url 'webapp_list' %}"><i class="fas fa-cloud"></i> apps</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fas fa-book"></i> Docs</a>
......
{% extends "base.html" %}
{% block title %}Webapps{% endblock %}
{% block content %}
<div class="row">
{% for webapp in webapp_list %}
<div class="col-sm-6">
<div class="card">
<img class="card-img-top" src="{{ webapp.logo_file_name }}" alt="{{ webapp.title }} logo">
<div class="card-body">
<h5 class="card-title">{{ webapp.title }}</h5>
<p class="card-text">
{% if webapp.description %}
{{ webapp.description|truncatechars:200 }}
{% else %}
No description available.
{% endif %}</p>
</div>
<div class="card-footer">
<small class="text-muted">{{ webapp.contact }}</small>
</div>
</div>
</div>
{% endfor %}
</div>
{% if is_paginated %}
<nav aria-label="Webapp page navigation">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">Previous</a>
</li>
{% endif %}
{% for page in page_obj.paginator.page_range %}
{% if page == page_obj.number %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">{{ page }}</a>
</li>
{% else %}
<li class="page_item"><a class="page-link" href="?page={{ page }}">{{ page }}</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}">Next</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">Next</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
{% endblock %}
{% extends "base.html" %}
{% block title %}Webapps{% endblock %}
{% block content %}
<ul>
{% for webapp in webapps %}
<li>{{ webapp.name }}</li>
{% endfor %}
</ul>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment