Improve adding data to forms programmatically

2015-09-15 Thread 'Moritz Sichert' via Django developers (Contributions to Django itself)
Hello,

currently you can add data to forms either by passing it into the
"initial" or the "data" argument of Form. However sometimes I have the
need to add data to a Form that isn't request.POST and doesn't come from
an http request.

My use case is the following:

I have a form where a user can edit a model. So I pass the current
values into "initial". Now the user can "save" his current changes
without saving the model instance. He can come back later and see the
changes he already made. So "initial" is still the data from the model
but now "data" has also be filled with the cached changes.
Only when the user clicks on "change model" the changes will actually be
made to the model.

The problem now is that when the user "saves" his intermediate changes I
get the data from form.cleaned_data and cache it somewhere. However if I
want to display the form back to the user I have to convert the data
from the format

{'field1': 'value1', 'field2': 'value2'}

into something like

{'form-prefix-widget-specific-field1': 'value1',
 'form-prefix-widget-specific-field2': 'value2'}

and have to actually know how the widgets get their data.

I'd like to propose a new argument to "django.forms.Form" called
"data_values".
Its semantics will be just like data. The difference is that it will be
a dictionary storing the data in {'field-name': 'field-value'} format
instead of a widget specific one.

I have a branch where I sketched this new functionality here:
https://github.com/MoritzS/django/tree/forms-data-values

I'd like to hear your comments on this!

Moritz

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/55F87E14.2090001%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Capturing faked migrations in django_migrations table

2015-09-15 Thread Markus Holtermann
First of all, thanks for all the feedback!

While the PR is in a good state there's one discussion happening with a 
decision that needs to be made:

The current Django documentation states that log messages are send to the 
console from INFO level an up. However, because of a misconfiguration this 
is not true; messages are logged for WARNING and above 
(see https://github.com/django/django/pull/5289 for a patch for that, see 
discussion at 
https://groups.google.com/forum/#!topic/django-developers/no2IhnRty68). 
Giving the updated default configuration, sending log messages to any 
logger in the `django` namespace ('django.*') will show up on the command 
line when run on DEBUG=True. This may make sense for `django.request` as 
that is issued from the runserver command, but at least the newly 
introduced `django.db.migrations` logger is not too helpful on the console. 
Even for `django.db` (query logging) I'm not too happy for it to show up in 
`manage.py shell` but like it in `manage.py runserver`.

I see the following solutions to bring this PR forward:

   1. Configure `django.db.migrations` logger to not send messages to 
   console by default and keep log levels to INFO (for "Applied/Unapplied 
   migration XYZ") and DEBUG (for "Marked migraiton XYZ as applied/unapplied")
   2. Change the log levels for both messages to DEBUG
   3. Don't propagate messages from `django.db.migrations` logger to parents
   4. Don't go forward with the above mentioned patch amending the default 
   log level

I prefer option 1 and clearly document how people can activate the logger, 
while option 2 is currently implemented but comes with the disadvantage 
that you can't separate the two log levels. Option 3 works too, but could 
cause some weird behavior and confusion if not documented why it's set. 
Option 4, no idea, it sounds correct to me.

/Markus

On Sunday, September 13, 2015 at 10:08:15 AM UTC+10, Markus Holtermann 
wrote:
>
> Hey there,
>
> here's a pull request for this feature: 
> https://github.com/django/django/pull/5279 . I'd appreciate some review.
>
> /Markus
>
> On Wednesday, May 20, 2015 at 9:25:00 AM UTC+10, steve byerly wrote:
>>
>> Awesome, thank you very much for the detailed answer.
>> -Steve
>>
>> On Tue, May 19, 2015 at 4:16 PM, Shai Berger  wrote:
>>
>>> Hi Steve,
>>>
>>> On Wednesday 20 May 2015 01:50:15 steve byerly wrote:
>>> >
>>> > I'm also unclear what the argument against storing in the migrations 
>>> table
>>> > is vs logging them - honest question. Since I have 4 web servers, the
>>> > information would be logged to any one of them - depending on which
>>> > executed the migration during deploy.
>>> >
>>>
>>> The argument is, basically, that logging solves a more general use-case, 
>>> and
>>> so it is a better solution for the problem.
>>>
>>> Your use case, as you described it:
>>>
>>> > During a deploy, it's really nice to make sure you faked the right
>>> > migrations/didn't fake the wrong migrations
>>>
>>> fits in the general pattern of "I want to know what happened in this 
>>> system".
>>> Logging, as far as we understand, solves that problem. The migrations 
>>> table
>>> solves a different problem -- it records which migrations the system 
>>> considers
>>> to have been executed, to support the decision of which migrations to run
>>> (when asked to). One of the outstanding "conflicts" between the two 
>>> goals is
>>> encountered when a migration is rolled back: For "decision support", the
>>> simplest handling is to delete the migration's record from the table 
>>> (and this
>>> is what Django does, AFAIK). For "forensics", this behavior is quite
>>> unacceptable.
>>>
>>> The most natural solution for knowing what happened in a system is 
>>> logging.
>>> When you have 4 servers, you want some federated logging anyway -- 
>>> migrations
>>> are probably not the only case where something that happens on one server
>>> affects the behavior of others. Be that as it may, Python's logging 
>>> library
>>> allows you to set different handlers for different loggers -- so, 
>>> assuming
>>> migrations get their own logger, it shouldn't be very hard to set up 
>>> logging
>>> so that all migration logging goes to some special place. That place can 
>>> even
>>> be the database -- see e.g. https://pypi.python.org/pypi/django-logdb 
>>> (I have
>>> no personal experience with that package, I just searched for it).
>>>
>>> HTH,
>>> Shai.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/e9fda94e-f405-472d-bb08-f099e

created_at / modified_at on all database tables

2015-09-15 Thread Aron Podrigal
Hi,

I'd like to propose a created_at / modified_at auto field to models so that 
one can just turn this functionality on by a setting in settings.py or 
within the models Meta settings.
I want these fields on both of the OneToOne related models when using 
concrete inheritance, thus using a TimeStampedBaseModel abstract model 
would cause these fields to clash. The reason I need created_at / 
updated_at on every table because Django is not the only app using the 
database I have other services sharing the same database. I assume having 
created_at updated_at fields on tables to be very common. I can imagine 
django creating those fields to all tables implicitly while handling those 
field collisions properly (eg.  When accessing model.created_at on a 
derived class it will return the value of that model. 
model.base_model.created_at would give access to its base model).

What are your thoughts?

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/4c2a341f-e9d1-4841-892d-8d72c7688db9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.