Пример #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()
Пример #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
Пример #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()
Пример #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