Example #1
0
 def post(self, lesson_key):
     """Updates a specific lesson"""
     if util.param("name") and util.param("is_a"):
         b_is_a = util.param("is_a")
         b_data = helpers.data_scheme_constructor(b_is_a, helpers.rerieve_content_fields(util))
         b_topics = [ndb.Key(urlsafe=topic_key_url) for topic_key_url in util.param("topics", list)]
         b_name = util.param("name")
         b_description = util.param("description")
         b_lesson = ndb.Key(urlsafe=lesson_key).get()
         if not b_lesson:
             return helpers.make_not_found_exception("Lesson %s not found" % lesson_key)
         b_lesson.data = b_data
         b_lesson.name = b_name
         b_lesson.is_a = b_is_a
         b_lesson.description = b_description
         b_lesson.topics = b_topics
         b_lesson = b_lesson.put()
         response = {
             "status": "success",
             "count": 1,
             "now": helpers.time_now(),
             "result": {
                 "message": "Lesson was successfuly updated!!",
                 "view_url": flask.url_for("lesson", lesson_key=b_lesson.urlsafe()),
             },
         }
         return response
     return helpers.make_bad_request_exception("Unsifificient parameters")
Example #2
0
 def post(self, lesson_key):
     """Updates a specific lesson"""
     if util.param('name') and util.param('is_a'):
         b_is_a = util.param('is_a')
         b_data = helpers.data_scheme_constructor(
             b_is_a, helpers.rerieve_content_fields(util))
         b_topics = [
             ndb.Key(urlsafe=topic_key_url)
             for topic_key_url in util.param('topics', list)
         ]
         b_name = util.param('name')
         b_description = util.param('description')
         b_lesson = ndb.Key(urlsafe=lesson_key).get()
         if not b_lesson:
             return helpers.make_not_found_exception('Lesson %s not found' %
                                                     lesson_key)
         b_lesson.data = b_data
         b_lesson.name = b_name
         b_lesson.is_a = b_is_a
         b_lesson.description = b_description
         b_lesson.topics = b_topics
         b_lesson = b_lesson.put()
         response = {
             'status': 'success',
             'count': 1,
             'now': helpers.time_now(),
             'result': {
                 'message':
                 'Lesson was successfuly updated!!',
                 'view_url':
                 flask.url_for('lesson', lesson_key=b_lesson.urlsafe())
             },
         }
         return response
     return helpers.make_bad_request_exception("Unsifificient parameters")
Example #3
0
 def post(self, version_key):
   """Updates a specific lesson version by key"""
   if util.param('name') and util.param('is_a'):
     b_is_a = util.param('is_a')
     b_data = helpers.data_scheme_constructor(b_is_a, helpers.rerieve_content_fields(util))
     b_topics = [ ndb.Key(urlsafe=topic_key_url) for topic_key_url in util.param('topics', list)]
     b_name = util.param('name')
     b_description = util.param('description')
     b_lesson_version = ndb.Key(urlsafe=version_key).get()
     if not b_lesson_version:
       return helpers.make_not_found_exception('LessonVersion %s not found' % b_lesson_version)
     b_lesson_version.data=b_data
     b_lesson_version.name=b_name
     b_lesson_version.is_a=b_is_a
     b_lesson_version.description=b_description
     b_lesson_version.topics=b_topics
     b_lesson_version = b_lesson_version.put()
     response = {
       'status': 'success',
       'count': 1,
       'now': helpers.time_now(),
       'result': {'message': 'Lesson Version was successfuly updated!',
                  'view_url': flask.url_for('lesson_version', version_key=b_lesson_version.urlsafe())
                 },
     }
     return response
   return helpers.make_bad_request_exception("Unsifificient parameters")
