Skip to content

Commit

Permalink
changes to registration templates, paginate search results
Browse files Browse the repository at this point in the history
  • Loading branch information
visiblegovernment committed Jul 21, 2011
1 parent 020985f commit 8d7392b
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 42 deletions.
13 changes: 7 additions & 6 deletions mainapp/forms.py
Expand Up @@ -99,7 +99,9 @@ class Meta:
model = UserProfile
fields = ( 'first_name','last_name','phone',)


# from example here:
# http://yuji.wordpress.com/2010/02/16/django-extension-of-modeladmin-admin-views-arbitrary-form-validation-with-adminform/

RELATED_FIELD_MAP = {
'first_name': 'first_name',
'last_name': 'last_name',
Expand Down Expand Up @@ -326,17 +328,16 @@ def clean_email(self):

def send_email(self,new_user):
registration_profile = RegistrationProfile.objects.get(user=new_user)
current_site = Site.objects.get_current()

subject = render_to_string('registration/activation_email_subject.txt',
{ 'site': current_site })
)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())

message = render_to_string('registration/activation_email.txt',
{ 'activation_key': registration_profile.activation_key,
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
'site': current_site })
{ 'user': new_user,
'activation_link': "%s/accounts/activate/%s/" %(settings.SITE_URL,registration_profile.activation_key),
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS })

new_user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)

Expand Down
42 changes: 18 additions & 24 deletions mainapp/views/main.py
@@ -1,7 +1,7 @@
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect, Http404
from mainapp.models import DictToPoint, Report, ReportUpdate, Ward, FixMyStreetMap, OverallReportCount, City, FaqEntry
from mainapp import search
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.template import Context, RequestContext
from django.contrib.gis.measure import D
from django.contrib.gis.geos import *
Expand Down Expand Up @@ -49,41 +49,35 @@ def search_address(request):
# should have a lat and lon by this time.
dict2pt = DictToPoint( request.GET )
pnt = dict2pt.pnt()
wards = Ward.objects.filter(geom__contains=dict2pt.__unicode__())
if (len(wards) == 0):
ward = dict2pt.ward()
if not ward:
return( home(request, None, _("Sorry, we don't yet have that area in our database. Please have your area councillor contact fixmystreet.ca.")))

ward = wards[0]

# calculate date range for which to return reports
if request.GET.has_key('years_ago'):
years_ago = int(request.GET['years_ago'])
else:
years_ago = 0
yearoffset = datetime.timedelta(days = 365 * years_ago )
try:
page_no = int(request.GET.get('page', '1'))
except ValueError:
page_no = 1

reportQ = Report.objects.filter(is_confirmed = True,point__distance_lte=(pnt,D(km=2))).distance(pnt).order_by('-created_at')
paginator = Paginator(reportQ, 100)

date_range_end = datetime.datetime.now() - yearoffset
date_range_start = date_range_end - datetime.timedelta(days =365)
try:
page = paginator.page(page_no)
except (EmptyPage, InvalidPage):
page = paginator.page(paginator.num_pages)


# do we want to show older reports?
if Report.objects.filter(ward=ward,created_at__lte=date_range_start).count() > 1:
older_reports_link = _search_url(request, years_ago - 1)
else:
older_reports_link = None

reports = Report.objects.filter(created_at__gte = date_range_start, created_at__lte = date_range_end, is_confirmed = True,point__distance_lte=(pnt,D(km=2))).distance(pnt).order_by('-created_at')
reports = page.object_list
gmap = FixMyStreetMap(pnt,True,reports)

return render_to_response("search_result.html",
{'google' : gmap,
'GOOGLE_KEY': settings.GMAP_KEY,
"pnt": pnt,
"enable_map": True,
"ward" : wards[0],
"ward" : ward,
"reports" : reports,
"date_range_start": date_range_start,
"date_range_end": date_range_end,
"older_reports_link": older_reports_link },
"page":page },
context_instance=RequestContext(request))


Expand Down
4 changes: 2 additions & 2 deletions media/css/layout-8.css
Expand Up @@ -435,7 +435,7 @@ div#register {

#account-form h3 {
font-size:2em;
margin-bottom:20px;
margin-bottom:15px;
}

