コード例 #1
0
ファイル: waypoint_api.py プロジェクト: wodore/wodore-ng
    def put(self, collection):
        """Updates waypoint properties"""
        print "Update waypoint property"
        update_properties = ['name', 'creator', 'description', 'key']
# TODO urls
        update_properties = ['collection', 'key','name','description','tags','geo']
        data = _.pick(request.json, update_properties)
        if 'collection' not in data:
            if data['collection'] != collection:
                return make_bad_request_exception("Wrong collection key")
            else:
                data['collection'] = collection


        if 'creator' not in data:
            data['creator'] = auth.current_user_key()
        else:
            data['creator'] =  ndb.Key(urlsafe=data['creator'])
        if 'geo' in data:
            data['geo'] = ndb.GeoPt(data['geo'])
        try:
            data['key'] = ndb.Key(urlsafe=data['key'])
        except:
            data['key'] = None
        try:
            data['collection'] = ndb.Key(urlsafe=data['collection'])
        except:
            return make_bad_request_exception("Wrong collection key")
        #print data
        # TODO key from new data or as argument
        key = model.WayPoint.create_or_update(**data)
        return {'key':key.urlsafe(),'id':key.id()}
コード例 #2
0
ファイル: auth_api.py プロジェクト: jacraven/lsiapp
    def post(self):
        """Signs in existing user. Note, g.user_db is set inside parse_signin decorator"""
        if g.user_db and g.user_db.verified and g.user_db.active:
            auth.signin_user_db(g.user_db, remember=g.args.remember)

        if g.user_db is None:
            make_bad_request_exception('Seems like these credentials are invalid')

        return g.user_db.to_dict(include=User.get_private_properties())
コード例 #3
0
ファイル: auth_api.py プロジェクト: sidharta/hansel-app
    def post(self):
        """Signs in existing user. Note, g.user_db is set inside parse_signin decorator"""
        if g.user_db and g.user_db.verified and g.user_db.active:
            auth.signin_user_db(g.user_db, remember=g.args.remember)

        if g.user_db is None:
            make_bad_request_exception('Seems like these credentials are invalid')

        return g.user_db.to_dict(include=User.get_private_properties())
コード例 #4
0
    def post(self, module_id):
        module_config_obj = util.param(MODULE_CONFIG)

        if not module_config_obj:
            helpers.make_bad_request_exception("`module_config` parameter is expected to be found in the request")
        meta = {META_KEYWORDS: util.param(META_KEYWORDS), META_DESCRIPTION: util.param(META_DESCRIPTION)}
        module_config_db = store_module_config(module_config_obj, meta, module_id)

        return helpers.make_response(module_config_db, model.ModuleConfig.FIELDS)
コード例 #5
0
ファイル: course.py プロジェクト: Biomassaedubr/FIRSTMastery
 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")
コード例 #6
0
ファイル: lesson.py プロジェクト: ColdSauce/FIRSTMastery
 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")
コード例 #7
0
ファイル: course.py プロジェクト: ColdSauce/FIRSTMastery
 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")
コード例 #8
0
ファイル: course.py プロジェクト: ColdSauce/FIRSTMastery
 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")
コード例 #9
0
ファイル: lesson.py プロジェクト: Biomassaedubr/FIRSTMastery
 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")
コード例 #10
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")
コード例 #11
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")
コード例 #12
0
ファイル: tag_api.py プロジェクト: wodore/wodore-ng
    def put(self,collection):
        """Updates user's properties"""
        #update_properties = ['name', 'collection', 'toplevel', 'icon_key', 'color', 'force_new_icon','auto_incr']
        #print request.json
        #data = _.pick(request.json, update_properties)
        data = request.json
        print "Data is:"
        print data

        if 'force_new_icon' not in data:
            data['force_new_icon'] = False
        if 'auto_incr' not in data:
            data['auto_incr'] = False
        if 'tag_details' not in data:
            data['tag_details'] = []
        try:
            data['collection'] = ndb.Key(urlsafe=data['collection'])
        except:
            return make_bad_request_exception("Wrong collection key")
        #print data
        tag_list = []
        # Check tag properties and add tag
        for tag in data['tag_details']:
            #if 'toplevel' not in tag:
                #tag['toplevel'] = None
            #else:
                #try:
                    #tag['toplevel'] = ndb.Key(urlsafe=tag['toplevel'])
                #except:
                    #tag['toplevel'] = None
            if 'icon_key' not in tag:
                tag['icon_key'] = None
            else:
                try:
                    tag['icon_key'] = ndb.Key(urlsafe=tag['icon_key'])
                except:
                    pass
            tag['collection'] = data['collection']
            print "Arguments for add tag"
            print tag
            key = model.Tag.add(**tag)
            tag_list.append(tag['name'])

        tags = model.Tag.get_tag_infos(tag_list,data['collection'])
        return make_list_response(tags, False, False, len(tags))
コード例 #13
0
ファイル: lesson.py プロジェクト: ColdSauce/FIRSTMastery
 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")
コード例 #14
0
ファイル: lesson.py プロジェクト: Biomassaedubr/FIRSTMastery
 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")
コード例 #15
0
ファイル: course.py プロジェクト: Biomassaedubr/FIRSTMastery
 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")