Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality - redirecting to home page with alert message on addPool form submission #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
30 changes: 30 additions & 0 deletions carpool/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,28 @@

<div class="page-content">

{% if messages %}
{% for message in messages %}
{% if message.tags == 'success' %}
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="close">&times;</button>
<strong>Successful Submission</strong>
<ul class="messages list-group">
<li class="{% if message.tags %} {{ message.tags }} {% endif %} list-group-item" > {{ message }} </li>
</ul>
</div>
{% elif message.tags == 'error'%}
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="close">&times;</button>
<strong>Error in Submission</strong>
<ul class="messages list-group">
<li class="{% if message.tags %} {{ message.tags }} {% endif %} list-group-item" > {{ message }} </li>
</ul>
</div>
{% endif %}
{% endfor %}
{% endif %}

<div class="last-rides">

<div class="col-md-12 col-sm-12 col-xs-12">
Expand Down Expand Up @@ -469,6 +491,14 @@ <h3><a href="#">From {{ ride.source }} to {{ ride.dest }}</a></h3>ride by <a hre
<!-- Slicknav -->
<script type="text/javascript" src="{% static 'js/jquery.slicknav.min.js' %}"></script>

<script>
$("document").ready(() => {
$(".alert").delay(5000).slideUp(200, () => {
$(this).alert('close');
});
})
</script>

</body>

</html>
7 changes: 6 additions & 1 deletion carpool/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.core.mail import EmailMessage, send_mail
from django.contrib.sites.shortcuts import get_current_site
from django.conf import settings
from django.contrib import messages
from .tokens import account_activation_token
import datetime
from django.db.models import Q
Expand Down Expand Up @@ -128,9 +129,13 @@ def addPool(request):
form = PoolForm(request.POST, initial={'paid': False, 'user': request.user})
if form.is_valid():
form.save()
messages.success(request, 'Your Ride has been successfully added.')
else:
messages.error(request,'ERROR: Invalid Form')
return redirect('dashboard');
else:
form = PoolForm(initial={'paid': False, 'user': request.user})
return render(request, 'add.html', {'form': form})
return render(request, 'add.html', {'form': form})
else:
return redirect('log')

Expand Down