Beispiel #1
0
    def comments_add(self, request):
        if request.apikey:
            self.apikey_model = ApiKeys.get_apikey_by_id(request.apikey)
            if self.apikey_model is None:
                return CommentsAddResponse(message="the API key provided is no longer valid")
            else:
                new_comment = Comments()
                self.user_model = User.get_user_by_id(self.apikey_model.user_id)
                self.model_current_posts = Connection.get_connections_by_user_id_status(self.user_model.key)
                new_comment.user_name = self.user_model.username
                new_comment.user_key = self.user_model.key
                self.apikey_model.total_calls += 1
                self.apikey_model.put()

        else:
            return ConnectionAddResponse(message="you must provide an API key")

        self.header_dict = self.parse_header(self.request_state.headers._headers)

        # if len(Connection.get_connection_by_title(request.title)) > 0:
        #     return CommentsAddResponse(message="title already exists %s" % request.title)

        if request.personthing_id:
            self.personthing_model = PeopleThing.get_person_by_id(request.personthing_id)
            new_comment.personthing_key = self.personthing_model.key
            new_comment.personthing_name = self.personthing_model.name

        if request.user_id:
            self.user_model = User.get_user_by_id(request.user_id)
            new_comment.user_key = self.user_model.key
            new_comment.user_name = self.user_model.name

        if request.connection_id:
            try:
                self.connection_model = Connection.get_connection_by_id(request.connection_id)
                new_comment.connection_key = self.connection_model.key
                new_comment.connection_title = self.connection_model.title
            except:
                return CommentsAddResponse(message="Connection ID not valid: %s" % request.connection_id)


        if request.media:
            new_comment.media = request.media

        new_comment.post_type = request.post_type
        new_comment.title = request.title
        new_comment.tags = request.tags
        new_comment.body = request.body

        new_comment.uastring = self.header_dict['user-agent']
        new_comment.ip = self.request_state.remote_address
        new_blog_key = new_comment.put()

        return CommentsAddResponse(message="successfully added comment", comment_id = new_blog_key.id())
Beispiel #2
0
    def comments_list(self, request):
        filter_dict = {}
        self.curs = Cursor(urlsafe=request.cursor)
        #If the user does not specify the limit of results, use 20
        if not request.limit:
            request.limit = 20

        if request.created:
            filter_dict['created'] = request.created

        if request.updated:
            filter_dict['updated'] = request.updated

        if request.tags:
            filter_dict['tags'] = request.connection_stage

        if request.title:
            filter_dict['title'] = request.title

        if request.user_id:
            filter_dict['user_key'] = User.get_user_by_id(request.user_id).key

        if request.personthing_id:
            filter_dict['personthing_key'] = PeopleThing.get_person_by_id(request.personthing_id).key

        if request.connection_id:
            filter_dict['connection_key'] = Connection.get_connection_by_id(request.connection_id).key

        self.all_comments, next_curs, more_results = Comments.get_comments(self.curs, request.limit, filter_dict)
        comments = [comment.to_comment_message() for comment in self.all_comments]
        if more_results is True:
            self.cursor=next_curs.urlsafe()
        else:
            self.cursor="No More Results"
        return CommentsListResponse(comments=comments, cursor = self.cursor, num_of_results = len(self.all_comments))
Beispiel #3
0
    def connection_update(self, request):
        # Create New Connection DB Instance
        self.header_dict = self.parse_header(self.request_state.headers._headers)

        if request.apikey:
            self.apikey_model = ApiKeys.get_apikey_by_id(request.apikey)
            if self.apikey_model is None:
                return ConnectionUpdateResponse(message="the API key provided is no longer valid")
            else:
                self.update_connection_model = Connection.get_connection_by_id(request.connection_id)
                self.user_model = User.get_user_by_id(self.apikey_model.user_id)
                self.update_connection_model.user_name = self.user_model.name
                self.update_connection_model.user_key = self.user_model.key
                self.apikey_model.total_calls += 1
                self.apikey_model.put()
        else:
            return ConnectionAddResponse(message="you must provide an API key")


        if self.update_connection_model is None:
            return ConnectionUpdateResponse(message="ID not found: %s" % request.connection_id)

        if request.personthing_id:
            request.personthing_name = self.personthing_model.name
            self.update_connection_model.personthing_key = self.personthing_model.key

        if request.media:
            self.update_connection_model.media = request.media

        if request.type is not None:
            self.update_connection_model.type = request.type
        if request.title is not None:
            self.update_connection_model.title = request.title
        if request.summary is not None:
            self.update_connection_model.summary = request.summary
        if request.body is not None:
            self.update_connection_model.body = request.body
        if request.primary_media is not None:
            self.update_connection_model.primary_media = request.primary_media
        if request.connection_stage is not None:
            self.update_connection_model.connection_stage = request.connection_stage
        if request.personthing_name is not None:
            self.update_connection_model.personthing_name = request.personthing_name
        if request.request_reason is not None:
            self.update_connection_model.request_reason = request.request_reason
        if request.private_location is not None:
            self.update_connection_model.private_loc = request.private_location
        if request.personalized_message is not None:
            self.update_connection_model.personalized_message = request.personalized_message
        self.update_connection_model.uastring = self.header_dict['user-agent']
        self.update_connection_model.ip = self.request_state.remote_address
        update_connection_key = self.update_connection_model.put()

        return ConnectionUpdateResponse(message="successfully updated connection", update_connection_id = update_connection_key.id())
