Пример #1
0
    def update_theme(release_time, theme, theme_inspire, theme_author):
        # don't allow themes to be edited after 5 minutes prior to it's release time.
        if (datetime.now() - release_time > timedelta(minutes=5)):
            return "What has past is past. Live the present, anticipate the future, and embrace the past"

        if (release_time.hour != 6 and release_time.hour != 20
            ) or release_time.minute != 30 or release_time.second != 0:
            return "Invalid release time."

        by_release_time = ThemeModel.find_by_release_time(release_time)
        if not by_release_time:
            return "Create theme for the release time first."

        by_theme = ThemeModel.find_by_theme(theme)
        if by_theme:
            if by_theme.id != by_release_time.id:
                return "Theme attempting to edit is already taken. Try a new theme."

        # update
        by_release_time.theme = theme
        by_release_time.theme_inspire = theme_inspire
        by_release_time.theme_author = theme_author
        try:
            by_release_time.save_to_db()
        except:
            return "Error saving updated theme."
        return ""
Пример #2
0
    def create_theme(release_time, theme, theme_inspire, theme_author):
        if (release_time.hour != 6 and release_time.hour != 20
            ) or release_time.minute != 30 or release_time.second != 0:
            return "Incorrect release time."
        if ThemeModel.find_by_release_time(release_time):
            return "Theme is already there for that time! Try PUT for edit."
        if ThemeModel.find_by_theme(theme):
            return "Theme has alrady been used."

        try:
            new_theme = ThemeModel(release_time, theme, theme_inspire,
                                   theme_author)
            new_theme.save_to_db()
            return ""
        except:
            return "Error in creating and saving theme."
Пример #3
0
 def filter_by_theme(theme):
     """
     checks if input is valid by alphabet or number, and not blank
     returns all the post models for that theme
     """
     if not theme:
         return "Theme is needed", None
     theme_nospace = theme.replace(" ", "")
     if not theme_nospace.isalnum():
         return "Theme should only be consisted of alphabets, numbers, and spaces", None
     if not ThemeModel.find_by_theme(theme):
         return "Theme doesn't exist.", None
     try:
         return "", PostModel.filter_by_theme(theme)
     except:
         return "Error in getting most saved", None
Пример #4
0
 def update_theme(release_time, theme, theme_inspire, theme_author):
     if (release_time.hour != 6 and release_time.hour != 20
         ) or release_time.minute != 30 or release_time.second != 0:
         return "Incorrect release time."
     if ThemeModel.find_by_release_time(release_time):
         return "Theme is already there for that time! Try PUT for edit."
     target_theme = ThemeModel.find_by_theme(theme)
     if not target_theme:
         return "Theme could not be found."
     target_theme.release_time = release_time
     target_theme.theme = theme
     target_theme.theme_inspire = theme_inspire
     target_theme.theme_author = theme_author
     try:
         target_theme.save_to_db()
     except:
         return "Error saving updated theme."
     return ""
Пример #5
0
    def create_post(theme, anonymity, writer_id, content):
        # check if that theme exists
        # check if that username exists
        # check if content is less than characters
        writer = UserModel.find_by_id(writer_id)
        if not ThemeModel.find_by_theme(theme):
            return "The post's theme doesn't exist.", None
        if not writer:
            return "The writer is not a user", None
        if len(content) > 150:
            return "The content is too long", None

        try:
            new_post = PostModel(theme, anonymity, writer_id, content)
            new_post.save_to_db()
        except:
            return "Error saving to db", None

        return ""