#register label {
Expand Down Expand Up @@ -537,7 +537,7 @@ input.big_button:hover {background: url("/media/images/search-hover.png") no-rep
#instructable img {padding-right:1.5em;}
#contact_us_form { width:450px; text-align: left; }
#contact_us_form p { margin-bottom: .5em; }
#privacy { text-align: left; }
#privacy { text-align: }
#posters { text-align: center; }
#posters p {width: 450px; margin: 20px auto;}
.myreports { width:100%; padding: 2em 0em; }
Expand Down
7 changes: 7 additions & 0 deletions templates/account/home.html
Expand Up @@ -11,6 +11,7 @@
{% block content %}
<h2>My Reports</h2>
{% include "reports/_pagination.html" %}
{% if reports %}
<table class='myreports'>
<tr>
<th>{% trans "Report" %}</th>
Expand Down Expand Up @@ -43,5 +44,11 @@ <h2>My Reports</h2>
</tr>
{% endfor %}
</table>
{% else %}
<br/>
<p>{% trans "You haven't yet filed any reports." %}</p>
<br/>
<a href='/'>{% trans "Submit a Report" %}</a>
{% endif %}
{% include "reports/_pagination.html" %}
{% endblock %}
2 changes: 1 addition & 1 deletion templates/registration/activate.html
Expand Up @@ -4,6 +4,6 @@
{% block content %}
<h2>{% trans "Account Confirmed" %}</h2>
<p>{% trans "Thanks for signing up!" %}</p>
<p/>
<br/>
<p><a href='/'>{% trans "Return to FixMyStreet.ca" %}</a></p>
{% endblock %}
16 changes: 16 additions & 0 deletions templates/registration/activation_email.txt
@@ -0,0 +1,16 @@
Hello {{user.first_name}},

You are almost done! Your FixMyStreet.ca account has been
created but your email address needs to be verified before
your account becomes fully active.

Click here to activate your account, or cut and paste
the link to your browser:

{{activation_link}}

Please keep this information for you records:
Username: {{user.username}}

Thank you for using FixMyStreet.ca.
The FixMyStreet.ca Team
1 change: 1 addition & 0 deletions templates/registration/activation_email_subject.txt
@@ -0,0 +1 @@
Activate your FixMyStreet.ca account
2 changes: 1 addition & 1 deletion templates/registration/registration_complete.html
Expand Up @@ -4,5 +4,5 @@
<h2>Check Your Inbox...</h2>
<p>Your account has been created, but you still need to confirm your email address.</p>
<p/>
<p>Please check your email at {{user.email}} to confirm.</p>
<p>Please check your email.</p>
{% endblock %}
6 changes: 2 additions & 4 deletions templates/registration/registration_form.html
Expand Up @@ -5,6 +5,7 @@
<style type="text/css" media="screen">
div#social-connect { text-align: center; padding-bottom: 1.5em; }
div#social-connect li { margin: 5px auto; }
div#register p { margin-bottom: 15px; }
</style>
{% endblock %}
{% block content %}
Expand All @@ -23,7 +24,7 @@
{% endif %}
<h3>{% trans "Join FixMyStreet.ca!" %}</h3>
{% if social_connect %}
<p>{% trans "We need a few more pieces of information to continue..." %}
<p>{% trans "We need a few more pieces of information to continue..." %}</p>
{% endif %}
<form action="{% url registration_register %}" method="POST">{% csrf_token %}
<table class='form'>
Expand All @@ -36,9 +37,6 @@ <h3>{% trans "Join FixMyStreet.ca!" %}</h3>
</tr>
</table>
</form>
<div id='tos'>
{% trans "By clicking 'Sign Up', you are indicating you agree to the fixmystreet.ca terms of service." %}
</div>

</div>
{% if providers %}
Expand Down
11 changes: 7 additions & 4 deletions templates/search_result.html
Expand Up @@ -16,23 +16,26 @@ <h3>{% trans "To Report a New Problem" %}</h3>
<img src="/media/images/arrow-right.png" class="right">
</div>
<br/><br/>
<p><strong>{% trans "Nearby reports filed between" %} {{date_range_start|date:"N jS, Y"}} {% trans "and" %} {{date_range_end|date:"N jS, Y"}}
{% if older_reports_link %} (<a href="{{older_reports_link}}" %}>{% trans "See older reports" %}</a>){% endif %}:</strong>
{% if reports %}
<p><strong>{% trans "Nearby Reports" %}:</strong></p>
{% include "reports/_pagination.html" %}
<ol id='search_results'>
{% for report in reports %}
<li><a href="{{report.get_absolute_url}}"> {{report.title}} ({{report.distance.km|floatformat:2}} km)</a>
{% if report.is_fixed %}({% trans "fixed" %}){% endif %}
</li>
{% endfor %}
</ol>
<p/>
<p>{% trans "Zoom out to see more reports nearby." %}</p>
<p/>
<p>{% trans "Zoom out to see more reports nearby." %}</p>
{% include "reports/_pagination.html" %}

{% else %}
<p>{% trans "No problems have been reported in this area." %}</p>
{% endif %}
</ol>
</p>

</div>

<div id="rightcol">
Expand Down

0 comments on commit 8d7392b

Please sign in to comment.