Forums

Errors with my Mezzanine project

Errors with my Mezzanine project , I post the details to mezzanine user group Thanks for your help

Looking at the error message on the page you linked in the user group, it looks like in your view:

@processor_for(Theme)
def subjects_list(request,page):
    return {'subject':page.children.filter(content_model='subject')}

...you're setting the template variable subject, but in the template:

{% for s in sujets %}

...you're iterating over a variable called sujets. Perhaps something else in your code is setting sujets to a single Page object?

Sorry Giles, I mistranslate from french to english to help, here is the complete code of my page_processor.py :

# -*- coding: utf-8 -*-
__author__ = 'stef'
from mezzanine.pages.page_processors import processor_for
from ligomezza.allervoir.models import Theme
from mezzanine.utils.views import  paginate
import ligomezza.settings as local_settings
from mezzanine.conf import settings

@processor_for(Theme)
def sujets_list(request,page):
    sujets =  paginate(page.children.filter(content_model='sujet').all(),
        request.GET.get("page", 1),
        local_settings.ENTRY_PER_PAGE,
        settings.MAX_PAGING_LINKS)
    return {'sujets':sujets}

As you can see bellow, the code return a list, not a single object, and most of all : its runs successfully on local runserver

In [1]: from mezzanine.pages.page_processors import processor_for
In [2]: from ligomezza.allervoir.models import Theme                                                                                                        
In [3]: from mezzanine.pages.models import Page
In [4]: page = Page.objects.filter(slug__iexact='astronomie')[0]
In [5]: print page.title
astronomie                                                                                                                                                  
In [6]: sujets = page.children.filter(content_model='sujet')                                                                                                
In [7]: for sujet in sujets :                                                                                                                              
....:     print sujet.title
....: 
A la recherche des océans extraterrestres | Espace des sciences                                                                                                
Christoph Adami : trouver une vie que l'on ne peut imaginer... | Société Française d'Exobiologie
Dailymotion - Dans les anneaux de Saturne-part1_3 - une vidéo High-tech et Science
Dailymotion - Les astres errants - une vidéo High-tech et Science                                                                                           
Espace des sciences - A La recherche de nouveaux mondes : l'Homme face à l'Univers           
Espace des sciences - Astronomie et écologie                                                    
Il pleut des planètes                                                                                                                                       
Quadruple éruption solaire observée par le satellite SOHO | Le Cosmographe

OK, I think I see the problem. page.children.filter(content_model='sujet').all() is iterable, but you're putting the result of the call to paginate into the sujets template variable:

sujets =  paginate(page.children.filter(content_model='sujet').all(),
        request.GET.get("page", 1),
        local_settings.ENTRY_PER_PAGE,
        settings.MAX_PAGING_LINKS)
return {'sujets':sujets}

In Django 1.3, paginate returns a Page object, which (as the error says) is not iterable. I think this may have changed in Django 1.4, which might explain the confusion.

You need to look at its object_list field in the template, by replacing your line

{% for s in sujets %}

with this:

{% for s in sujets.object_list %}

Give that a go, and let us know how you get on.

Bravo ! Yes you right, it works now, thank you very much, I would never be able to resolve this issue by myself. I post this answer to mezzanine group, it can help other poeple. Do you plan to upgrade to 1.4 ?

Excellent, thanks for confirming! I put something on the Mezzanine group already, but your confirmation that it worked there would definitely help :-)

We will upgrade to 1.4 in the future, the problem is making sure that we don't break people's existing 1.3 applications. Harry has some ideas about that -- we'll post more here when we have something solid.

Hello (and forgive my frenglish),

1) Things have evolved from your side because if I get off this "object_list" tag from the object "sujets" (see above) it still works and I'm happy because it fits with may local project.

2) I don't see my uploaded medias localted for instance as the following : <img src="/static/media/uploads/.thumbnails/michel-brunet-cover-75x75.jpg">. I precise that there had not been uploaded from pythonanywhere hosting, there were part of the git repo I pull from. Nevertheless I have debug=True and the staticfile helper in urls.py. I missed something?

3) Can't access admin, after login :

Django Version:     1.3.4
Exception Type:     ValueError
Exception Value:    
too many values to unpack
Exception Location:     /usr/local/lib/python2.7/site-packages/django/contrib/auth/models.py in check_password, line 42

This is of course because I build my project on DJ 1.4. Si, I tried to in an virtualenv execute my :

pip install -r requirements/project.txt

but it fails on Pilow (users can't compile as the read in the forum).

I don't kwown what to do exept restart coding my project with DJ1.3 :(

Do you have an idée ?

Thank you

To create the virtualenv, remove Pillow from the requirements.txt and then follow the instructions that @rcooke posted here. That should get PIL into your virtualenv and you should be able to continue from there.