Symfony2 FlashBag stopped working after upgrade to 2.4? - session

In my controller I used this code to add a flash-message and redirect:
$this->get('session')->getFlashBag()->add('success', 'Foo Message');
return $this->redirect($this->generateUrl('list_route'));
I displayed the messages in the template with this code:
<div id="flashes" class="row-fluid">
{% for type, flashMessages in app.session.flashbag.all() %}
{% for flashMessage in flashMessages %}
<div class="alert alert-{{ type }}">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ flashMessage|raw }}
</div>
{% endfor %}
{% endfor %}
</div>
This worked perfectly until I upgraded from symfony 2.3 to 2.4.1.
There is no error, nothing wrong in my logs. The message is simply not displayed, app.session.flashbag is empty.
Did something change with the flashbag? How to fix that?

Are you using the Liip\CacheControlBundle by chance? I had the exact same problem and after some digging I found out that this bundle clears the flashbag.
in config.yml see if there is a flash_message_listner: true line and if there is turn it to false and things should work again.
I did this as an answer because I don't have enough rep to comment. I imagine that Liip\CacheControlBundle would have done that in the previous version too, but I thought I would give it a shot because it worked for me.
Instead of getting the standard distribution bundle I got the REST distribution and it came with this package which includes that flash_message_listner: true by default. Simply flipping that, fixed my problem.

Related

Jekyll - Plugins don't work when sorting posts

I have a plugin called jekyll-spaceship in Jekyll - It helps me to use video feature (not available in Markdown): ! [Video] (https://vimeo.com/633912445?height=500)
Everything works perfectly on post page.
But in home page, I am listing posts like this:
<div id="main" class="site-main">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
{% for post in paginator.posts %}
<header class="entry-header">
<h1 class="entry-title">
{{post.title}}
</h1>
</header>
<div class="entry-content">{{ post.content }}</div>
{% endfor %}
</div></div>
</div>
And, this event turns it into an image. So I can't use the plugin feature. I think {% for post in paginator.posts %} turns it into normal Markdown.
How can I fix this problem?
By the way, I am using jekyll-paginate-v2 for paginating but doesn't matter, its the same like normal Jekyll
I think this issue has been addressed and fixed, you can refer to spaceship with paginate-v2, and please try again with the latest version.

Show recent blog activity on main page

Using Lektor, trying to determine how to list the most recent three blogs by published date on the main landing (root) page. I'm feeling like I should be using a macro, but I don't understand how to pass the Blogs to the page template, or if this is an example of a flowblock? I've added a section like the following to the page.ini:
[children]
model = blog-post
order_by = -pub_date, title
but can't seem to loop through them in the template (no error is thrown but doesn't iterate). Quite lost, but still consuming the documentation.
I ended up using the site.query class functionality directly in the layout template (based on the Blog quickstart).
{% for blogpost in site.query('/blog').order_by('pub_date').limit(3) %}
<div class="post col-md-4">
<div class="post-details">
<div class="post-meta d-flex justify-content-between">
<div class="date">{{ blogpost.pub_date }}</div>
</div><a href="post.html"> <!-- fix this one shortly -->
<h3 class="h4">{{ blogpost.title }}</h3></a>
<p class="text-muted">{{ blogpost.teaser }}</p>
</div>
</div>
{% endfor %}

Deletion by tab button doesn't work

