Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Cachebust my own picture, fix bug 690513
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed Oct 4, 2011
1 parent 13b8fbf commit 21cb055
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
17 changes: 17 additions & 0 deletions apps/phonebook/helpers.py
@@ -1,7 +1,24 @@
import time

import jinja2
from funfactory.urlresolvers import reverse
from jingo import register


@register.filter
def vouched(user):
if hasattr(user, 'is_vouched'):
return user.is_vouched()


@register.inclusion_tag('phonebook/includes/photo.html')
@jinja2.contextfunction
def profile_photo(context, person):
user = context['request'].user
me = bool(user.username == person.username)
url = reverse('phonebook.profile_photo', args=[person.unique_id])

if me:
url += '?%d' % int(time.time())

return dict(image_url=url)
2 changes: 2 additions & 0 deletions apps/phonebook/templates/phonebook/includes/photo.html
@@ -0,0 +1,2 @@
<img class="photo u-photo"src="{{ image_url }}" id="profile-photo"

This comment has been minimized.

Copy link
@cvan

cvan Oct 4, 2011

should probably be a space before src

This comment has been minimized.

Copy link
@davedash

davedash Oct 4, 2011

Author Contributor

ergh, stupid "Join-lines" command thanks for the catch

alt="{{ _('Profile photo') }}">
3 changes: 1 addition & 2 deletions apps/phonebook/templates/phonebook/profile.html
Expand Up @@ -56,8 +56,7 @@ <h1>
<div class="clear"></div>

<div class="blue-pastels vcard h-card">
<img class="photo u-photo" src="{{ url('phonebook.profile_photo', person.unique_id) }}"
id="profile-photo" alt="{{ _('Profile photo') }}">
{{ profile_photo(person) }}

{% if user.username == person.username %}
<a href="{{ url('phonebook.edit_profile', person.unique_id) }}"
Expand Down
7 changes: 7 additions & 0 deletions apps/phonebook/tests/test_views.py
Expand Up @@ -218,6 +218,13 @@ def test_pending_edit_profile(self):
r = newbie_client.post(delete_url, data, follow=True)
eq_(200, r.status_code, 'A Mozillian can delete their own account')

def test_my_profile(self):
"""Are we cachebusting our picture?"""
profile = reverse('profile', args=[MOZILLIAN['uniq_id']])
r = self.mozillian_client.get(profile)
doc = pq(r.content)
assert '?' in doc('#profile-photo').attr('src')


def _logged_in_html(response):
doc = pq(response.content)
Expand Down
9 changes: 3 additions & 6 deletions apps/phonebook/views.py
Expand Up @@ -8,7 +8,6 @@
HttpResponseForbidden)
from django.shortcuts import redirect, render
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST

import jingo
Expand Down Expand Up @@ -99,11 +98,9 @@ def _profile(request, person, use_master):
person.irc_nickname = services[MOZILLA_IRC_SERVICE_URI]
del services[MOZILLA_IRC_SERVICE_URI]

return jingo.render(request, 'phonebook/profile.html',
dict(absolutify=absolutify,
person=person,
vouch_form=vouch_form,
services=services))
data = dict(absolutify=absolutify, person=person, vouch_form=vouch_form,

This comment has been minimized.

Copy link
@cvan

cvan Oct 4, 2011

instead of passing absolutify as a context variable, you could register this as a function/filter

This comment has been minimized.

Copy link
@davedash

davedash Oct 4, 2011

Author Contributor

Thanks, I didn't even notice that.

services=services)
return jingo.render(request, 'phonebook/profile.html', data)


@never_cache
Expand Down

0 comments on commit 21cb055

Please sign in to comment.