def send_contact(self,
                     submit,
                     email,
                     subject,
                     email_text,
                     recaptcha_challenge_field=None,
                     recaptcha_response_field=None):
        email = ensure_string_no_longer(email, 250)
        subject = ensure_string_no_longer(subject, 50)
        email_text = ensure_string_no_longer(email_text, 500)

        remoteip = environ['REMOTE_ADDR']

        cResponse = captcha.submit(recaptcha_challenge_field,
                                   recaptcha_response_field,
                                   "6LeugrwSAAAAAMyvJJL8DKIyUa0sTn5Ywq5WDFlV",
                                   remoteip)

        if cResponse.is_valid and validate_email(email) and len(
                email_text.strip()) > 0:
            #send email
            mail.send_mail(sender="Brave Octopus Member <" + email + ">",
                           to="*****@*****.**",
                           subject=subject,
                           body=email_text)
            redirect("/index")
        else:
            return self.contact(cResponse.error_code, subject, email,
                                email_text, "Make sure your email is correct.")
    def do_create_story(self,
                        submit=None,
                        story_title=None,
                        own_story=None,
                        story_tags=None,
                        story_description=None,
                        recaptcha_challenge_field=None,
                        recaptcha_response_field=None):
        story_title = ensure_string_no_longer(story_title, 100).strip()
        story_tags = ensure_string_no_longer(story_tags, 100)
        story_description = ensure_string_no_longer(story_description, 500)
        remoteip = environ['REMOTE_ADDR']

        cResponse = captcha.submit(recaptcha_challenge_field,
                                   recaptcha_response_field,
                                   "6LeugrwSAAAAAMyvJJL8DKIyUa0sTn5Ywq5WDFlV",
                                   remoteip)
        story = get_story_or_none(story_title)
        if cResponse.is_valid and story == None and len(story_title) > 0:
            story = Story()
            story.account = get_current_account(
            ) if own_story == "single_owner" else None
            story.title = story_title
            story.date = datetime.datetime.now()
            story.description = story_description
            if story_tags != None:
                tag_list = []
                for s in story_tags.split():
                    if validate_letters_and_numbers(s):
                        increment_tag_count(s)
                        tag_list.append(str.lower(s))
                story.tags = unique(tag_list)
            story.put()
            redirect("/edit_story_page?title=" + story_title +
                     "&page=FrontPage")

        else:
            error_message = "Please verify you are a human by completing out the captcha below."
            if story != None:
                error_message = "Cannot create story, because it already exists!"
            if len(story_title) == 0:
                error_message = "You must have a story title"
            return self.create_story(None, story_title, story_description,
                                     story_tags, cResponse.error_code,
                                     error_message, own_story)
    def do_create_story(
        self,
        submit=None,
        story_title=None,
        own_story=None,
        story_tags=None,
        story_description=None,
        recaptcha_challenge_field=None,
        recaptcha_response_field=None,
    ):
        story_title = ensure_string_no_longer(story_title, 100).strip()
        story_tags = ensure_string_no_longer(story_tags, 100)
        story_description = ensure_string_no_longer(story_description, 500)
        remoteip = environ["REMOTE_ADDR"]

        cResponse = captcha.submit(
            recaptcha_challenge_field, recaptcha_response_field, "6LeugrwSAAAAAMyvJJL8DKIyUa0sTn5Ywq5WDFlV", remoteip
        )
        story = get_story_or_none(story_title)
        if cResponse.is_valid and story == None and len(story_title) > 0:
            story = Story()
            story.account = get_current_account() if own_story == "single_owner" else None
            story.title = story_title
            story.date = datetime.datetime.now()
            story.description = story_description
            if story_tags != None:
                tag_list = []
                for s in story_tags.split():
                    if validate_letters_and_numbers(s):
                        increment_tag_count(s)
                        tag_list.append(str.lower(s))
                story.tags = unique(tag_list)
            story.put()
            redirect("/edit_story_page?title=" + story_title + "&page=FrontPage")

        else:
            error_message = "Please verify you are a human by completing out the captcha below."
            if story != None:
                error_message = "Cannot create story, because it already exists!"
            if len(story_title) == 0:
                error_message = "You must have a story title"
            return self.create_story(
                None, story_title, story_description, story_tags, cResponse.error_code, error_message, own_story
            )
    def send_contact(
        self, submit, email, subject, email_text, recaptcha_challenge_field=None, recaptcha_response_field=None
    ):
        email = ensure_string_no_longer(email, 250)
        subject = ensure_string_no_longer(subject, 50)
        email_text = ensure_string_no_longer(email_text, 500)

        remoteip = environ["REMOTE_ADDR"]

        cResponse = captcha.submit(
            recaptcha_challenge_field, recaptcha_response_field, "6LeugrwSAAAAAMyvJJL8DKIyUa0sTn5Ywq5WDFlV", remoteip
        )

        if cResponse.is_valid and validate_email(email) and len(email_text.strip()) > 0:
            # send email
            mail.send_mail(
                sender="Brave Octopus Member <" + email + ">",
                to="*****@*****.**",
                subject=subject,
                body=email_text,
            )
            redirect("/index")
        else:
            return self.contact(cResponse.error_code, subject, email, email_text, "Make sure your email is correct.")
    def save_story_page(
        self,
        submit=None,
        title=None,
        page=None,
        page_text=None,
        action_link_0=None,
        action_text_0=None,
        action_link_1=None,
        action_text_1=None,
        action_link_2=None,
        action_text_2=None,
        action_link_3=None,
        action_text_3=None,
        action_link_4=None,
        action_text_4=None,
        recaptcha_challenge_field=None,
        recaptcha_response_field=None,
    ):
        page_text = ensure_string_no_longer(page_text, 2000)
        do_access_check_by_title(title)

        remoteip = environ["REMOTE_ADDR"]

        cResponse = captcha.submit(
            recaptcha_challenge_field, recaptcha_response_field, "6LeugrwSAAAAAMyvJJL8DKIyUa0sTn5Ywq5WDFlV", remoteip
        )

        action_link_0 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_0) else action_link_0.strip(), 30
        )
        action_link_1 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_1) else action_link_1.strip(), 30
        )
        action_link_2 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_2) else action_link_2.strip(), 30
        )
        action_link_3 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_3) else action_link_3.strip(), 30
        )
        action_link_4 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_4) else action_link_4.strip(), 30
        )

        action_text_0 = ensure_string_no_longer(None if action_link_0 == None else action_text_0.strip(), 200)
        action_text_1 = ensure_string_no_longer(None if action_link_1 == None else action_text_1.strip(), 200)
        action_text_2 = ensure_string_no_longer(None if action_link_2 == None else action_text_2.strip(), 200)
        action_text_3 = ensure_string_no_longer(None if action_link_3 == None else action_text_3.strip(), 200)
        action_text_4 = ensure_string_no_longer(None if action_link_4 == None else action_text_4.strip(), 200)

        clean_page_text = "".join(BeautifulSoup.BeautifulSoup(page_text).findAll(text=True))

        links_text = filter(None, [action_text_0, action_text_1, action_text_2, action_text_3, action_text_4])
        links = filter(None, [action_link_0, action_link_1, action_link_2, action_link_3, action_link_4])
        links_count = []
        for i in range(0, len(links)):
            links_count.append("0")

        if cResponse.is_valid:

            p = get_page_by_title_and_page_or_none(title, page)
            p = p if p != None else StoryPage()

            story = get_story_or_none(title)

            if story == None:
                redirect("/create_story?title=" + title)

            story.date = datetime.datetime.now()
            story.put()

            p.story = story
            p.title = title
            p.name = page
            p.page_text = clean_page_text
            p.page_link_text = links_text
            p.page_link_count = links_count
            p.page_link = links
            p.put()
            redirect("/story?title=" + title + "&page=" + page)
        else:
            pl = zip(links_text, links, range(0, len(links_text)))
            return self.edit_story_page(title, page, clean_page_text, pl, None, cResponse.error_code)
    def save_story_page(self,
                        submit=None,
                        title=None,
                        page=None,
                        page_text=None,
                        action_link_0=None,
                        action_text_0=None,
                        action_link_1=None,
                        action_text_1=None,
                        action_link_2=None,
                        action_text_2=None,
                        action_link_3=None,
                        action_text_3=None,
                        action_link_4=None,
                        action_text_4=None,
                        recaptcha_challenge_field=None,
                        recaptcha_response_field=None):
        page_text = ensure_string_no_longer(page_text, 2000)
        do_access_check_by_title(title)

        remoteip = environ['REMOTE_ADDR']

        cResponse = captcha.submit(recaptcha_challenge_field,
                                   recaptcha_response_field,
                                   "6LeugrwSAAAAAMyvJJL8DKIyUa0sTn5Ywq5WDFlV",
                                   remoteip)

        action_link_0 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_0) else
            action_link_0.strip(), 30)
        action_link_1 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_1) else
            action_link_1.strip(), 30)
        action_link_2 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_2) else
            action_link_2.strip(), 30)
        action_link_3 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_3) else
            action_link_3.strip(), 30)
        action_link_4 = ensure_string_no_longer(
            None if is_all_whitespace_or_none(action_link_4) else
            action_link_4.strip(), 30)

        action_text_0 = ensure_string_no_longer(
            None if action_link_0 == None else action_text_0.strip(), 200)
        action_text_1 = ensure_string_no_longer(
            None if action_link_1 == None else action_text_1.strip(), 200)
        action_text_2 = ensure_string_no_longer(
            None if action_link_2 == None else action_text_2.strip(), 200)
        action_text_3 = ensure_string_no_longer(
            None if action_link_3 == None else action_text_3.strip(), 200)
        action_text_4 = ensure_string_no_longer(
            None if action_link_4 == None else action_text_4.strip(), 200)

        clean_page_text = ''.join(
            BeautifulSoup.BeautifulSoup(page_text).findAll(text=True))

        links_text = filter(None, [
            action_text_0, action_text_1, action_text_2, action_text_3,
            action_text_4
        ])
        links = filter(None, [
            action_link_0, action_link_1, action_link_2, action_link_3,
            action_link_4
        ])
        links_count = []
        for i in range(0, len(links)):
            links_count.append('0')

        if cResponse.is_valid:

            p = get_page_by_title_and_page_or_none(title, page)
            p = p if p != None else StoryPage()

            story = get_story_or_none(title)

            if story == None:
                redirect("/create_story?title=" + title)

            story.date = datetime.datetime.now()
            story.put()

            p.story = story
            p.title = title
            p.name = page
            p.page_text = clean_page_text
            p.page_link_text = links_text
            p.page_link_count = links_count
            p.page_link = links
            p.put()
            redirect("/story?title=" + title + "&page=" + page)
        else:
            pl = zip(links_text, links, range(0, len(links_text)))
            return self.edit_story_page(title, page, clean_page_text, pl, None,
                                        cResponse.error_code)