Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Post creation is now handled with a specific class, which has a singl…

…e insert() method for insertion into the database.
  • Loading branch information...
commit e3a06a5d9c9743e0921cb7c8eee9b9b196a95307 1 parent 531669c
Trevor Slocum authored
50 post.py
View
@@ -2,12 +2,62 @@
import os
import threading
import Queue
+import _mysql
from database import *
from template import *
from settings import Settings
from framework import *
+class Post(object):
+ def __init__(self, boardid=0):
+ self.post = {
+ 'boardid': boardid,
+ 'parentid': 0,
+ 'name': '',
+ 'tripcode': '',
+ 'email': '',
+ 'subject': '',
+ 'message': '',
+ 'password': '',
+ 'file': '',
+ 'file_hex': '',
+ 'file_mime': '',
+ 'file_original': '',
+ 'file_size': 0,
+ 'file_size_formatted': '',
+ 'thumb': '',
+ 'image_width': 0,
+ 'image_height': 0,
+ 'thumb_width': 0,
+ 'thumb_height': 0,
+ 'thumb_catalog_width': 0,
+ 'thumb_catalog_height': 0,
+ 'ip': '',
+ 'timestamp_formatted': '',
+ 'timestamp': 0,
+ 'bumped': 0,
+ }
+
+ def __getitem__(self, key):
+ return self.post[key]
+
+ def __setitem__(self, key, value):
+ self.post[key] = value
+
+ def __iter__(self):
+ return self.post
+
+ def insert(self):
+ post_values = [_mysql.escape_string(str(value)) for key, value in self.post.iteritems()]
+
+ db.query('INSERT INTO `posts` (`%s`) VALUES (\'%s\')' % (
+ '`, `'.join(self.post.keys()),
+ '\', \''.join(post_values)
+ ))
+
+ return db.insert_id()
+
class RegenerateThread(threading.Thread):
def __init__(self, threadid, request_queue):
threading.Thread.__init__(self, name="RegenerateThread-%d" % (threadid,))
41 pyib.py
View
@@ -69,33 +69,8 @@ def run(self):
except:
raise Exception, 'Invalid board supplied'
- post = {
- 'boardid': board['id'],
- 'parentid': 0,
- 'name': '',
- 'tripcode': '',
- 'email': '',
- 'subject': '',
- 'message': '',
- 'password': '',
- 'file': '',
- 'file_hex': '',
- 'file_mime': '',
- 'file_original': '',
- 'file_size': 0,
- 'file_size_formatted': '',
- 'thumb': '',
- 'image_width': 0,
- 'image_height': 0,
- 'thumb_width': 0,
- 'thumb_height': 0,
- 'thumb_catalog_width': 0,
- 'thumb_catalog_height': 0,
- 'ip': self.environ['REMOTE_ADDR'],
- 'timestamp_formatted': '',
- 'timestamp': 0,
- 'bumped': 0,
- }
+ post = Post(board['id'])
+ post['ip'] = self.environ['REMOTE_ADDR']
try:
parent = cgi.escape(self.formdata['parent']).strip()
@@ -174,17 +149,9 @@ def run(self):
post['bumped'] = timestamp(t)
post['nameblock'] = nameBlock(post['name'], post['tripcode'], post['email'], post['timestamp_formatted'])
- post_values = [_mysql.escape_string(str(value)) for key, value in post.iteritems()]
-
- db.query('INSERT INTO `posts` (`%s`) VALUES (\'%s\')' % (
- '`, `'.join(post.keys()),
- '\', \''.join(post_values)
- ))
-
- postid = db.insert_id()
-
+ postid = post.insert()
trimThreads()
-
+
if post['parentid']:
if post['email'].lower() != 'sage':
db.query('UPDATE `posts` SET bumped = ' + str(timestamp(t)) + ' WHERE `id` = ' + str(post['parentid']) + ' AND `boardid` = ' + board['id'] + ' LIMIT 1')
4 templates/base_bottom.html
View
@@ -2,7 +2,9 @@
<?py include('templates/navbar.html') ?>
<?py #endif ?>
<div class="footer" style="clear: both;">
- - <a href="http://www.2chan.net" target="_top">futaba</a> + <a href="http://www.1chan.net" target="_top">futallaby</a> + <a href="http://www.kusaba.org" target="_top">kusaba</a> + <a href="http://code.google.com/p/pyib-standalone/" target="_top">PyIB</a> r$WCREV$ -
+ - <a href="http://www.2chan.net" target="_top">futaba</a> + <a href="http://www.1chan.net" target="_top">futallaby</a> + <a href="http://www.kusaba.org" target="_top">kusaba</a> + <a href="http://code.google.com/p/pyib-standalone/" target="_top">PyIB</a>
+r<?py include('templates/revision.html') ?>
+ -
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
1  templates/revision.html
View
@@ -0,0 +1 @@
+23
Please sign in to comment.
Something went wrong with that request. Please try again.