Sunday, May 24, 2015

Re: MultipleSelectCheckbox problem (working on dev, not on production)

Awesome. Glad to help.

As an aside, if your function is expecting a list of integers, I would also validate the code in the caller is actually doing what it is supposed to. You may have a use case where either longs or ints may be passed in, but something smells fishy in the code leading up to calling your render function if you're receiving unexpected data types.

Of course that may be expected behavior, so you may be just fine as is.

Just a thought.

-James

On May 23, 2015 11:24 PM, "gabn88" <gerbenmorsink@gmail.com> wrote:
Thanks James! I have solved the problem, but could have never done it without you!!! I will describe the problem if anybody else ever has the same problem.

The problem is in my widgets render function, this line:

        if value is None:
            value = []
        else:
            value = TemplateEventMeta.WEEKDAYS.get_selected_values(value)

On my dev server it correctly translates for example 7, to [1,2,4].

But on my production server it does not! I found out by send out a mail with the values :)

Where BitChoices.get_selected_values() is :
    def get_selected_values(self, selection):
        """ Return a list of values for the given selection, or empty is there is no selection or empty selection """
        if selection and isinstance(selection, int):
            return [b for b, v in self._choices if b & selection]
        elif isinstance(selection, list):
            return selection
        else:
            return []


When I got the mail messages I found out the L next to the integers, which means that python uses a long instead of integers. The isinstance(selection, int) therefore always gave a False!!! Now I fixed the check to also check for long and it works :):):) so happy!

Thank you once more!


Op zondag 24 mei 2015 01:13:09 UTC+2 schreef James Schneider:

In that case you should post up the relevant model, view, and form code. You may not be instantiating the form correctly.

Are you manually rendering it?

-James

On May 23, 2015 1:57 PM, "gabn88" <gerben...@gmail.com> wrote:
Thank you for your reply!

I have done the following steps:
1. disable memcached -> Nothing changed
2. Checked the databased -> Saved correctly
3. Checked browser cache -> Used chrome dev mode (with disable cache) -> Not working

I'm really banging my head off on this one...:(


Op zaterdag 23 mei 2015 11:42:13 UTC+2 schreef James Schneider:

Caching is often the culprit in these situations. Disable it and recheck. Obviously clear cookies and history in the browser as well.

Also, verify that your database shows the correct data state (meaning that the fields in the database show as checked) once the models are saved, either through the Django shell or directly interrogating the database.

Your web server process is least likely to be the culprit, unless it is telling the browser to use the cached version of your page for some reason.

-James

On May 23, 2015 12:26 AM, "gabn88" <gerben...@gmail.com> wrote:
I have a MultipleSelectbox form that creates multiple select boxes (wow!).

Now, I use a model to save the selected values to, and also to retrieve the values back from.

If a user wants to update the model, I would like to show them which checkboxes are checked already from the model. This works perfectly fine on my dev server, but not on my production server and I can't seem to find the issue.

Could the reason be: 1. the memcached, 2. the mysql vs sqlite, 3. the apache/wsgi/ngix vs. dev server configuration?

I really don't know where to start searching.

Thank you!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e28d66a-58a2-4f66-b77e-1a0898ae45b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3bbdba86-5e05-4c5d-9c24-be48d324f377%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/007338f4-3337-4823-9519-8ef4e0e11ed0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVaAyeXjmUNOHk7PQWJ4fykL6zHv61n7pcjk6%3Dsj5%3DWqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment