コード例 #1
0
 def replace(self, params):
     new_username = params['username']
     new_email = params['email']
     user = User.replace(self.root.db,
                         self.name,
                         new_username=new_username,
                         new_email=new_email)
     Photo.replace_author(self.root.db, self.name, new_username)
     new_item = Item(new_username, self.__parent__, self.request, user)
     user['href'] = new_item.url()
     user['photos'] = {'href': new_item['photos'].url()}
     return user
コード例 #2
0
 def replace(self, params):
     new_username = params['username']
     new_email = params['email']
     user = User.replace(self.root.db, self.name,
                         new_username=new_username,
                         new_email=new_email)
     Photo.replace_author(self.root.db, self.name, new_username)
     new_item = Item(new_username, self.parent, user)
     user['href'] = new_item.url()
     user['photos'] = {
         'href': new_item['photos'].url()
     }
     return user
コード例 #3
0
ファイル: test_example.py プロジェクト: deuxpi/pyramid_royal
    def test_post_photo(self):
        from example.model import Photo
        image_gif = pkg_resources.resource_stream('royal.tests.functional',
                                                  'image.gif')
        result = self.app.post(
            '/users/hadrien/photos',
            upload_files=[(u'image', u'image.gif', image_gif.read())]
        )
        photo = Photo.get_one(self.db, author='hadrien')
        location = 'http://localhost/photos/%s/' % str(photo._id)

        headers = result.headers
        self.assertIn('Content-Type', headers)
        self.assertIn('Location', headers)

        self.assertEqual('application/json; charset=UTF-8',
                         headers['Content-Type'])
        self.assertEqual(location,
                         headers['Location'])

        expected = {
            'href': location,
            '_id': str(photo._id),
            'author': {
                'href': 'http://localhost/users/hadrien/'
            }
        }
        self.assertEqual(expected, result.json)
コード例 #4
0
    def test_post_photo(self):
        from example.model import Photo
        image_gif = pkg_resources.resource_stream('royal.tests.functional',
                                                  'image.gif')
        result = self.app.post('/users/hadrien/photos',
                               upload_files=[(u'image', u'image.gif',
                                              image_gif.read())])
        photo = Photo.get_one(self.db, author='hadrien')
        location = 'http://localhost/photos/%s/' % str(photo._id)

        headers = result.headers
        self.assertIn('Content-Type', headers)
        self.assertIn('Location', headers)

        self.assertEqual('application/json; charset=UTF-8',
                         headers['Content-Type'])
        self.assertEqual(location, headers['Location'])

        expected = {
            'href': location,
            '_id': str(photo._id),
            'author': {
                'href': 'http://localhost/users/hadrien/'
            }
        }
        self.assertEqual(expected, result.json)
コード例 #5
0
ファイル: photos.py プロジェクト: hadrien/pyramid_royal
 def index(self, params):
     offset = params['offset']
     limit = params['limit']
     cursor = Photo.get_newests(self.root.db, offset, limit)
     query = dict(offset=offset, limit=limit)
     return royal.PaginatedResult(self, cursor, Item, query,
                                  cursor.count())
コード例 #6
0
 def create(self, params):
     fs = params['image']
     author = self.user.name
     mime_type = mimetypes.guess_extension(fs.filename)
     doc = Photo.create(self.root.db, author, fs.file, mime_type)
     return photos.Item(str(doc._id), self.root['photos'], self.request,
                        doc)
コード例 #7
0
ファイル: photos.py プロジェクト: timgates42/pyramid_royal
    def load_document(self):
        if self.document is None:
            self.document = Photo.get_by_id(self.root.db, self.__name__)

        if self.document is None:
            raise NotFound(self)

        return self.document
コード例 #8
0
    def load_document(self):
        if self.document is None:
            self.document = Photo.get_by_id(self.root.db, self.__name__)

        if self.document is None:
            raise NotFound(self)

        return self.document
