def show_add_organization_info_form(self, name):
    logging.debug("show_organization_html")
    if check_login(self):
        # try:
        path = os.path.join(os.path.dirname(__file__))
        path_length = path.__len__()
        final_path = path[0 : path_length - 11] + "views/htmls/show_add_organization_info_form.html"

        filters = {"name": name}
        logged_in = check_login(self)

        results, results_exist = datastore_results(
            "Organization", filters=filters, inequality_filters=None, order=None, fetch_total=1, offset=0, mem_key=None
        )

        order = "name"
        organization_results, results_exist = datastore_results(
            "Organization", filters=None, inequality_filters=None, order=order, fetch_total=1000, offset=0, mem_key=None
        )

        data = {
            "logged_in": logged_in,
            "organization_results": organization_results,
            "single_organization_results": results,
            "title_kind": "Organizations",
            "name": name,
        }

        self.response.out.write(template.render(final_path, data))
        # except:
        # logging.debug("exception")
        # show_error_html(self, "template error")
    else:
        self.redirect("/")
def show_home_page_html(self):
    logging.debug("show_home_page_html")
    # try:
    if check_login(self):
        path = os.path.join(os.path.dirname(__file__))
        path_length = path.__len__()
        final_path = path[0 : path_length - 11] + "views/htmls/member_home_html.html"

        logging.debug("path = " + path)
        logging.debug("final_path = " + final_path)

        session = get_current_session()
        email = session["email"]
        logged_in = check_login(self)
        filters = {"email": email}

        member_results, member_results_exist = datastore_results(
            "Member", filters=filters, inequality_filters=None, order=None, fetch_total=1000, offset=0, mem_key=None
        )
        finished_organizations_list = []
        unfinished_organizations_list = []
        original_organizations_list = []
        for result in member_results:
            original_organizations_list = result.orgs_list

        for name in original_organizations_list:
            filters = {"name": name}

            results, results_exist = datastore_results(
                "Organization",
                filters=filters,
                inequality_filters=None,
                order=None,
                fetch_total=1000,
                offset=0,
                mem_key=None,
            )
            for result in results:
                city = result.city
                if city:
                    finished_organizations_list.append(name)
                else:
                    unfinished_organizations_list.append(name)

        error_message = "MEMBER HOME PAGE... CONTROL NOT FINISHED"
        data = {
            "error_message": error_message,
            "title_kind": "About Me:",
            "member_results": member_results,
            "logged_in": logged_in,
            "finished_organizations_list": finished_organizations_list,
            "unfinished_organizations_list": unfinished_organizations_list,
        }

        self.response.out.write(template.render(final_path, data))
        # except:
        # logging.debug("exception")
        # show_error_html(self, "template error")
    else:
        self.redirect("/")
def show_contact_html(self, name):
    logging.debug("show_contact_html")
    #try:
    path = os.path.join(os.path.dirname(__file__))
    path_length = path.__len__()
    final_path = path[0:path_length-11] + 'views/htmls/show_contact_html.html'
    
    filters = {
        "first_name": name,
    }
    logged_in = check_login(self)
    
    results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
    
    order = "name"
    contact_results, results_exist = datastore_results("Member", filters = None, inequality_filters = None, order = order, fetch_total = 1000, offset = 0, mem_key = None)
    
    
    data = {
        "logged_in": logged_in,
        "contact_results": contact_results,
        "single_contact_results": results,
        "title_kind": "Contacts",
    }
    

    self.response.out.write(template.render(final_path, data))         
    #except:
        #logging.debug("exception")
        #show_error_html(self, "template error")