Beispiel #4
0
    def search_add(self, request):
        # Create New Connection DB Instance
        self.header_dict = self.parse_header(self.request_state.headers._headers)
        index = search.Index(name="alcindex_01")

        try:
            self.user_key = User.get_user_by_id(request.user_id)
        except:
            return SearchAddResponse(message="user_id is a required field")

        search_document_dictionary = {}

        if request.user_id:
            self.user_model = User.get_user_by_id(request.user_id)
            if self.user_model is not None:
                search_document_dictionary['user_name'] = self.user_model.name
            else:
                return SearchAddResponse(message="provided user id did not match")
        else:
            search_document_dictionary['user_name'] = None

        if request.personthing_id:
            self.personthing_model = PeopleThing.get_person_by_id(request.personthing_id)
            search_document_dictionary['personthing_name'] = self.personthing_model.name

        else:
            search_document_dictionary['personthing_name'] = None

        search_document_dictionary['type'] = request.type
        search_document_dictionary['title'] = request.title
        search_document_dictionary['blog_title'] = request.blog_title
        search_document_dictionary['summary'] = request.summary
        search_document_dictionary['tags'] = request.tags
        search_document_dictionary['latitude'] = request.latitude
        search_document_dictionary['longitude'] = request.longitude
        search_document_dictionary['body'] = request.body
        new_search_doc_id = self.search_doc_create(search_document_dictionary, index)

        return SearchAddResponse(message="successfully added connection", new_search_id = new_search_doc_id[0].id)
