Пример #1
0
 def post(self, course_key):
     """Updates a specific Course"""
     b_course = ndb.Key(urlsafe=course_key).get()
     if b_course and util.param('name') and util.param('lessons'):
         b_name = util.param('name')
         b_description = util.param('description')
         b_topics = [
             ndb.Key(urlsafe=topic_key_url)
             for topic_key_url in util.param('topics', list)
         ]
         b_lessons = helpers.connected_entities_constructor(
             util.param('lessons', list))
         b_contributors = b_course.contributors
         #add new contributors to the list of course contributors.
         if auth.current_user_key() not in b_contributors:
             b_contributors += [auth.current_user_key()]
         b_course.name = b_name
         b_course.description = b_description
         b_course.topics = b_topics
         b_course.contributors = b_contributors
         b_course.lessons = b_lessons
         b_course = b_course.put()
         response = {
             'status': 'success',
             'count': 1,
             'now': helpers.time_now(),
             'result': {
                 'message':
                 'Course was successfuly created!!',
                 'view_url':
                 flask.url_for('course', course_key=b_course.urlsafe())
             },
         }
         return response
     return helpers.make_bad_request_exception("Unsifificient parameters")
Пример #2
0
 def post(self, course_key):
   """Updates a specific Course"""
   b_course = ndb.Key(urlsafe=course_key).get()
   if b_course and util.param('name') and util.param('lessons'):
     b_name = util.param('name')
     b_description = util.param('description')
     b_topics = [ ndb.Key(urlsafe=topic_key_url) for topic_key_url in util.param('topics', list)]
     b_lessons = helpers.connected_entities_constructor(util.param('lessons', list))
     b_contributors = b_course.contributors
     #add new contributors to the list of course contributors.
     if auth.current_user_key() not in b_contributors:
       b_contributors += [auth.current_user_key()]
     b_course.name=b_name
     b_course.description=b_description
     b_course.topics=b_topics
     b_course.contributors=b_contributors
     b_course.lessons=b_lessons
     b_course = b_course.put()
     response = {
       'status': 'success',
       'count': 1,
       'now': helpers.time_now(),
       'result': {'message': 'Course was successfuly created!!',
                  'view_url': flask.url_for('course', course_key=b_course.urlsafe())
                 },
     }
     return response
   return helpers.make_bad_request_exception("Unsifificient parameters")
Пример #3
0
 def post(self):
   """
   name = ndb.StringProperty(required=True,indexed=True)
   description = ndb.TextProperty()
   lessons = ndb.TextProperty()
   topics = ndb.KeyProperty(kind='Topic', repeated=True)
   contributors = ndb.KeyProperty(kind='User', repeated=True)
   approved = ndb.BooleanProperty(default=False)
   deadlock = ndb.BooleanProperty(default=False)
   color = ndb.StringProperty()
   vote = ndb.KeyProperty(kind='Vote')
   """
   if util.param('name') and util.param('lessons'):
     b_name = util.param('name')
     b_description = util.param('description')
     b_topics = [ ndb.Key(urlsafe=topic_key_url) for topic_key_url in util.param('topics', list)]
     b_lessons = helpers.connected_entities_constructor(util.param('lessons', list))
     b_contributor = auth.current_user_key()
     b_course = model.Course(name=b_name,description=b_description,topics=b_topics,
                             contributors=[b_contributor], lessons=b_lessons).put()
     response = {
       'status': 'success',
       'count': 1,
       'now': helpers.time_now(),
       'result': {'message': 'Course was successfuly created!!',
                  'view_url': flask.url_for('course', course_key=b_course.urlsafe())
                 },
     }
     return response
   return helpers.make_bad_request_exception("Unsifificient parameters")
Пример #4
0
 def post(self):
     """
 name = ndb.StringProperty(required=True,indexed=True)
 description = ndb.TextProperty()
 lessons = ndb.TextProperty()
 topics = ndb.KeyProperty(kind='Topic', repeated=True)
 contributors = ndb.KeyProperty(kind='User', repeated=True)
 approved = ndb.BooleanProperty(default=False)
 deadlock = ndb.BooleanProperty(default=False)
 color = ndb.StringProperty()
 vote = ndb.KeyProperty(kind='Vote')
 """
     if util.param('name') and util.param('lessons'):
         b_name = util.param('name')
         b_description = util.param('description')
         b_topics = [
             ndb.Key(urlsafe=topic_key_url)
             for topic_key_url in util.param('topics', list)
         ]
         b_lessons = helpers.connected_entities_constructor(
             util.param('lessons', list))
         b_contributor = auth.current_user_key()
         b_course = model.Course(name=b_name,
                                 description=b_description,
                                 topics=b_topics,
                                 contributors=[b_contributor],
                                 lessons=b_lessons).put()
         response = {
             'status': 'success',
             'count': 1,
             'now': helpers.time_now(),
             'result': {
                 'message':
                 'Course was successfuly created!!',
                 'view_url':
                 flask.url_for('course', course_key=b_course.urlsafe())
             },
         }
         return response
     return helpers.make_bad_request_exception("Unsifificient parameters")