Permalink
Browse files

initial support for endless pagination

  • Loading branch information...
edulix committed Apr 14, 2012
1 parent 33e1579 commit 3ffd05e27f34ab3c051cb1b2e480c630541928d2
@@ -46,3 +46,4 @@ def get(self, request):
+ 'been reset, you can now <a href="%(url)s">login</a> with your '
+ 'new password') % dict(url=reverse('userena_signin')))
return redirect('/')
+
@@ -0,0 +1,53 @@
+# Copyright (C) 2012 Daniel Garcia Moreno <danigm AT wadobo DOT com>
+# Copyright (C) 2012 Eduardo Robles Elvira <edulix AT wadobo DOT com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+
+import random
+
+
+names = ['Juan', 'Antonio', 'Jose', 'Carmen', 'Isabel', 'Daniel',
+ 'David', 'Moises', 'Monica', 'Juana', 'Maria', 'Victoria']
+surnames = ['Garcia', 'Bonilla', 'Lopez', 'Perez', 'Ariza', 'Aguilar',
+ 'Moreno', 'Robles', 'Cuesta', 'Molero', 'Romero']
+locations = ['Cordoba', 'Sevilla', 'Huelva', 'Cadiz', 'Malaga',
+ 'Granada', 'Almeria', 'Jaen']
+desc = 'Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.'.split(' ')
+
+class Command(BaseCommand):
+ args = '<n>'
+ help = 'Adds n test users'
+
+ def handle(self, *args, **options):
+ try:
+ n = int(args[0])
+ except:
+ raise CommandError("You need to provide the number of users to add")
+
+
+ for i in range(n):
+ uid = i + 1
+ u = User(username='user%s' % uid, email='user%s@agoraciudadana.com' % uid, )
+ u.set_password('123')
+ u.first_name = "%s %s" % (random.choice(names), random.choice(surnames))
+ u.is_active = True
+ u.save()
+
+ p = u.get_profile()
+ p.short_description = ' '.join(random.choice(desc) for i in range(15))
+ p.biography = ' '.join(random.choice(desc) for i in range(100))
+ p.save()
@@ -0,0 +1,28 @@
+# Copyright (C) 2012 Eduardo Robles Elvira <edulix AT wadobo DOT com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+
+import random
+
+
+class Command(BaseCommand):
+ args = '<n>'
+ help = 'Remove all users'
+
+ def handle(self, *args, **options):
+ for i in User.objects.all():
+ i.delete()
@@ -47,9 +47,6 @@ class Profile(UserenaLanguageBaseProfile):
# language (among other things)
lang_code = models.CharField(_("Language Code"), max_length=10, default='')
- photo = models.ImageField(_("Avatar"), blank=True, null=True,
- upload_to=os.path.join(settings.STATIC_DOC_ROOT, "photos"))
-
email_updates = models.BooleanField(_("Receive email updates"),
default=True)
@@ -63,6 +60,17 @@ class Profile(UserenaLanguageBaseProfile):
#}
extra = JSONField(_('Extra'), null=True)
+from django.db.models.signals import post_save
+
+# definition of UserProfile from above
+# ...
+
+def create_user_profile(sender, instance, created, **kwargs):
+ if created:
+ Profile.objects.create(user=instance)
+
+post_save.connect(create_user_profile, sender=User)
+
class Agora(models.Model):
'''
Represents an Agora, formed by a group of people which can vote and delegate
@@ -1,51 +0,0 @@
-{% extends 'base.html' %}
-{% load i18n %}
-{% load crispy_forms_tags %}
-
-{% block title %}{% trans 'Log in' %}{% endblock %}
-
-
-{% block running-board-wrapper-class %}auth-board{% endblock %}
-{% block running-board %}
-
-{% block script-block %}
-<script type="text/javascript">
- $(document).ready(function() {
- $(".span3").bind("click", function(e) {
- $(".auth-highlight").removeClass("auth-highlight");
- $(this).addClass("auth-highlight");
- console.log("ergerg");
- });
- });
-</script>
-{% endblock %}
-
-<div class="row">
- <div class="span3 {% ifequal action 'login' %}auth-highlight{% endifequal %}">
- <h3>{% trans "Log in" %}</h3>
- <p>{% trans "Please log in to continue." %}</p>
- {% crispy login_form %}
- </div>
-
- <div class="span3 {% ifequal action 'register' %}auth-highlight{% endifequal %}">
- <h3>{% blocktrans %}New to {{ SITE_NAME }}?{% endblocktrans %}</h3>
- <p>{% blocktrans %}An account in {{ SITE_NAME }} is required to continue.{% endblocktrans %}</p>
- {% crispy register_form %}
- </div>
-
-
- <div class="span3 use-account">
- <h3>{% trans "Use your account in.." %}</h3>
- <p>{% trans "You can log in using your account in Twitter." %}</p>
- <div>
- <a href="{% url socialauth_begin 'twitter' %}">
- <img src="{{ STATIC_URL }}img/sign-in-with-twitter-l.png" />
- </a>
- </div>
- <strong>{% trans "Privacy" %}</strong>
- <small>{% trans "We won't give any private data to Twitter and we will not use your profile to post anything without your permission." %}</small>
- </a>
- </div>
-</div>
-
-{% endblock %}
@@ -0,0 +1,31 @@
+{% extends 'base.html' %}
+{% load i18n %}
+{% load endless %}
+
+{% block script-block %}
+ <script src="{{ STATIC_URL }}js/endless_pagination/endless.js" type="text/javascript" charset="utf-8"></script>
+ <script src="{{ STATIC_URL }}js/endless_pagination/endless_on_scroll.js" type="text/javascript" charset="utf-8"></script>
+
+ <script type="text/javascript" charset="utf-8">
+ var endless_on_scroll_margin = 300;
+ </script>
+{% endblock %}
+
+{% block running-board-wrapper-class %}auth-board{% endblock %}
+{% block running-board %}
+
+<h1>{% block subtitle %}{% endblock %}</h1>
+{% endblock %}
+
+{% block content %}
+
+{% paginate object_list %}
+{% for object in object_list %}
+ {% block object-block %}{% endblock %}
+{% endfor %}
+{% show_more %}
+
+{% endblock %}
+
+{% block footer-wrapper-class %}endless{% endblock %}
+{% block footer %} {% endblock %}
@@ -0,0 +1,36 @@
+{% extends 'agora_core/object_list.html' %}
+{% load i18n %}
+{% block title %}{% trans "User list" %}{% endblock %}
+{% block subtitle %}{% trans "User list" %}{% endblock %}
+
+
+{% block object-block %}
+
+ <!-- {% cycle "left" "right" as row %} -->
+ {% ifequal row "left" %}
+ <div class="user_list_item row-fluid row-{% if forloop.first %}first{% endif %}">
+ {% endifequal %}
+
+ <div class="span6 span6-{{ row }}">
+ <a href="{ % user-view object.username %}">
+ <div class="row-fluid">
+ <div class="span4">
+ <img src="{{ object.get_profile.get_mugshot_url }}" alt="{% trans "User mugshot" %}" />
+ </div>
+ <div class="span8">
+ <strong>{{ object.username }}</strong>
+ <p>{{ object.first_name }}</p>
+ </div>
+ </div>
+ </a>
+ </div>
+
+ {% ifequal row "right" %}
+ </div>
+ {% endifequal %}
+
+{% endblock %}
+
+{% ifequal row "left" %}
+ </div>
+{% endifequal %}
@@ -0,0 +1,36 @@
+{% load i18n %}
+{% load endless %}
+
+{% paginate object_list %}
+{% for object in object_list %}
+ <!-- {% cycle "left" "right" as row %} -->
+ {% ifequal row "left" %}
+ <div class="user_list_item row-fluid row-{% if forloop.first %}first{% endif %}">
+ {% endifequal %}
+
+ <div class="span6 span6-{{ row }}">
+ <a href="{ % user-view object.username %}">
+ <div class="row-fluid">
+ <div class="span4">
+ <img src="{{ object.get_profile.get_mugshot_url }}" alt="{% trans "User mugshot" %}" />
+ </div>
+ <div class="span8">
+ <strong>{{ object.username }}</strong>
+ <p>{{ object.first_name }}</p>
+ </div>
+ </div>
+ </a>
+ </div>
+
+ {% ifequal row "right" %}
+ </div>
+ {% endifequal %}
+
+{% endfor %}
+
+{% ifequal row "left" %}
+ </div>
+
+{% endifequal %}
+
+{% show_more %}
@@ -1,16 +0,0 @@
-{% extends "template_base.html" %}
-{% load i18n %}
-{% block title %} {% trans 'Change password' %} {% endblock %}
-
-{% block content %}
- <div class="section_3">
- <h1>{% trans 'Change password' %}</h1>
- <form action="" method="post">
- {% csrf_token %}
- <fieldset>
- {% include "main/form_snippet.html" %}
- </fieldset>
- <input class="submit" type="submit" value="{% trans 'Change password' %}"/>
- </form>
- </div>
-{% endblock %}
@@ -1,17 +0,0 @@
-{% extends "template_base.html" %}
-{% load i18n %}
-{% block title %} {% trans 'Did you forget your password?' %} {% endblock %}
-
-{% block content %}
- <div class="section_3">
- <h1>{% trans 'Did you forget your password?' %}</h1>
- <p>{% trans 'Fill the following form so that we can send you a link to your email address which will let you change your password.' %}
- <form action="" method="post">
- {% csrf_token %}
- <fieldset>
- {% include "main/form_snippet.html" %}
- </fieldset>
- <input class="submit" type="submit" value="{% trans 'Send verification email' %}"/>
- </form>
- </div>
-{% endblock %}
@@ -1,21 +0,0 @@
-{% extends "template_base.html" %}
-{% load i18n %}
-{% block title %} {% trans 'Change your password' %} {% endblock %}
-
-{% block content %}
- <div class="section_3">
- <h1>{% trans 'Change your password' %}</h1>
- {% if form %}
- <p>{% trans 'Now that we have verified your identity, you can set your new password. Try not to forget it again. In case you forget it, you can still use again the same form to reset it if you at least remember your username or email address.' %}
- <form action="" method="post">
- {% csrf_token %}
- <fieldset>
- {% include "main/form_snippet.html" %}
- </fieldset>
- <input class="submit" type="submit" value="{% trans 'Change password' %}"/>
- </form>
- {% else %}
- <p>{% trans '<strong>¡Error!</strong> This confirmation link is invalid or has expired. Check that you accessed the correct link, or try again to reset your password.' %}</p>
- {% endif %}
- </div>
-{% endblock %}
@@ -1,15 +0,0 @@
-{% load i18n %}{% url user-remember-confirm uid token as url_remember %}{% blocktrans with user.username as username %}Hi,
-
-You are receiving this email because you requested to reset your
-password for your account in {{ protocol }}://{{ site_name }}.
-If you didn't request to reset your password, you should ignore this
-message. You can change your password in the following address:
-
-{{ protocol }}://{{ domain }}{{ url_remember }}
-
-Yor username, in case you forgot it, is: {{ username }}
-
-Thanks for using our web site!
-
---
-The team of {{ site_name }}{% endblocktrans %}
@@ -14,6 +14,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf.urls.defaults import *
+from endless_pagination.views import AjaxListView
+from django.contrib.auth.models import User
+from django.utils.translation import ugettext_lazy as _
urlpatterns = patterns('',
+ url(r'^user/list$', AjaxListView.as_view(
+ queryset=User.objects.all(),
+ template_name='agora_core/user_list.html',
+ page_template='agora_core/user_list_page.html'),
+ name="object_list"
+ ),
)
@@ -12,3 +12,25 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from django.conf.urls import patterns, url, include
+from django.conf import settings
+from django.views.generic import TemplateView, ListView, CreateView
+from django.core.urlresolvers import reverse
+from django import http
+from django.utils import simplejson as json
+from django.contrib.auth.models import User
+from django.utils.translation import ugettext as _
+from django.contrib.auth import authenticate, login
+from django.shortcuts import redirect
+from django.contrib import messages
+
+class AgoraCreateView(CreateView):
+ template_name = 'agora_core/base_top_form.html'
+ success_url = '' #reverse('agora-view')
+
+class ExtraContextMetaMixin(object):
+
+ def as_view(self, *args, **kwargs):
+ context = super(ExtraContextMetaMixin, self).as_views(*args, **kwargs)
+ return context
Oops, something went wrong.

0 comments on commit 3ffd05e

Please sign in to comment.