def get_list(self, *args, **kwargs): """ Provides a list of JSON objects from a MongoConnection class. """ # Set up the mongo connection. mongo_object = MongoConnection(db=self.db_name, collection=self.collection_name, auth=self.auth_string) connection = mongo_object.connect() # Get the total count and the number of pages. total_count = connection.find(self.query_dict).count() if (total_count % self.pagination_limit) > 0: self.pages = (total_count / self.pagination_limit) + 1 else: self.pages = total_count / self.pagination_limit if self.pages == 1: self.page_range = [1] else: self.page_range = range(1, self.pages + 1) try: query_kwargs = self.query_filter["kwargs"] query_filter = {query_kwargs["mongo_field"]: self.kwargs[query_kwargs["url_kwarg"]]} except Exception, e: print Exception, e query_filter = None
def get_object(self, *args, **kwargs): mongo_object = MongoConnection(db=self.db_name, collection=self.collection_name, auth=self.auth_string) connection = mongo_object.connect() query = connection.find_one(ObjectId(str(self.kwargs[self.query_filter["kwargs"]["url_kwarg"]]))) if query == None: raise Http404(u"List is empty.") else: return query, "query"
def auth(self, **options): """ Authorize with a database/collection """ connection_object = MongoConnection(db=options['database'], collection=options['collection'], auth=options['auth']) if options['gridfs']: return(connection_object.gridfs()) else: return(connection_object.connect())