Several DEVICE forms can be displayed on a page (Order), as tabs. When a user closes a tab and hits save, then renters that particular Order (ID), the user still sees his deleted tab. As a quick workaround, a checkbox was built into the html code but this is not desired.
Currently the code in my view.py looks like this.
def edit_order(request,id = None, order_id = None):
order = Order.objects.get(id=id)
'''some stuff'''
if request.method == 'POST':
formCustomer = CustomerModelForm(request.POST,instance=Customer.objects.get(order=order.id))
formInfo = InfoModelForm(request.POST,instance=Info.objects.get(order=order.id))
DBFormSet = modelformset_factory(DB, extra=1, can_delete=True, form=LUNModelForm)
formset = DBFormSet(request.POST or None, queryset=DB)
if formset.is_valid():
for i,frm in enumerate(formset.forms):
if frm.cleaned_data['id']:
if frm.is_valid():
if not frm.cleaned_data['capacityGB'] > 0:
frm.cleaned_data['id'].delete()
elif frm.cleaned_data['DELETE'] == True:
frm.cleaned_data['id'].delete()
#frm.save() or formset.save() ??
else:
dev = frm.cleaned_data['id']
dev.capacity = frm.cleaned_data['capacity']
dev.save()
I suspected the matter that the tab was not remaining closed was an issue with "can_delete", but it doesn't seem to make a difference when I added this. Then I read that the issue could be related to the formset.save, which also didn't resolve anything. Below the html code:
html:
<ul class="nav nav-tabs" id="tab4Headers">
{% for form in formsetDEVICE.forms %}
{% if forloop.first %}
{% if form.errors %}
<li class="active">DEVICE <i class="icon-warning-sign"></i> </li> <!-- section 4.1 -->
{% else %}
<li class="active">DEVICE</li> <!-- section 4.1 -->
{% endif %}
{% else %}
{% if form.errors %}
<li><button class="close" type="button" id="close-tab4_{{forloop.counter}}">×</button>DEVICE <i class="icon-warning-sign"></i> </i></li> <!-- section 4.2 ... 4.n -->
<!--{% if formsetDEVICE.can_delete %}
<li>{{ form.DELETE }}</li>
{% endif %}-->
{% else %}
<li><button class="close" type="button" id="close-tab4_{{forloop.counter}}">×</button>DEVICE</li> <!-- section 4.2 ... 4.n -->
<!--{% if formsetDEVICE.can_delete %}
<li>{{ form.DELETE }}</li>
{% endif %}-->
{% endif %}
{% endif %}
{% endfor %}
</ul>
Since it is not clear how to delete the tab via closing the tab (and then hit the save button), the current work around is simply to insert a section on the tab with a checkbox included, as so:
{# --- delete item --- #}
{% if form.instance.pk %}
{# render row for DELETE-flag only for forms with existing instance #}
<tr>
<td colspan="2">
</td>
<td colspan="2">
edit Action required: <br/><br/>
{{form.DELETE|safe}} delete this DEVICE from the Order.
</td>
</tr>
{% endif %}
{# --- END delete item --- #}
The current workaround works, but this is not the desired functionality. I've tried some of the suggestions as seen here, but to no avail. I think the problem is more related to the link between the html and the view.py (so something to do with frm.cleaned_data['DELETE'] though I could be wrong.
EDIT:
I suspect to get around this, js code and/or css needs to be inserted.
I was having the same problem with inlineformset_factory. Reading the base Django classes, i found the problem seems to be in BaseFormSet class (or some like that), the _should_delete_form() method looks for the forms DELETE value in cleaned_data, but using debugging i found that the DELETE value doesn't exist in cleaned_data, neither the DELETE field exists by the time cleaned_data is populated.
I think this could be because the DELETE field is dynamically created by FormSet Classes, but cleaned_data is populated by the Form class before the DELETE field is created (somewhere on forms init? maybe) so as this field doesn't exists, cleaned_data DELETE value isn't populated.
Somewhere in the base FormSet classes, the dynamically created DELETE field value have to be included in cleaned_data, BUT i found a quick and temporary solution to this, Add the DELETE field to the form class:
class RutinaForm(ModelForm):
DELETE = forms.BooleanField(required=False, widget=forms.CheckboxInput())
class Meta:
model = Rutina
fields = '__all__'
exclude = ('usuario',)
widgets = { .........}
This way the DELETE field exists so its value gets cleaned and added to cleaned_data.
This can be seen like a "machetazo", but it works! at least temporary. I will continue reading the base code and look if it is a bug, or what is happening.
Note: Sorry for my english, and i'm not an expert so PLEASE give me your comments.
This is my view if you need it, or if you can find what is wrong:
rutinaFormSet = inlineformset_factory(Usuario, Rutina, form=RutinaForm, can_delete=True, extra=1)
if request.method == 'POST':
formSet = rutinaFormSet(request.POST, instance=usuario)
if formSet.is_valid():
formSet.save()
else:
formSet = rutinaFormSet(instance=usuario)

Why won't datepicker work in a twig in userfrosting?

Bit of a beginner here and this issue has been causing me a headache for over a day. I'm using userfrosting as a framework, with the usual twig files for the web pages.
I'm trying to include a datepicker (bootstrap-datepicker.js hasn't worked, neither is the current iteration using jquery-ui) in a form in a twig - but no matter what I do, I can't get it to work!
Here's the basic setup:
{% block head %}
{{ parent() }}
<script src="{{site.uri.js}}/jquery-1.11.2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="{{site.uri.js}}/custom.js" ></script>
{% endblock %}
{% block content %}
.... {{boring stuff missed out}}
<form class="form-inline" role="form">
.... {{boring stuff missed out}}
<div class="form-group row">
<label for="datepicker" class="col-sm-3 form-control-label">Subject Date:</label>
<div class="col-sm-6">
<input type="date" class="form-control" id="datepicker" />
</div>
</div>
.... {{boring stuff missed out}}
</form>
.... {{boring stuff missed out}}
{% endblock %}
{% block javascripts %}
<script type="text/javascript">
$(document).ready(function() {
$("#datepicker").datepicker();
});
</script>
{% endblock %}
The box is on the page, you can type a date into it etc, but nothing appears when you click on it (there should be a calendar appearing.)
Anyone have any ideas? I'm at a total loss. I've tried various versions, locally and (as you can see, currently) on a CDN, but nothing works. I'm sure it's probably something basic as I'm not an experienced web dev or anything, but any advice or working examples would be gratefully received!
Uh! facepalm
Well, after some digging and serious consideration of the inspector output (thanks CTRL-SHIFT-I!) it turns out to be a simple case of script loading order and multiple scripts being loaded.
I didn't realise twig loads a whole bucketload of scripts on top of what I ask it to load in the template I was creating. Only after seeing the inspector output for the page did I see that I was trying to load two different versions of jQuery and my own custom script was being loaded out of order - I was loading them here:
{% block head %}
{{ parent() }}
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script src="{{site.uri.js}}/custom.js" ></script>
{% endblock %}
that block should be reserved for stylesheets. Instead, I should be loading them here:
{% block page_scripts %}
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script src="{{site.uri.js}}/custom.js"></script>
{% endblock %}
... so that they are loaded AFTER all the default Bootstrap and userfrosting scripts.
https://jqueryui.com/datepicker/ uses type="text" for the input field. When I google the matter it seems that type="date" has at least previously caused problems.
In short: I would try changing type="date" to type="text".

Struggling to find array in Jekyll config file (site navigation)

In my _config.yml I have:
navigation:
- text: Home
url: index.html
- text: About
url: about.html
- text: Blog
url: blog.html
- text: Portfolio
url: portfolio.html
In my default.html layout I have:
<ul class="nav-list">
{% for link in site.navigation %}
{% assign current = nil %}
{% if page.url == link.url %}
{% assign current = 'current' %}
{% endif %}
<li class="nav-list-item{% if forloop.first %}first{% endif %} {{ current }} {% if forloop.last %}nav-list-item-last{% endif %}">
<a class="{{ current }}" href="{{ link.url }}">{{ link.text }}</a>
</li>
{% endfor %}
</ul>
For some reason, this is not working. Why might this be?
I just found out you have to restart the server and run jekyll --server again and the _config.yml variables will be accessible.
Then after figuring it out came back to this page and was about to post this answer, clicked add / show 4 more comments and saw that this was also found out by the op. So posting it as answer.
In addition to the other answer: You can - as you mentioned in your answer - use Ctrl + C to end the currently running server (in your CLI). But, you can as well start the server with
jekyll server -w
to tell Jekyll to watch for changes in your files. Whilst this won't work for changes to the _config.yml, it works for all other files. Note, that this won't work including the --safe option, so you won't get errors. To catch them, I still recommend to run jekyll --safe build from time to time to see if you got syntax errors. The same goes for running jekyll doctor/jekyll hyde sometimes during your dev process.

Resources