Ejemplo n.º 1
0
    def put(self, theme_id):
        data = Theme.parser.parse_args()

        theme = ThemeModel.find_by_id(theme_id)

        if theme is None:  # Create a new theme if it does not exist in the database
            theme = ThemeModel(**data)
        else:  # Update the theme if it exists in the database
            theme.theme_name = data['theme_name']
            theme.theme_update = datetime.now()

        theme.save_to_db()

        return theme.json()
Ejemplo n.º 2
0
    def post(self):
        # parse_args() return only arguments added by add_argument as Namespace
        # Any missing added argument will stop and return help message to the browser
        data = Theme.parser.parse_args()

        # data namespace is rolled into one argument (**data)
        theme = ThemeModel(**data)

        try:
            theme.save_to_db()
        except:
            return {"message": "An error occurred inserting the item."}, 500

        return theme.json(), 201
Ejemplo n.º 3
0
    def put(self, year, week):
        data = Theme.parser.parse_args()

        theme = ThemeModel.find_by_week(year, week)

        if theme is None:
            theme = ThemeModel(year, week, **data)
        else:
            theme.week_focus = data['week_focus']
            theme.month = data['month']
            theme.month_theme = data['month_theme']

        theme.save_to_db()

        return theme.json()
Ejemplo n.º 4
0
    def post(self, year, week):
        if ThemeModel.find_by_week(year, week):
            return {
                'message': "A theme for week '{}' already exists.".format(week)
            }, 400

        data = Theme.parser.parse_args()
        theme = ThemeModel(year, week, **data)

        try:
            theme.save_to_db()
        except:
            return {"message": "An error occurred inserting the Theme."}, 500

        return theme.json(), 201  # created
Ejemplo n.º 5
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."