def addcomment (self, body, slug): # Verify user is logged in. if (not pageutils.is_logged_in_p()): raise cherrypy.HTTPRedirect ("/login") # Remove any leading or trailing spaces from comment text. body = string.strip(body) user_id = pageutils.get_user_id() if (user_id == None): raise cherrypy.HTTPRedirect ("/login") try: # Connect to the database and insert the values. dbconnection = pgdb.connect (database_connect_fields) dbcursor = dbconnection.cursor() dbcursor.execute ("SELECT * FROM articles WHERE slug=%s", [slug]) results = dbcursor.fetchone() if (results == None): return pageutils.generate_page ("Invalid Article Specified", "Unable to post comment.") article_id = results[0] # article_id is the first column in the table. dbcursor.execute ("INSERT INTO articles (author_id, body, display, refers_to, creation_date) " + "VALUES (%s, %s, %s, %s, current_timestamp)", [str(user_id), body, "1", str(article_id)]) dbconnection.commit() # Close the database cursor and connection. dbcursor.close() dbconnection.close() except: return pageutils.generate_page ("Invalid SQL Query", "Unable to add comment.")
def process( self, title=None, description=None, start_month=None, start_day=None, start_year=None, end_month=None, end_day=None, end_year=None, ): # Verify user is logged in. if not pageutils.is_logged_in_p(): raise cherrypy.HTTPRedirect("/login") # Make sure the title and description are present. if title == None or description == None: return self.index(missing=True, title=title, description=description) # Prepare start/end date strings. start_date = start_year + "-" + start_month + "-" + start_day end_date = None if end_year <> "" and end_month <> "" and end_day <> "": end_date = end_year + "-" + end_month + "-" + end_day # Get the user_id. user_id = str(pageutils.get_user_id()) # Insert the event into the database. try: # Connect to the database and insert the values. dbconnection = pgdb.connect(database_connect_fields) dbcursor = dbconnection.cursor() # Category value currently unused; default to 0. if end_date <> None: dbcursor.execute( "INSERT INTO events (category, author_id, creation_date, title, " + "description, start_date, end_date, display) " + "VALUES (%s, %s, current_timestamp, %s, %s, %s, %s, %s)", ["0", user_id, title, description, start_date, end_date, "1"], ) else: dbcursor.execute( "INSERT INTO events (category, author_id, creation_date, title, " + "description, start_date, display) " + "VALUES (%s, %s, current_timestamp, %s, %s, %s, %s)", ["0", user_id, title, description, start_date, "1"], ) dbconnection.commit() # Close the database cursor and connection. dbcursor.close() dbconnection.close() except: return pageutils.generate_page("Database Error", '<div class="error">Unable to add event.</div>\n') raise cherrypy.HTTPRedirect("/events/")
def process (self, body=None, subject=None, refers_to=None): # Verify user is logged in. if (not pageutils.is_logged_in_p()): raise cherrypy.HTTPRedirect ("/login/access") # FIXME: Make sure we have all of the data we need in the form. # Remove any leading or trailing spaces from comment text. if (body <> None): body = string.strip(body) if (subject <> None): subject = string.strip(subject) # Make sure refers_to, if it exists, is an integer. if (refers_to <> None): try: refers_to = str(int(refers_to)) except: return pageutils.generate_page ("Invalid Reference", "<div class=\"error\">Unable to add discussion element.</div>\n") user_id = pageutils.get_user_id() if (user_id == None): raise cherrypy.HTTPRedirect ("/login/access") # Insert the discussion / comment into the database. try: # Connect to the database and insert the values. dbconnection = pgdb.connect (database_connect_fields) dbcursor = dbconnection.cursor() # Category value currently unused; default to 0. # Is this a top-level discussion? if (refers_to == None): dbcursor.execute ("INSERT INTO discussions (category, author_id, subject, body, display, creation_date) " + "VALUES (%s, %s, %s, %s, %s, current_timestamp)", ["0", str(user_id), subject, body, "1"]) # Or is this a reply? else: dbcursor.execute ("INSERT INTO discussions (refers_to, category, author_id, subject, body, display, creation_date) " + "VALUES (%s, %s, %s, %s, %s, %s, current_timestamp)", [str(refers_to), "0", str(user_id), subject, body, "1"]) dbconnection.commit() # Close the database cursor and connection. dbcursor.close() dbconnection.close() except: return pageutils.generate_page ("Database Error", "<div class=\"error\">Unable to add discussion element.</div>\n") if (refers_to == None): raise cherrypy.HTTPRedirect ("/discussions/") else: raise cherrypy.HTTPRedirect ("/discussions/" + str(refers_to))
def processnew (self, title=None, slug=None, display=None, body=None, article_id=None, edit=False): # Verify user is logged-in admin. if (not pageutils.is_admin_p()): raise cherrypy.HTTPRedirect ("/") # If we got to this page through the /admin/articles/new form, all fields # should be filled in. If they aren't, something unexpected happened, and # we shouldn't continue processing the form. if (title == None or slug == None or display == None or body == None): return pageutils.generate_page ("Invalid Input for New Article", "Invalid Input for New Article!") else: # Remove any leading or trailing spaces. title = string.strip (title) slug = string.strip (slug) body = string.strip (body) display = string.strip (display) author_id = pageutils.get_user_id() try: # Connect to the database and insert the values. dbconnection = pgdb.connect (database_connect_fields) dbcursor = dbconnection.cursor() if (edit): if (article_id == None): return pageutils.generate_page ("No Article Id Specified", "No Article Id Specified") dbcursor.execute ("UPDATE articles SET title=%s, slug=%s, body=%s, display=%d WHERE article_id=%d", [title, slug, body, int(display), int(article_id)]) else: dbcursor.execute ("INSERT INTO articles (title, author_id, slug, body, display, creation_date) " + "VALUES (%s, %s, %s, %s, %s, current_timestamp)", [title, author_id, slug, body, display]) dbconnection.commit() # Close the database cursor and connection. dbcursor.close() dbconnection.close() except: return pageutils.generate_page ("Invalid SQL Query", "Invalid SQL Query!") raise cherrypy.HTTPRedirect ("/admin/articles/")