#3 Boolean combinations issue when sending out karma
Opened 7 years ago by skrzepto. Modified 7 years ago

What works

`increment = True` updates the karma by +1
`decrement=True` updates the karma by -1

What doesn't work

# This shouldn't increment up
`increment = False` updates the karma by +1

# This shouldn't decrement down
`decrement=False` updates the karma by -1

Yeah, it's a web form, so the only way of specifying true or false is by the presence of the key or its absence. I'm just converting to a bool whatever the "decrement" argument gives, and I'd rather not do too much parsing.

Basically, if you want to decrement, you have to set "decrement=<whatever>". Any other situation is an increment. Since it's a service to be used by applications, I guess it's OK like this, it should just be written in the docs :-)

Do you have a better proposal?

The problem is now we are giving trust to the external applications to play nice.

Perhaps we can extend the if statement

if we assume decrement=False to be increment then we can have something like this kind of logic

if form['decrement']:
    if form['decrement'] == True:
          increment = False
    elif form['decrement'] == False
           increment = True
elif form['increment]:
    if form['increment'] == True:
          increment = True
    elif form['increment'] == False
           increment = False

You could make that large if statement a seperate function as well. Also what I noticed is that the input for whats after decrement of increment type can be a problem. For hubs I made a helper function for this

def plus_plus_update_bool_helper(val):
     if isinstance(val, bool):
          return val
     elif isinstance(val, (str, unicode)):
         fmt_str = str(val).replace("'", "").replace('"', '').lower()
         return fmt_str in ("yes", "true", "t", "1")
         raise ValueError

Log in to comment on this ticket.