aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar neptune 2022-12-25 20:25:10 -0300
committerLibravatar neptune 2022-12-25 20:25:10 -0300
commitca824bec5c85acdc88d0436ad1191703b4584ec5 (patch)
tree2d5aa17aa6374656f230aba59cc164567e4a310f
parent9c0db2a20bc7b2f8f511d5b3dfbcd96583c4e5a9 (diff)
downloadweabot-ca824bec5c85acdc88d0436ad1191703b4584ec5.tar.gz
weabot-ca824bec5c85acdc88d0436ad1191703b4584ec5.tar.xz
weabot-ca824bec5c85acdc88d0436ad1191703b4584ec5.zip
Usar constantes para operaciones bitwise
-rw-r--r--cgi/framework.py7
-rw-r--r--cgi/manage.py73
2 files changed, 44 insertions, 36 deletions
diff --git a/cgi/framework.py b/cgi/framework.py
index 0f62fff..7894c16 100644
--- a/cgi/framework.py
+++ b/cgi/framework.py
@@ -14,6 +14,13 @@ from http.cookies import SimpleCookie
from settings import Settings
from database import *
+### Constants ###
+BIT = lambda x: 2 ** x
+
+RB_FRONT = BIT(0)
+RB_ALL = BIT(1)
+RB_KAKO = BIT(2)
+RB_HOME = BIT(3)
def setBoard(dir):
"""
diff --git a/cgi/manage.py b/cgi/manage.py
index 4199b91..4839b5e 100644
--- a/cgi/manage.py
+++ b/cgi/manage.py
@@ -867,19 +867,19 @@ def manage(self, path_split):
if self.formdata['longname'] != board['longname']:
board['longname'] = self.formdata['longname']
if board['board_type'] == 1:
- rebuild |= 1
+ rebuild |= RB_FRONT
else:
- rebuild |= 2
+ rebuild |= RB_ALL
if board['name'] != self.formdata['name']:
board['name'] = self.formdata['name']
- rebuild |= 2
+ rebuild |= RB_BOARD
if board['board_type'] == 1:
- rebuild |= 4
+ rebuild |= RB_KAKO
if board['subname'] != self.formdata['subname']:
board['subname'] = self.formdata['subname']
- rebuild |= 8
+ rebuild |= RB_HOME
board['anonymous'] = self.formdata['anonymous']
board['subject'] = self.formdata['subject']
@@ -897,20 +897,20 @@ def manage(self, path_split):
if 'disable_name' in self.formdata and not board['disable_name']:
board['disable_name'] = 1
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
elif 'disable_name' not in self.formdata and board['disable_name']:
board['disable_name'] = 0
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
if 'disable_subject' in self.formdata and not board['disable_subject']:
board['disable_subject'] = 1
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
elif 'disable_subject' not in self.formdata and board['disable_subject']:
board['disable_subject'] = 0
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
if 'secret' in self.formdata:
board['secret'] = 1
@@ -925,61 +925,61 @@ def manage(self, path_split):
if board['postarea_desc'] != self.formdata['postarea_desc']:
board['postarea_desc'] = self.formdata['postarea_desc']
if board['board_type'] == 1:
- rebuild |= 1
+ rebuild |= RB_FRONT
else:
- rebuild |= 2
+ rebuild |= RB_ALL
if board['postarea_extra'] != self.formdata['postarea_extra']:
board['postarea_extra'] = self.formdata['postarea_extra']
if board['board_type'] == 1:
- rebuild |= 1
+ rebuild |= RB_FRONT
else:
- rebuild |= 2
+ rebuild |= RB_ALL
if board['force_css'] != self.formdata['force_css']:
board['force_css'] = self.formdata['force_css']
- rebuild |= 2
+ rebuild |= RB_ALL
if 'allow_noimage' in self.formdata and not board['allow_noimage']:
board['allow_noimage'] = 1
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
elif 'allow_noimage' not in self.formdata and board['allow_noimage']:
board['allow_noimage'] = 0
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
if 'allow_images' in self.formdata and not board['allow_images']:
board['allow_images'] = 1
- rebuild |= 1
+ rebuild |= RB_FRONT
elif 'allow_images' not in self.formdata and board['allow_images']:
board['allow_images'] = 0
- rebuild |= 1
+ rebuild |= RB_FRONT
if 'allow_image_replies' in self.formdata and not board['allow_image_replies']:
board['allow_image_replies'] = 1
- rebuild |= 2
+ rebuild |= RB_ALL
elif 'allow_image_replies' not in self.formdata and board['allow_image_replies']:
board['allow_image_replies'] = 0
- rebuild |= 2
+ rebuild |= RB_ALL
if 'allow_spoilers' in self.formdata and not board['allow_spoilers']:
board['allow_spoilers'] = 1
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
elif 'allow_spoilers' not in self.formdata and board['allow_spoilers']:
board['allow_spoilers'] = 0
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
if 'allow_oekaki' in self.formdata and not board['allow_oekaki']:
board['allow_oekaki'] = 1
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
elif 'allow_oekaki' not in self.formdata and board['allow_oekaki']:
board['allow_oekaki'] = 0
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
if 'archive' in self.formdata:
board['archive'] = 1
@@ -994,26 +994,26 @@ def manage(self, path_split):
if 'filetype'+filetype['ext'] in self.formdata:
UpdateDb("INSERT INTO boards_filetypes VALUES (%s, %s)", (board['id'], filetype['id']) )
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
try:
if board['numthreads'] != int(self.formdata['numthreads']):
board['numthreads'] = int(self.formdata['numthreads'])
- rebuild |= 1
+ rebuild |= RB_FRONT
except:
raise UserError(_("Max threads shown must be numeric."))
try:
if board['numcont'] != int(self.formdata['numcont']):
board['numcont'] = int(self.formdata['numcont'])
- rebuild |= 1
+ rebuild |= RB_FRONT
except:
raise UserError(_("Max replies shown must be numeric."))
try:
if board['numline'] != int(self.formdata['numline']):
board['numline'] = int(self.formdata['numline'])
- rebuild |= 1
+ rebuild |= RB_FRONT
except:
raise UserError(_("Max lines shown must be numeric."))
@@ -1021,7 +1021,7 @@ def manage(self, path_split):
if board['thumb_px'] != int(self.formdata['thumb_px']):
board['thumb_px'] = int(self.formdata['thumb_px'])
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
except:
raise UserError(_("Max thumb dimensions must be numeric."))
@@ -1029,7 +1029,7 @@ def manage(self, path_split):
if board['maxsize'] != int(self.formdata['maxsize']):
board['maxsize'] = int(self.formdata['maxsize'])
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
except:
raise UserError(_("Max size must be numeric."))
@@ -1037,7 +1037,7 @@ def manage(self, path_split):
if board['maxage'] != int(self.formdata['maxage']):
board['maxage'] = int(self.formdata['maxage'])
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
except:
raise UserError(_("Max age must be numeric."))
@@ -1045,7 +1045,7 @@ def manage(self, path_split):
if board['maxinactive'] != int(self.formdata['maxinactive']):
board['maxinactive'] = int(self.formdata['maxinactive'])
if board['board_type'] == 0:
- rebuild |= 2
+ rebuild |= RB_ALL
except:
raise UserError(_("Max inactivity must be numeric."))
@@ -1063,19 +1063,20 @@ def manage(self, path_split):
if new_type != board['board_type']:
switchBoard(new_type)
board['board_type'] = new_type
+ rebuild |= RB_ALL
updateBoardSettings()
board = setBoard(board['dir'])
- if rebuild & 2:
+ if rebuild & RB_ALL:
regenerateBoard(everything=True)
- elif rebuild & 1:
+ elif rebuild & RB_FRONT:
regenerateBoard()
- if rebuild & 4:
+ if rebuild & RB_KAKO:
regenerateKako()
- if rebuild & 8:
+ if rebuild & RB_HOME:
regenerateHome()
message = _('Board options successfully updated.')