[mezzanine-users] Re: Can't get mezzanine to render template with real time database entries

2016-03-28 Thread Bernardo Tavares
Sorry for not giving much detail,

The object is being passed to direct_to_template view method:

extra_context = {"menssagens": Menssagem.objects.filter(publicado=True)}
url("^$", direct_to_template, {"template": "index.html", "extra_context": 
extra_context}, name="home"),

I have also tried creating a custom view.

And this is my models.py

class Menssagem(models.Model):
menssagem = models.TextField()
publicado = models.BooleanField(default=False)

class Meta:
verbose_name = "Menssagem"
verbose_name_plural = "Menssagens"

Em segunda-feira, 28 de março de 2016 19:12:28 UTC-3, Bernardo Tavares 
escreveu:
>
> Hello guys,
> I'm pulling my hair out trying to solve this issue and couldn't find any 
> solution on the internet or docs.
>
> I have the following code in my template:
>
> {% nevercache %}
> {% if menssagens %}
>   {% for menssagem in menssagens %}
>   
>   {{ menssagem.menssagem }}
> &
> times;
>   
>   {% endfor %}
> {% endif %}
> {% endnevercache %}
>
> The problem is when i change a database entry the changes are not rendered 
> to the html. I have to restart the server to update the changes. I thought 
> the problem was with mezzanine's caching engine. I have tried using 
> mezzanine.conf.Settings clear_cache() method and changing 
> CACHE_SET_DELAY_SECONDS without success.
>
> How can I update my html in real time like a page or blog entry?
>
> Any help would be greatly appreciated!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Re: Can't get mezzanine to render template with real time database entries

2016-03-28 Thread Bernardo Tavares
I figured it out,

The problem was that the object was being requested from database on script 
import and not on the function call. I looked everywhere for the answer but 
it was right in front of me. Breaks are good for the mind.

Thanks and sorry for the dumb question

Em segunda-feira, 28 de março de 2016 19:12:28 UTC-3, Bernardo Tavares 
escreveu:
>
> Hello guys,
> I'm pulling my hair out trying to solve this issue and couldn't find any 
> solution on the internet or docs.
>
> I have the following code in my template:
>
> {% nevercache %}
> {% if menssagens %}
>   {% for menssagem in menssagens %}
>   
>   {{ menssagem.menssagem }}
> &
> times;
>   
>   {% endfor %}
> {% endif %}
> {% endnevercache %}
>
> The problem is when i change a database entry the changes are not rendered 
> to the html. I have to restart the server to update the changes. I thought 
> the problem was with mezzanine's caching engine. I have tried using 
> mezzanine.conf.Settings clear_cache() method and changing 
> CACHE_SET_DELAY_SECONDS without success.
>
> How can I update my html in real time like a page or blog entry?
>
> Any help would be greatly appreciated!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Re: Can't get mezzanine to render template with real time database entries

2016-03-28 Thread Bernardo Tavares
Eduardo Rivas, just saw your answer, thanks for the help. This happens 
sometimes to me, when I focus too much on the problem i can't see the anwer.

I don't know much about page processors, I will study this!

The solution i gave was a simple view:

def index(request):
menssagens = Menssagem.objects.filter(publicado=True)
return render(request, "index.html", {'menssagens': menssagens})



Em segunda-feira, 28 de março de 2016 19:12:28 UTC-3, Bernardo Tavares 
escreveu:
>
> Hello guys,
> I'm pulling my hair out trying to solve this issue and couldn't find any 
> solution on the internet or docs.
>
> I have the following code in my template:
>
> {% nevercache %}
> {% if menssagens %}
>   {% for menssagem in menssagens %}
>   
>   {{ menssagem.menssagem }}
> &
> times;
>   
>   {% endfor %}
> {% endif %}
> {% endnevercache %}
>
> The problem is when i change a database entry the changes are not rendered 
> to the html. I have to restart the server to update the changes. I thought 
> the problem was with mezzanine's caching engine. I have tried using 
> mezzanine.conf.Settings clear_cache() method and changing 
> CACHE_SET_DELAY_SECONDS without success.
>
> How can I update my html in real time like a page or blog entry?
>
> Any help would be greatly appreciated!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Re: Can't get mezzanine to render template with real time database entries

2016-03-28 Thread Eduardo Rivas
Alright, so urls.py is loaded when the server is started. It means that 
the extra_context variable stores the Menssagem objects that are 
published at that time. The value is not updated on every request, which 
means that the published objects are never re-fetched. This is why you 
only get the new objects after a server restart.


My advice is that you create a very thin view, either function or 
class-based, to make sure your logic is executed on every request, not 
only on server load. Another option is to create a page processor for 
"/", injecting the context you want. 
http://mezzanine.jupo.org/docs/content-architecture.html#page-processors.


Hope that helps :)

--
You received this message because you are subscribed to the Google Groups "Mezzanine 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Re: Can't get mezzanine to render template with real time database entries

2016-03-28 Thread Eduardo Rivas

Glad you got it working!

--
You received this message because you are subscribed to the Google Groups "Mezzanine 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.