Exemplo n.º 4
0
 def post(self):
     form = SignInForm(self.request.POST)
     if not form.validate():
         path = os.path.join(os.path.dirname(__file__))
         path_length = path.__len__()
         final_path = path + '/views/htmls/member_login_form.html'
         #print final_path
         data = {
             'form': form,
         }
         self.response.out.write(template.render(final_path, data))         
     else:
         login_check = login_member(self)
         email = self.request.get("email")
         password = self.request.get("password")
         hashed_password = get_hash(password)
         filters = {
             "email": email,
             "password": hashed_password,
         }
         session = get_current_session()
         session.clear()
         
         results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None)
         if results_exist:
             session = get_current_session()
             session['member'] = True
             session['email'] = email
             
             if login_check:
             ### check for first name, if first name, go to main page
                 session = get_current_session()
                 session['member'] = True
                 
                 email = session['email']
                 filters = {
                     "email": email,
                 }
                 
                 results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
                 first_name = None
                 if results_exist:
                     for result in results:
                         first_name = result.first_name
                         
                 if first_name is None:
                     self.redirect('/?' + urllib.urlencode({'member_info': True}))
                 else:
                     self.redirect('/?' + urllib.urlencode({'home_page': True}))
                 
                 
         else:
             self.redirect('/?' + urllib.urlencode({'member_login': True}))
def show_organizations_html(self):
    logging.debug("show_tags_html")
    #try:
    path = os.path.join(os.path.dirname(__file__))
    path_length = path.__len__()
    final_path = path[0:path_length-11] + 'views/htmls/show_organizations_html.html'
    
    logging.debug("path = " + path)
    logging.debug("final_path = " + final_path)
    
    logged_in = check_login(self)
    order = "name"
    results, results_exist = datastore_results("Organization", filters = None, inequality_filters = None, order = order, fetch_total = 1000, offset = 0, mem_key = None)
    
    
    data = {
        "logged_in": logged_in,
        "organization_results": results,
        "title_kind": "Organizations",
    }
    
    self.response.out.write(template.render(final_path, data))         
    #except:
        #logging.debug("exception")
        #show_error_html(self, "template error")