コード例 #9
0
ファイル: users_photos.py プロジェクト: hadrien/pyramid_royal
 def index(self, query_params):
     offset = query_params["offset"]
     limit = query_params["limit"]
     cursor = Photo.get_newests(self.root.db, offset, limit, author=self.user.name)
     documents = [photos.Item(str(doc._id), self.root, self.request, doc).show() for doc in cursor]
     result = {
         "photos": documents,
         "href": self.url(offset=offset, limit=limit),
         "first": self.url(offset=0, limit=limit),
     }
     has_previous = offset > 0
     if has_previous:
         result["previous"] = self.url(offset=max(offset - limit, 0), limit=limit)
     has_next = len(documents) == limit
     if has_next:
         result["next"] = self.url(offset=offset + limit, limit=limit)
     return result
コード例 #10
0
ファイル: users_photos.py プロジェクト: deuxpi/pyramid_royal
 def index(self, query_params):
     offset = query_params['offset']
     limit = query_params['limit']
     cursor = Photo.get_newests(self.root.db, offset, limit,
                                author=self.parent.name)
     documents = [photos.Item(str(doc._id), self.root, doc).show()
                  for doc in cursor]
     result = {
         'photos': documents,
         'href': self.url(offset=offset, limit=limit),
         'first': self.url(offset=0, limit=limit),
     }
     has_previous = offset > 0
     if has_previous:
         result['previous'] = self.url(offset=max(offset - limit, 0),
                                       limit=limit)
     has_next = len(documents) == limit
     if has_next:
         result['next'] = self.url(offset=offset + limit, limit=limit)
     return result
コード例 #11
0
 def index(self, query_params):
     offset = query_params['offset']
     limit = query_params['limit']
     cursor = Photo.get_newests(self.root.db,
                                offset,
                                limit,
                                author=self.user.name)
     documents = [
         photos.Item(str(doc._id), self.root, self.request, doc).show()
         for doc in cursor
     ]
     result = {
         'photos': documents,
         'href': self.url(offset=offset, limit=limit),
         'first': self.url(offset=0, limit=limit),
     }
     has_previous = offset > 0
     if has_previous:
         result['previous'] = self.url(offset=max(offset - limit, 0),
                                       limit=limit)
     has_next = len(documents) == limit
     if has_next:
         result['next'] = self.url(offset=offset + limit, limit=limit)
     return result
コード例 #12
0
ファイル: users_photos.py プロジェクト: deuxpi/pyramid_royal
 def create(self, params):
     fs = params['image']
     author = unicode(self.parent.name)
     mime_type = mimetypes.guess_extension(fs.filename)
     doc = Photo.create(self.root.db, author, fs.file, mime_type)
     return photos.Item(str(doc._id), self.root['photos'], doc)
コード例 #13
0
ファイル: user_photo.py プロジェクト: bkuberek/pyramid_royal
 def create(self, **kwargs):
     fs = kwargs['image']
     author = self.__parent__.__name__
     mime_type = mimetypes.guess_extension(fs.filename)
     photo = Photo.create(self.root.db, author, fs.file, mime_type)
     return Resource(str(photo._id), self, photo)
コード例 #14
0
ファイル: user_photo.py プロジェクト: bkuberek/pyramid_royal
 def index(self, offset, limit):
     cursor = Photo.get_newests(self.root.db, offset, limit,
                                author=self.__parent__.__name__)
     query = dict(offset=offset, limit=limit)
     return royal.PaginatedResult(self, cursor, Resource, query,
                                  cursor.count())
コード例 #15
0
ファイル: photos.py プロジェクト: timgates42/pyramid_royal
 def index(self, params):
     offset = params['offset']
     limit = params['limit']
     cursor = Photo.get_newests(self.root.db, offset, limit)
     query = dict(offset=offset, limit=limit)
     return royal.PaginatedResult(self, cursor, Item, query, cursor.count())
コード例 #16
0
ファイル: users_photos.py プロジェクト: hadrien/pyramid_royal
 def create(self, params):
     fs = params["image"]
     author = self.user.name
     mime_type = mimetypes.guess_extension(fs.filename)
     doc = Photo.create(self.root.db, author, fs.file, mime_type)
     return photos.Item(str(doc._id), self.root["photos"], self.request, doc)