Beispiel #5
0
    def connection_add(self, request):
        # Create New Connection DB Instance
        index = search.Index(name="alcindex_01")
        self.header_dict = self.parse_header(self.request_state.headers._headers)
        new_connection = Connection()
        search_document_dictionary = {}
        search_document_dictionary['title'] = None
        search_document_dictionary['loc_name'] = None
        search_document_dictionary['personthing_name'] = None
        search_document_dictionary['user_name'] = None
        search_document_dictionary['blog_title'] = None
        search_document_dictionary['type'] = None
        search_document_dictionary['latitude'] = None
        search_document_dictionary['longitude'] = None
        search_document_dictionary['body'] = None
        search_document_dictionary['summary'] = None
        search_document_dictionary['tags'] = None


        if request.apikey:
            self.apikey_model = ApiKeys.get_apikey_by_id(request.apikey)
            if self.apikey_model is None:
                return ConnectionAddResponse(message="the API key provided is no longer valid")
            else:
                self.user_model = User.get_user_by_id(self.apikey_model.user_id)
                self.model_current_posts = Connection.get_connections_by_user_id_status(self.user_model.key)
                new_connection.user_name = self.user_model.username
                new_connection.user_key = self.user_model.key
                self.apikey_model.total_calls += 1
                self.apikey_model.put()
                search_document_dictionary['user_name'] = self.user_model.name
        else:
            return ConnectionAddResponse(message="you must provide an API key")



        if self.model_current_posts and len(self.model_current_posts) > 4:
            return ConnectionAddResponse(message="user can only have 5 pending requests: %s" % request.apikey)

        # if len(Connection.get_connection_by_title(request.title)) > 0:
        #     return ConnectionAddResponse(message="title already exists %s" % request.title)

        if request.personthing_id:
            self.personthing_model = PeopleThing.get_person_by_id(request.personthing_id)
            new_connection.personthing_name = self.personthing_model.name
            new_connection.personthing_key = self.personthing_model.key
            search_document_dictionary['personthing_name'] = self.personthing_model.name

        #If the API only provides a name, I will create a personthing
        elif request.personthing_name:
            new_personthing = PeopleThing()
            new_personthing.name = request.personthing_name
            new_connection.personthing_name = new_personthing.name
            new_connection.personthing_key = new_personthing.put()
            search_document_dictionary['personthing_name'] = new_personthing.name


        if request.media:
            new_connection.media = request.media
            # Add the API object for the media
            self.media_response_full = []
            self.json_gen = self.iterload(request.media)
            self.media_response = []
            for media_item in self.json_gen['results']:
                self.media_response.append(MediaJsonMessage(width = int(media_item['width']),
                                                            height = int(media_item['height']),
                                                            filetype = media_item['filetype'],
                                                            file_cat = media_item['file_cat'],
                                                            blob_key = images.get_serving_url(media_item['blobstore_key'])))
            self.media_response_full.append(MediaJsonFinalResponse(media_item_message=self.media_response,
                                                                   filename = self.json_gen['filename']))
            new_connection.media_binary = self.media_response_full


        if request.latitude and request.longitude:
            #temporarily storing as lat, lng, and geopt because I am unsure of how to interact with it later
            new_connection.latitude = request.latitude
            new_connection.longitude = request.longitude
            new_connection.loc_geopt = ndb.GeoPt(float(request.latitude), float(request.longitude))

        new_connection.type = request.type
        new_connection.title = request.title
        new_connection.summary = request.summary
        new_connection.primary_media = request.primary_media
        new_connection.request_reason = request.request_reason
        new_connection.private_loc = request.private_location
        new_connection.personalized_message = request.personalized_message
        new_connection.uastring = self.header_dict['user-agent']
        new_connection.ip = self.request_state.remote_address




        new_connection_key = new_connection.put()

        search_document_dictionary['type'] = request.type
        search_document_dictionary['title'] = request.title
        search_document_dictionary['summary'] = request.summary
        search_document_dictionary['latitude'] = request.latitude
        search_document_dictionary['longitude'] = request.longitude
        search_document_dictionary['connection_id'] = str(new_connection_key.id())
        new_search_doc_id = self.search_doc_create(search_document_dictionary, index)

        short = new_connection_key.get()
        short_url = 'http://www.bealittlecloser.com/map?node_id=%s&lat=%s&lng=%s&zoom=15' % (new_connection_key.id(), request.latitude, request.longitude)
        short.social_media_json = self.create_short_url(short_url)
        short.put()

        return ConnectionAddResponse(message="successfully added connection", new_connection_id = new_connection_key.id())
Beispiel #6
0
    def connection_list(self, request):
        filter_dict = {}
        if request.apikey:
            self.apikey_model = self.lookup_api_key(request.apikey)
            if self.apikey_model is not None:
                self.apikey_model.total_calls += 1
                self.apikey_model.put()
                self.user_id = self.apikey_model.user_id
                self.user_key = User.get_user_by_id(self.user_id).key
                filter_dict['user_key'] = self.user_key

        self.curs = Cursor(urlsafe=request.cursor)
        #If the user does not specify the limit of results, use 20
        if not request.limit:
            request.limit = 20

        if request.created:
            filter_dict['created'] = request.created

        if request.updated:
            filter_dict['updated'] = request.updated

        if request.connection_stage:
            filter_dict['connection_stage'] = request.connection_stage

        if request.connection_type:
            filter_dict['connection_type'] = request.connection_type

        if request.loc_name:
            if request.loc_name != "all":
                filter_dict['loc_name'] = request.loc_name

        if request.user_name:
            filter_dict['user_name'] = request.user_name

        if request.title:
            filter_dict['title'] = request.title

        if request.type:
            filter_dict['type'] = request.type

        if request.personthing_id:
            filter_dict['personthing_key'] = PeopleThing.get_by_id(request.personthing_id).key

        self.all_connections, next_curs, more_results = Connection.get_connections(self.curs, request.limit, filter_dict)


        connects = []

        for entity in self.all_connections:
            if request.loc_name != "all":
                self.connection_response = entity.to_message(entity.media_binary)

            else:
                self.connection_response = entity.to_message_no_media()
            connects.append(self.connection_response)

        if more_results is True:
            self.cursor=next_curs.urlsafe()
        else:
            self.cursor="No More Results"
        return ConnectionListResponse(connections=connects, cursor = self.cursor, num_of_results = len(self.all_connections))