def put_tag(self, tag):
    logging.debug("put_tag")
    if check_login(self):
            
        
        continue_boolean = False
        email = ""
        #try:
        session = get_current_session()
        email = session['email']
        continue_boolean = True
        #except:
        #logging.debug("gaesessions exception, do not continue")
        #continue_boolean = False
        #show_error_html(self, "session error")
        
        tag = tag.lower()
        tag = tag.strip()
        if continue_boolean:
            ### check db, if not in db put tag
            filters = {
                "tag": tag,
            }
            
            results, results_exist = datastore_results("Tag", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
            if results_exist:
                logging.debug("tag already exists")
            else:
                t = model.Tag(tag = tag)
                t.put()
                
    else:
        self.redirect("/")
def plus_one_constraints(self, post_id):
    logging.debug("put_post_plus_one")
    if check_login(self):
        session = get_current_session()
        email = session["email"]

        filters = {"post_id": post_id}

        results, results_exist = datastore_results(
            "PlusMinusConstraints",
            filters=filters,
            inequality_filters=None,
            order=None,
            fetch_total=1,
            offset=0,
            mem_key=None,
        )
        points = 0
        if results_exist:
            for result in results:
                points = result.points

        # print points
        if points > 0:
            return False
        else:
            return True

    else:
        self.redirect("/")
def put_organization_info(self):
    logging.debug("put_organization_info")
    if check_login(self):
        
        continue_boolean = False
        email = ""
        #try:
        session = get_current_session()
        email = session['email']
        continue_boolean = True
        #except:
            #logging.debug("gaesessions exception, do not continue")
            #continue_boolean = False
            #show_error_html(self, "session error")
            
            
        if continue_boolean:
            name = self.request.get("name")
            organization = self.request.get("organization")
            email = self.request.get("email")
            street_address = self.request.get("street_address")
            city = self.request.get("city")
            state = self.request.get("state")
            country = self.request.get("country")
            notes = self.request.get("notes")
            address = street_address + " " + city + " " + state + " " + country
            print address

            
            if not state:
                address = street_address + " " + city + " " + country
            
            g = geocoders.OpenMapQuest()
            place, (lat, lng) = g.geocode(address)  
                
            filters = {
                "name": name,
            }
            results, results_exist = datastore_results("Organization", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
            
            key = None
            for result in results:
                key = result.key()
                
            if key is not None:                    
                o = model.Organization.get(key)
                o.email = email
                o.address = address
                o.city = city
                o.state = state
                o.country = country
                o.notes = notes
                lat_string = str(lat)
                lng_string = str(lng)
                o.lat = lat_string
                o.lng = lng_string
                o.put()
                
    else:
        self.redirect("/")
def show_single_tag_html(self, tag):
    logging.debug("show_single_tag_html")
    path = os.path.join(os.path.dirname(__file__))
    path_length = path.__len__()
    final_path = path[0:path_length-11] + 'views/htmls/show_single_tag.html'
    
    logging.debug("path = " + path)
    logging.debug("final_path = " + final_path)
    logged_in = check_login(self)
    filters = {
        "tags_list": tag,
    }
    results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
    
    no_results = False
    if results_exist == False:
        no_results = True
        delete_tag(tag)
    data = {
        "logged_in": logged_in,
        "tag_results": results,
        "title_kind": "All results with: " + tag,
        "no_results": no_results,
    }
    
    self.response.out.write(template.render(final_path, data))         
    #except:
        #logging.debug("exception")
        #show_error_html(self, "template error")
def put_organization(self, name):
    logging.debug("put_organization")
    if check_login(self):
        continue_boolean = False
        email = ""
        # try:
        session = get_current_session()
        email = session["email"]
        continue_boolean = True
        # except:
        # logging.debug("gaesessions exception, do not continue")
        # continue_boolean = False
        # show_error_html(self, "session error")

        if continue_boolean:
            ### check db, if not in db put tag
            filters = {"name": name}

            results, results_exist = datastore_results(
                "Organization",
                filters=filters,
                inequality_filters=None,
                order=None,
                fetch_total=1,
                offset=0,
                mem_key=None,
            )
            if results_exist:
                logging.debug("tag already exists")
            else:
                o = model.Organization(name=name, added_by=email)
                o.put()

    else:
        self.redirect("/")
def show_maps_html(self):
    logging.debug("show_maps_html")
    #if login_check:
        #try:
    path = os.path.join(os.path.dirname(__file__))
    path_length = path.__len__()
    final_path = path[0:path_length-11] + 'views/htmls/main_maps_html.html'
    
    logging.debug("path = " + path)
    logging.debug("final_path = " + final_path)
    logged_in = check_login(self)
        
    results, results_exist = datastore_results("Organization", filters = None, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None)
    
    data = {
        "logged_in": logged_in,
        "title_kind": "Maps",
        "organization_results": results,
    }
    
    self.response.out.write(template.render(final_path, data))         
        #except:
            #logging.debug("exception")
            #show_error_html(self, "template error")
    #else:
        #self.redirect('/?' + urllib.urlencode({'member_login': True}))
        
        
def check_invite_email_and_hash(email, invite_hash):
    logging.debug("check_invite_email_and_hash")
    filters = {
        "email": email,
        "invite_hash": invite_hash,
    }
    results, results_exist = datastore_results("Invites", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
    return results_exist
def show_index_html(self):
    logging.debug("show_index_html")
    session = get_current_session()
    staff_boolean = False
    try:
        staff_boolean = session['staff']
    
    except:
        staff_boolean = False
        
    if staff_boolean:
        try:
            path = os.path.join(os.path.dirname(__file__))
            path_length = path.__len__()
            final_path = path[0:path_length-11] + 'views/htmls/index_staff.html'
            
            logging.debug("path = " + path)
            logging.debug("final_path = " + final_path)
            
            logged_in = check_login(self)
                
                
            data = {
                "logged_in": logged_in,
            }
            
            
            self.response.out.write(template.render(final_path, data))         
        except:
            logging.debug("exception")
            show_error_html(self, "template error")
    else:
        #try:
        path = os.path.join(os.path.dirname(__file__))
        path_length = path.__len__()
        final_path = path[0:path_length-11] + 'views/htmls/index.html'
        
        logging.debug("path = " + path)
        logging.debug("final_path = " + final_path)
        
        logged_in = check_login(self)
            
        results, results_exist = datastore_results("Post", filters = None, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None)
            
        data = {
            "logged_in": logged_in,
            "post_results": results,
            "title_kind": "Timeline",
        }
        
        
        
        
        
        self.response.out.write(template.render(final_path, data))         
        #except:
            #logging.debug("exception")
            #show_error_html(self, "template error")
def email_to_rep_points(email):
    filters = {
        "email": email
    }
    results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None)
    rep_points = ""
    for result in results:
        rep_points = result.rep_points
    return rep_points
def email_to_name(request):
    filters = {
        "email": request
    }
    results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None)
    name = ""
    for result in results:
        name = result.first_name
    return name
def show_add_post_form(self, post_id = None):
    logging.debug("show_index_html")
    if check_login(self):
        #try:
        session = get_current_session()
        email = session['email']
        
        old_entry = None
        old_tags = None
        old_title = None
        old_hash = None
        
        if post_id:
            filters = {
                "email": email,
                "post_id": post_id,
            }
            results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
            
            if not results_exist:
                return False
                
            for result in results:
                old_entry = result.entry
                old_tags = result.tags
                old_title = result.title
                old_hash = result.post_id
            
            
            
        path = os.path.join(os.path.dirname(__file__))
        path_length = path.__len__()
        final_path = path[0:path_length-11] + 'views/htmls/add_post.html'
        #print final_path
        
        
        logging.debug("path = " + path)
        logging.debug("final_path = " + final_path)

        logged_in = check_login(self)
        data = {
            "logged_in": logged_in,
            "title_kind": "What makes a good post",
            "old_entry": old_entry,
            "old_title": old_title,
            "old_tags": old_tags,
            "old_hash": old_hash,
        }
            
            
        self.response.out.write(template.render(final_path, data))         
        #except:
            #logging.debug("exception")
        #show_error_html(self, "template error")
    else:
        self.redirect("/")
def put_post_flag(self):
    logging.debug("put_post_flag")
    if check_login(self):

        continue_boolean = False
        email = ""
        # try:
        session = get_current_session()
        email = session["email"]
        continue_boolean = True
        # except:
        # logging.debug("gaesessions exception, do not continue")
        # continue_boolean = False
        # show_error_html(self, "session error")

        if continue_boolean:
            post_id = self.request.get("post_id")

            filters = {"post_id": post_id}
            results, results_exist = datastore_results(
                "Post", filters=filters, inequality_filters=None, order=None, fetch_total=1, offset=0, mem_key=None
            )
            key = None
            points = 0
            for result in results:
                key = result.key()
                post_id = result.post_id
                email = result.email
                title = result.title
                tags = result.tags
                entry = result.entry
                tags_list = result.tags_list
                timestamp = result.timestamp
                points = result.points
                user_email = session["email"]

                p = model.FlagPost(
                    post_id=post_id,
                    email=email,
                    title=title,
                    tags=tags,
                    entry=entry,
                    tags_list=tags_list,
                    timestamp=timestamp,
                    points=points,
                    added_by=user_email,
                )
                p.put()
                db.delete(key)
            return post_id

    else:
        self.redirect("/")
def put_member_sign_up(self):
    logging.debug("sign_in_user")
    email = self.request.get("email")
    password = self.request.get("password")
    password2 = self.request.get("password2")
    invite_hash = self.request.get("invite_hash")
    
    filters = {
        "email": email,
    }
    
    results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
    
    if results_exist:
        show_error_html(self, "email already exists error")
        return False
        
    
    if password == password2:
        category = "Volunteer"
        try:
            
            if check_invite_email_and_hash(email = email, invite_hash = invite_hash):
                hashed_password = get_hash(password)
                m = model.Member(email = email, password = hashed_password, category = category, skills_list = [""])
                m.put()
                delete_invite(invite_hash = invite_hash, invite_email = email)
            else:
                show_error_html(self, "Not the correct email for this invite.")
                logging.debug("Incorrect email for invite")
                return False
        except:
            logging.debug("datastore error")
            show_error_html(self, "database error")
            
            
        try:
            session = get_current_session()
            session['email'] = email
            session['member'] = True
        except:
            logging.debug("gaesessions error")
            show_error_html(self, "session error")
        
        
        return True
    else:
        show_error_html(self, "The passwords are not the same, press back and try again.")
        
def show_post_html(self, post_id):
    logging.debug("show_post_html")
    #try:
    path = os.path.join(os.path.dirname(__file__))
    path_length = path.__len__()
    final_path = path[0:path_length-11] + 'views/htmls/show_post.html'
    
    logging.debug("path = " + path)
    logging.debug("final_path = " + final_path)
                
    filters = {
        "post_id": post_id,
    }
    
    results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
    
    
    filters = {
        "post_id": post_id,
    }
    
    comment_results, comment_results_exist = datastore_results("Comment", filters = filters, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None)
    login_check = check_login(self)

    data = {
        "post_results": results,
        "logged_in": login_check,
        "comment_results": comment_results,
        "title_kind": "About Post",
     }
    
    
    self.response.out.write(template.render(final_path, data))         
    #except:
        #logging.debug("exception")
        #show_error_html(self, "template error")
def check_post_duplicates(post_id):
    logging.debug("check_post_duplicates")
    session = get_current_session()
    email = session['email']
    filters = {
        "email": email,
        "post_id": post_id,
    }
    results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
    if not results_exist:
        return False
    
    for result in results:
        key = result.key()
        return key
def delete_invite(invite_hash, invite_email):
    logging.debug("check_post_duplicates")
    session = get_current_session()
    email = session['email']
    filters = {
        "invite_hash": invite_hash,
        "email": invite_email,
    }
    results, results_exist = datastore_results("Invites", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
    if not results_exist:
        return False
    
    for result in results:
        key = result.key()
        db.delete(key)
        return True
def check_login_2():
    logging.debug("check_login")
    logged_in = False
    session = get_current_session()
    
    try:
        if session['member'] == True:
            email = session['email']
            logging.debug("session member is True")
            logged_in = True
        else:
            logging.debug("session member is False")
            logged_in = False
    except:
        logging.debug("session member exception, gaesession does not exist, return False")
        logged_in = False
        
        
     ####
     #
     #  Uncomment below if gaesessions seems to be malfunctioning, this will give you a look at the datastore directly
     #  
     ####
     
     
    #if logged_in = False:
            
        #name = self.request.get("hub_name")
        #password = self.request.get("password")
        
        #filters = { "name": name, "password": password }
        #results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None)
        #if results_exist:
            #logged_in = True
        #else:
            #logged_in = False    
    if logged_in:
        filters = {
            "email": email,
        }
        results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
        if results_exist:
            logged_in = True
        else:
            logged_in = False
    return logged_in
def delete_tag(tag):
    logging.debug("check_post_duplicates")
    if check_login_2():
        session = get_current_session()
        #email = session['email']
        filters = {
            "tag": tag,
        }
        results, results_exist = datastore_results("Tag", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
        if not results_exist:
            return False
        
        for result in results:
            key = result.key()
            db.delete(key)
            return True
    else:
        return False
def put_comment(self):
    logging.debug("put_post")
    if check_login(self):
        
        continue_boolean = False
        email = ""
        #try:
        session = get_current_session()
        email = session['email']
        continue_boolean = True
        #except:
        #logging.debug("gaesessions exception, do not continue")
        #continue_boolean = False
        #show_error_html(self, "session error")
        comment = self.request.get("comment")
        post_id = self.request.get("post_id")
        
        if not comment:
            logging.debug("No comment entered")
            return False, post_id
        if continue_boolean:
            ### check db, if not in db put tag
            new_hash = get_hash()
            timestamp = get_date_time()
        
            c = model.Comment(comment = comment, email = email, comment_id = new_hash, post_id = post_id, timestamp = timestamp)
            c.put()
            filters = {
                "email": email,
            }
            results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
            if results_exist:
                for result in results:
                    key = result.key()
                    points = result.rep_points
                    
                    member = model.Member.get(key)
                    member.rep_points = points + 5
                    member.put()
            return True, post_id
                
    else:
        self.redirect("/")
def delete_comment(comment_id):
    logging.debug("delete_comment")
    if check_login_2():
        session = get_current_session()
        email = session['email']
        filters = {
            "email": email,
            "comment_id": comment_id,
        }
        results, results_exist = datastore_results("Comment", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
        if not results_exist:
            return False
        
        for result in results:
            key = result.key()
            db.delete(key)
            return True
    else:
        return False
def put_comment_flag(self):
    logging.debug("put_comment_flag")
    
    continue_boolean = False
    email = ""
    #try:
    session = get_current_session()
    email = session['email']
    continue_boolean = True
    #except:
        #logging.debug("gaesessions exception, do not continue")
        #continue_boolean = False
        #show_error_html(self, "session error")
        
        
    if continue_boolean:
        comment_id = self.request.get("comment_id")

        filters = {
            "comment_id": comment_id,
        }
        results, results_exist = datastore_results("Comment", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
        key = None
        points = 0
        for result in results:
            key = result.key()
            comment = result.comment
            email = result.email
            comment_id = result.comment_id
            post_id = result.post_id
            timestamp = result.timestamp
            points = result.points
            user_email = session['email']
            
            
            p = model.FlagComment(post_id = post_id, email = email, comment = comment, comment_id = comment_id, timestamp = timestamp, points=points, added_by = user_email)
            p.put()
            db.delete(key)
        return post_id
def login_member(self):
    logging.debug("login_member")
    
    email = self.request.get("email")
    password = self.request.get("password")
    
    
    logging.debug("email = " + email)
    logging.debug("password = "******"hashed_password")
    #print hashed_password
    filters = {
        "email": email,
        "password": hashed_password,
    }
        
    results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
    category = ""
    for result in results:
        category = result.category
        
    try:
        session = get_current_session()
        session['member'] = True
        session['email'] = email
        if category == "Staff":
            session['staff'] = True
    except:
        logging.debug("gaesessions exception")
        show_error_html(self, "session error")
    
    if results_exist:
        return True
    else:
        return False
def show_comment_form(self, post_id):
    logging.debug("show_comment_form")
    if check_login(self):
        #try:
        path = os.path.join(os.path.dirname(__file__))
        path_length = path.__len__()
        final_path = path[0:path_length-11] + 'views/htmls/comment_form.html'
        
        logging.debug("path = " + path)
        logging.debug("final_path = " + final_path)
        
        logged_in = check_login(self)
        
                        
        filters = {
            "post_id": post_id,
        }
        
        results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
        
        
        
        data = {
            "logged_in": logged_in,
            "post_id": post_id,
            "show_comment_form": True,
            "post_results": results,
        }
        
        
        self.response.out.write(template.render(final_path, data))         
            #except:
                #logging.debug("exception")
            #show_error_html(self, "template error")
    else:
        self.redirect("/")
def comment_minus_one_constraints(self, comment_id):
    logging.debug("comment_minus_one_constraints")
    if check_login(self):
        session = get_current_session()
        email = session['email']
        
        filters = {
            "comment_id": comment_id,
            "email": email,
        }
        
        results, results_exist = datastore_results("CommentPlusMinusConstraints", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
        points = 0
        if results_exist:
            for result in results:
                points = result.points
            
        #print points
        if points < 0:
            return False
        else:
            return True
    else:
        return False
def put_post_minus_one(self):
    logging.debug("put_post_minus_one")
    if check_login(self):
        continue_boolean = False
        email = ""
        #try:
        session = get_current_session()
        email = session['email']
        continue_boolean = True
        #except:
            #logging.debug("gaesessions exception, do not continue")
            #continue_boolean = False
            #show_error_html(self, "session error")
            
            
        if continue_boolean:
            post_id = self.request.get("post_id")
            post_email = ""
            if minus_one_constraints(self, post_id):
                    

                filters = {
                    "post_id": post_id,
                }
                results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
                key = None
                points = 0
                for result in results:
                    key = result.key()
                    post_email = result.email
                    points = result.points
                
                if key is not None:
                    p = model.Post.get(key)
                    if points is None:
                        points = 0
                    p.points = points - 1
                    p.put()
                    
                    filters = {
                        "post_id": post_id,
                        "email": email,
                    }
                    
                    results, results_exist = datastore_results("PlusMinusConstraints", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
                    points = 0
                    
                    if results_exist:
                        for result in results:
                            points = result.points
                            key = result.key()
                            pm = model.PlusMinusConstraints.get(key)
                            pm.points = points - 1
                            pm.put()

                    
                    else:
                        pm = model.PlusMinusConstraints(email = email, post_id = post_id, points = points - 1)
                        pm.put()
                            
                        filters = {
                            "email": post_email,
                        }
                        results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None)
                        if results_exist:
                            for result in results:
                                key = result.key()
                                points = result.rep_points
                    
                                member = model.Member.get(key)
                                member.rep_points = points - 4
                                member.put()
                    
            return post_id
    else:
        self.redirect("/")