Example #4
0
 def post(self, lesson_key):
   if util.param('name') and util.param('is_a'):
     b_is_a = util.param('is_a')
     b_data = helpers.data_scheme_constructor(b_is_a, helpers.rerieve_content_fields(util))
     b_topics = [ ndb.Key(urlsafe=topic_key_url) for topic_key_url in util.param('topics', list)]
     b_name = util.param('name')
     b_description = util.param('description')
     b_contributor = auth.current_user_key()
     b_lesson = ndb.Key(urlsafe=lesson_key).get()
     if not b_lesson:
       return helpers.make_not_found_exception('Lesson %s not found' % b_lesson)
     b_lesson_version = model.LessonVersion(data=b_data,name=b_name,is_a=b_is_a,description=b_description,topics=b_topics,lesson=b_lesson.key,contributor=b_contributor).put()
     b_lesson.contributors += [b_contributor]
     b_lesson.lesson_versions += [b_lesson_version]
     b_lesson.put()
     response = {
       'status': 'success',
       'count': 1,
       'now': helpers.time_now(),
       'result': {'message': 'Lesson Version update proposal was successfuly created!!',
                  'view_url': flask.url_for('lesson_version', version_key=b_lesson_version.urlsafe())
                 },
     }
     return response
   return helpers.make_bad_request_exception("Unsifificient parameters")
Example #5
0
 def post(self):
     if util.param("name") and util.param("is_a"):
         b_is_a = util.param("is_a")
         b_data = helpers.data_scheme_constructor(b_is_a, helpers.rerieve_content_fields(util))
         b_topics = [ndb.Key(urlsafe=topic_key_url) for topic_key_url in util.param("topics", list)]
         b_name = util.param("name")
         b_description = util.param("description")
         b_contributor = auth.current_user_key()
         b_lesson = (
             model.Lesson(
                 data=b_data,
                 name=b_name,
                 is_a=b_is_a,
                 description=b_description,
                 topics=b_topics,
                 contributors=[b_contributor],
             )
             .put()
             .get()
         )
         b_lesson_version = model.LessonVersion(
             data=b_data,
             name=b_name,
             is_a=b_is_a,
             description=b_description,
             topics=b_topics,
             lesson=b_lesson.key,
             contributor=b_contributor,
         ).put()
         b_lesson.latest_version = b_lesson_version
         b_lesson.lesson_versions = [b_lesson_version]
         b_lesson.put()
         response = {
             "status": "success",
             "count": 1,
             "now": helpers.time_now(),
             "result": {
                 "message": "Lesson was successfuly created!!",
                 "view_url": flask.url_for("lesson", lesson_key=b_lesson.key.urlsafe()),
             },
         }
         return response
     return helpers.make_bad_request_exception("Unsifificient parameters")
Example #6
0
 def post(self):
     if util.param('name') and util.param('is_a'):
         b_is_a = util.param('is_a')
         b_data = helpers.data_scheme_constructor(
             b_is_a, helpers.rerieve_content_fields(util))
         b_topics = [
             ndb.Key(urlsafe=topic_key_url)
             for topic_key_url in util.param('topics', list)
         ]
         b_name = util.param('name')
         b_description = util.param('description')
         b_contributor = auth.current_user_key()
         b_lesson = model.Lesson(data=b_data,
                                 name=b_name,
                                 is_a=b_is_a,
                                 description=b_description,
                                 topics=b_topics,
                                 contributors=[b_contributor]).put().get()
         b_lesson_version = model.LessonVersion(
             data=b_data,
             name=b_name,
             is_a=b_is_a,
             description=b_description,
             topics=b_topics,
             lesson=b_lesson.key,
             contributor=b_contributor).put()
         b_lesson.latest_version = b_lesson_version
         b_lesson.lesson_versions = [b_lesson_version]
         b_lesson.put()
         response = {
             'status': 'success',
             'count': 1,
             'now': helpers.time_now(),
             'result': {
                 'message':
                 'Lesson was successfuly created!!',
                 'view_url':
                 flask.url_for('lesson', lesson_key=b_lesson.key.urlsafe())
             },
         }
         return response
     return helpers.make_bad_request_exception("Unsifificient parameters")