Is it ok to change request.POST._mutable [closed] - django

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Django 1.11.2
Do you think this is a good style or not:
In CBV:
request.POST._mutable = True
request.POST['{}_date_day'.format(prefix)] = ceil_day(day=day, month=month, year=year)
request.POST._mutable = False
The program works well. I'm satisfied. What troubles me is whether this is ok or not. Maybe it is really a bad practice.
I mean, is it acceptable that we should change the private property _mutable?

The first argument to a Form is simply a dictionary, it's not necessary to use the request.POST querydict, and it's a bad practice to interfere with the inner workings of the framework, you'll make your code much more portable if you do:
my_querydict = request.POST.copy() #creates a mutable copy
my_querydict['{}_date_day'.format(prefix)] = ceil_day(day=day, month=month, year=year)
form = WhateverForm(my_querydict)
You'll feel better about yourself later :-)

Related

Why there's a not operator in programming? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Regardless of the programming language, Why there's a not operator while I may compare the expression with false and that will do the work needed.
For example, if I have a function called valid that returns boolean (true if valid and false if not) and I want to check if it's not valid then I will write it like this:
if not valid():
print("Not Valid")
While I can simply check if valid equals false like this:
if valid() == false:
print("Not Valid")
not is shorter and it is easier to understand. if not valid is simpler and closer to English than if valid equals false

Django SlugField versus URLField [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Both of these fields appear to serve essentially the same purpose. Are there any situations in which you would choose a SlugField instead of a URLField?
URLField is used to store URL, where as SlugField is used to store a alphanumeric/varchar value that relates to the title or some description of the model.
Example
URL: https://www.example.com/products/whss1540-wrogn-printed-slim-fit-sweatshirt
Slug: whss1540-wrogn-printed-slim-fit-sweatshirt

Full hydrate vs per field hydrate best practices [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm getting quite familiar with Django and Tastypie but I have a question about best practices. When I'm hydrating data coming from a POST, should I prefer to hydrate all fields directly in the hydrate function or it's recommended to hydrate each field separetely in the corresponding hydrate_field subfunction? In my case I have only 4 fields and to me it seems faster to simply define the hydrate function with 5 lines of code performing the complete transformation of the provided bundle.
Thanks for your help
Hydrating all 4 fields in a single hydrate method is totally fine, just be careful not to hydrate data for read-only fields.

Readability: splitting lines of code, should the operator be on the first or second line? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Simple question about formatting code (in my case C++).
If I have a line of code, say:
SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace + IDontActuallyUseVariablesThisLong
Should I split it like:
SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace +
IDontActuallyUseVariablesThisLong
or:
SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace
+ IDontActuallyUseVariablesThisLong
Another example:
foo = bar->baz;
// Should it be:
foo = bar->
baz;
//Or:
foo = bar
->baz;
Do people have a preference when it comes to this? Is it on a case-by-case basis? They both seem equally clear (or unclear) to me, so I was wondering if there are any standard ways of doing it.
Yes, people have preferences about this.
No, there's no standard or consensus agreement. I'm not aware of any especially strong arguments for either side, either.
So like any coding style issue, you can stick with whatever other people who edit the same code have been doing, or just pick one you like.
(I wouldn't even complain about being inconsistent on this issue.)

Is relying on short-circuit evaluation good design? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Are there alternatives that would be more preferred?
Short-circuit evaluation is a crucial feature of most modern programming languages and there's no reason to avoid relying on it. Without it pointer-related tests would be (unnecessarily) much more complicated and less readable.
Of course it's good design, everyone knows to expect it and it beats using nested conditionals.