Permalink
Browse files

Added in message system.

  • Loading branch information...
1 parent 188c40a commit 20002afd313c5f4acbb9f502bf50d82f6a9b85c4 @overshard committed May 1, 2012
@@ -29,6 +29,30 @@ body {
text-decoration: underline;
}
+.messages {
+ list-style-type: none;
+ top: 50px;
+ right: 10px;
+ position: absolute;
+ z-index: 200;
+}
+
+ .messages li {
+ margin: 10px 0;
+ padding: 18px 28px;
+ border: 1px solid #ccc;
+ font-size: 16px
+ }
+
+ .messages li:hover {
+ -webkit-transform: scale(1.1);
+ -moz-transform: scale(1.1);
+ -ms-transform: scale(1.1);
+ -o-transform: scale(1.1);
+ transform: scale(1.1);
+ cursor: pointer;
+ }
+
#loader {
margin-top: 70px;
text-align: center;
@@ -38,6 +62,7 @@ body {
top: 70px;
position: absolute;
background: #eee;
+ z-index: 100;
}
.pin {
@@ -0,0 +1,12 @@
+$(document).ready(function() {
+ var delayTime = 3000,
+ alerts = $('.alert');
+
+ delayTime = delayTime + (alerts.length * 250);
+
+ alerts.each(function() {
+ $(this).delay(delayTime).fadeOut('slow');
+ delayTime -= 250;
+ console.log(delayTime);
+ });
+});
@@ -34,6 +34,14 @@
</div>
</div>
+ {% if messages %}
+ <ul class="messages">
+ {% for message in messages %}
+ <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+
{% block yield %}{% endblock %}
{% new_pin %}
@@ -53,5 +61,6 @@
{% endif %}
<script src="/static/core/js/pinry.js"></script>
+ <script src="/static/core/js/messages.js"></script>
</body>
</html>
View
@@ -4,6 +4,7 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout
from django.contrib.auth.forms import UserCreationForm
+from django.contrib import messages
def home(request):
@@ -14,6 +15,7 @@ def register(request):
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
+ messages.success(request, 'Thank you for registering, you can now login.')
return HttpResponseRedirect(reverse('core:login'))
else:
form = UserCreationForm()
@@ -23,5 +25,5 @@ def register(request):
@login_required
def logout_user(request):
logout(request)
+ messages.success(request, 'You have successfully logged out.')
return HttpResponseRedirect(reverse('core:home'))
-
View
@@ -1,6 +1,7 @@
from django.template.response import TemplateResponse
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
+from django.contrib import messages
from .models import Pin
from .forms import PinForm
@@ -15,7 +16,10 @@ def new_pin(request):
form = PinForm(request.POST)
if form.is_valid():
form.save()
+ messages.success(request, 'New pin successfully added.')
return HttpResponseRedirect(reverse('pins:recent-pins'))
+ else:
+ messages.error(request, 'Pin did not pass validation!')
else:
form = PinForm()
context = {
@@ -1,4 +1,5 @@
import os
+from django.contrib.messages import constants as messages
SITE_ROOT = os.path.join(os.path.realpath(os.path.dirname(__file__)), '../../')
@@ -42,6 +43,12 @@
WSGI_APPLICATION = 'pinry.wsgi.application'
LOGIN_REDIRECT_URL = '/'
INTERNAL_IPS = ['127.0.0.1']
+MESSAGE_TAGS = {
+ messages.WARNING: 'alert',
+ messages.ERROR: 'alert alert-error',
+ messages.SUCCESS: 'alert alert-success',
+ messages.INFO: 'alert alert-info',
+}
INSTALLED_APPS = (
'django.contrib.auth',

0 comments on commit 20002af

Please sign in to comment.