After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 671180 - Better behaviour when profile image URL is invalid
Better behaviour when profile image URL is invalid
Status: RESOLVED FIXED
Product: damned-lies
Classification: Infrastructure
Component: l10n.gnome.org
unspecified
Other All
: Normal enhancement
: ---
Assigned To: damned-lies Maintainer(s)
damned-lies Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-03-02 02:09 UTC by Henrique P Machado
Modified: 2015-09-26 15:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
D-L cosmetic changes (5.36 KB, patch)
2012-03-02 02:09 UTC, Henrique P Machado
none Details | Review
D-L cosmetic changes #2 (4.07 KB, patch)
2012-03-07 02:37 UTC, Henrique P Machado
needs-work Details | Review
Add a javascript fallback for invalid avatar url (1.45 KB, patch)
2015-09-26 14:00 UTC, gregoire
committed Details | Review

Description Henrique P Machado 2012-03-02 02:09:26 UTC
Created attachment 208837 [details] [review]
D-L cosmetic changes

Hi, Devs.

I've made some changes on a local instance of Damned Lies just to correct an issue when the URL the D-L user provides for his/her image profile is not found. I.e: When the user joined the team, typed the URL for his profile image and for some reason the URL is not actually valid.

Currently, when the internet browser doesn't find users image, it simply shows the "alt" attribute of the "img" tag. Instead, I wrote some lines of code that shows the nobody.png or nobody-16.png (when listing users Actions), with a message on "title" attribute when he/she is logged.
Comment 1 Claude Paroz 2012-03-03 09:01:44 UTC
Here are some comments. You can disagree of course. Just explain your motivations if you think your approach is the right one:

* I don't think it's worth creating a new templatetags file. I know stats_extras.py might be a bit overloaded, but I suggest adding the check_for_image filter in this existing file anyway.

* About width/height forced to 100px, what about max-width/max-weight instead?

* I suspect something is missing in your patch, as valid_image is referenced in templates, but I don't see where it is defined.

Now I wonder if it wouldn't be better to just write a filter which takes person.image and output directly the <img> tag altogether. What do you think?
Comment 2 Henrique P Machado 2012-03-04 04:29:44 UTC
(In reply to comment #1)
> Here are some comments. You can disagree of course. Just explain your
> motivations if you think your approach is the right one:
> 

No, problem. 

> * I don't think it's worth creating a new templatetags file. I know
> stats_extras.py might be a bit overloaded, but I suggest adding the
> check_for_image filter in this existing file anyway.
> 

Well, in fact, I must confess that I created the new templatetag file because I didn't read stats_extras.py. +1 for you.

> * About width/height forced to 100px, what about max-width/max-weight instead?
> 

OK! Suggestion approved. +1 again.

> * I suspect something is missing in your patch, as valid_image is referenced in
> templates, but I don't see where it is defined.
> 

This time, I understood that valid_image is used just used to hold the value returned from check_for_image. Am I wrong?

> Now I wonder if it wouldn't be better to just write a filter which takes
> person.image and output directly the <img> tag altogether. What do you think?

Agreed! This would make the template code a little bit easyer to understand.

Thanks!
Comment 3 Claude Paroz 2012-03-04 19:29:36 UTC
(In reply to comment #2)
> > * I suspect something is missing in your patch, as valid_image is referenced in
> > templates, but I don't see where it is defined.
> > 
> 
> This time, I understood that valid_image is used just used to hold the value
> returned from check_for_image. Am I wrong?

You are wrong here. Template filters do not assign values to variables. You should have written: {{ person.image|check_for_image }} with your filter receiving only one argument which is person.image content.

I'm looking forward to your next patch :-)
Comment 4 Henrique P Machado 2012-03-07 02:37:27 UTC
Created attachment 209130 [details] [review]
D-L cosmetic changes #2
Comment 5 Henrique P Machado 2012-03-07 02:38:33 UTC
(In reply to comment #3)

> You are wrong here. Template filters do not assign values to variables. You
> should have written: {{ person.image|check_for_image }} with your filter
> receiving only one argument which is person.image content.

Thanks for the explanation. After reading this, I skimmed through the Django documentation and understood a little bit about filters.

But one thing that left me bored, was the impossibility of passing more than one parameter to the filter, which in this case, would help me/us a lot.
So I decided to quickly correct the issue with the images using only nodody.png while I study a little more on how to use nobody.png and nobody-16.png without creating another filter just to make it work inside vertimus_detail.html.

> 
> I'm looking forward to your next patch :-)

And here it is!
Comment 6 Claude Paroz 2012-03-07 09:00:47 UTC
Review of attachment 209130 [details] [review]:

I don't think it's worth keeping both nobody and nobody-16, it's fine for me if you use the same image and just set the size to 14x14 through css for the vertimus_detail.html page.

::: stats/templatetags/stats_extras.py
@@ +3,3 @@
 from django import template
 from django.conf import settings
+from django.contrib.auth.decorators import login_required

Probably a leftover from a previous tentative...

@@ +186,3 @@
+        if is_authenticated:
+            result = '<img src="%simg/nobody.png" alt="" title="%s"/>' % (settings.MEDIA_URL, img_title)
+    return mark_safe(result)

I think that it is unnecessary complicated to use is_authenticated. Just set the title to 'The image is invalid or was not found' for all cases.
Comment 7 Gil Forcada 2012-08-19 12:09:51 UTC
Henrique, are you still interested to get your patch in? :)

If you address Claude's last concerns in comment #6 maybe everything would be already fine to get the patch accepted and upstream ;)
Comment 8 Alexandre Franke 2015-06-01 22:18:35 UTC
Henrique seems to have disappeared. Gil or Claude, can you fix the patch and get it in?
Comment 9 gregoire 2015-09-26 13:57:27 UTC
Using URLValidator in the templates seems to be a bad idea to me both in term of performances and security. Django used to have a verify_url option on URLFied that has been removed for this reason.

I'm trying to see if there is a way to do it client-side. I.e. let the browser do the request (which it'll do anyway) and putting our own fallback image if it fails.
Comment 10 Claude Paroz 2015-09-26 14:00:06 UTC
Sure, this is the way to go.
Comment 11 gregoire 2015-09-26 14:00:42 UTC
Created attachment 312205 [details] [review]
Add a javascript fallback for invalid avatar url
Comment 12 Claude Paroz 2015-09-26 15:16:59 UTC
Review of attachment 312205 [details] [review]:

Thanks!