Update Objects and reset the isDirty-flag (ember-data 1.0 beta.2) - ember.js

With former versions of ember-data I could bring a modified model back to clear-state by calling:
user.transitionTo('loaded.saved')
Is there a way to do this in version 1.0beta.2? The main reason is to suppress any server requests when saying
user.save()
[Edit] - I didn't explicitly mention, that my intention was to keep the modified values, just resetting the dirty-state.

What I really wanted to do is updating some fields of a record w/o setting the dirty flag.
store.update(type, hash)
here: http://emberjs.com/blog/2013/09/04/ember-data-1-0-beta-2-released.html
does right that.

I responded over at Discourse, too, but for the sake of completeness:
user.rollback() does what you aim to do, judging from the source code.

Related

Saving cookies in Cypress without cy.session()

I am looking for some way how to save exact cookie in Cypress through whole test case.
Was using
Cypress.Cookies.defaults({ preserve: 'cookie_name' })
and
Cypress.Cookies.preserveOnce('cookie_name')
but this doesn't work anymore. And the new cy.session() is not working for me, because I use custom addresses per user and per new form.
Does anyone know of anything that works better than cy.session()?
The use pattern of cy.session() is a bit opaque, but since it replaces the older cookie config it probably can be made to work.
I have seen a note somewhere that session is likely to be revamped shortly.
Since Cypress.Cookies.preserveOnce('cookie_name') is deprecated but still available, maybe use that until session mark 2 comes along.

Express-validator: Define accepted fields

i am using the express-validator npm package. I looking for a way to prevent the user to send undesired fields on the body.
So, i want a validator that defines the accepted fields on the body. How can I do this with express-validator?
Just use matchedData from the filter API.
https://express-validator.github.io/docs/filter-api.html
I remember reading that it is a good idea to achieve this by taking a whitelist approach in the handler function. So, don't just incorporate all the posted variables. Specifically create a variable for each posted value you are expecting. Then If data is posted which you are not expecting it will not be incorporated into your program. Now I have written this I can see it is pretty much the same as the first answer.

Why should I care about django-revision operation being atomic?

I want to start using django-reversion. It seems the easiest way is to use their middleware. But it gives the following warning:
Warning: Due to changes in the Django 1.6 transaction handling, revision data will be saved in a separate database transaction to the one used to save your models, even if you set ATOMIC_REQUESTS = True.
What are the caveats if the requests are not atomic? It seems to indicate that there might be some kind of race conditions. How could they look like? What do I need to watch out for?
Thank you for your time. Sorry for spelling mistakes I'm not a native speaker.
As mentioned in the warning, due to some changes in the way django handles transactions since 1.6, the middlewares are no longer wrapped in the same transaction as the view function.
This is discussed at the following issue at django-reversion.
In practice, since the RevisionMiddleware runs outside of the transaction where the models are saved, no strict guarantee can be provided at the database level that reversion data will also be saved.
The usage of RevisionMiddleware was then discouraged. The following practice is advised:
If you need to ensure that your models and revisions are saved in the
save transaction, please use the reversion.create_revision() context
manager or decorator in combination with transaction.atomic()
This way, you can be sure that reversion_data will always be saved alongside model data. I hope this helps.

Shouldn't django's model get_or_create method be wrapped in a transaction?

I was browsing django's source and looked at get_or_create.
Shouldn't it be wrapped with a transaction?
Thanks
Looking at this diff it looks like as of Revision 8315, that has been handle explicitly within the get_or_create() method.
Update
As #reshefm pointed out, this was properly solved in rev 8670 where force_insert=True was added to obj.save() to ensure that during a race condition, all instances will attempt an insert (and not fall back to update) so only one will succeed while others will fail. Failing instances will proceed to do another get().
In terms of release version, this fix was first introduce in release 1.0.

Django: assign accesskey to label instead of select

i'm developing a site that must be as accessible as possible. While assigning the accesskeys to my form fields with
widget=FieldWidget(attrs={'accesskey':'A'})
i found out that the w3c validator won't validate an xhtml strict page with an accesskey in a select tag. Anyway i couldn't find a way to assign an accesskey to the label related to the select field (the right way to make the select accessible). Is there a way to do so?
Thanks
Interesting question. HTML 4.01 also prohibits accesskey in a select.
I believe the Short Answer is: Not in standard Django.
Much longer answer: I looked at the code in django/forms/fields.py and .../widgets.py and the label is handled strictly as a string (forced to smart_unicode()). Four possible solutions come to mind, the first three are not pretty:
Ignore the validation failure. I hate doing this, but sometimes it's a necessary kludge. Most browsers are much looser than the DTDs in what they allow. If you can get the accesskey to work even when it's technically in the wrong place, that might be the simplest way to go.
Catch the output of the template and do some sort of ugly search-and-replace. (Blech!)
Add new functionality to the widgets/forms code by MonkeyPatching it. MonkeyPatch django.forms.fields.Field to catch and save a new arg (label_attrs?). MonkeyPatch the label_tag() method of forms.forms.BoundField to deal with the new widget.label_attrs value.
I'm deliberately not going to give more details on this. If you understand the code well enough to MonkeyPatch it, then you are smart enough to know the dangers inherent in doing this.
Make the same functional changes as #3, but do it as a submitted patch to the Django code base. This is the best long-term answer for everyone, but it's also the most work for you.
Update: Yoni Samlan's link to a custom filter (http://www.djangosnippets.org/snippets/693/) works if you are generating the <label> tag yourself. My answers are directed toward still using the full power of Forms but trying to tweak the resultant <label>.