示例#1
0
def detail_view(request):
    item_id = request.url.split('/')[-1]
    user = request.authenticated_userid

    root = firstpyramid.root_factory(request)

    item = root['images'].get(int(item_id))

    if user in item['voters']:
        css_classes = get_css_classes(user, item['voters'][user])
    else:
        css_classes = get_css_classes(user)

    return {
        'item': {
            'title': item['title'],
            'image': b64(item['image']),
            'id': item_id,
            'uploader_name': root['users'][item['uploader']]['name'],
            'uploader_id': item['uploader'],
            'votes': votes_presage(item['votes']),
            'desc': item['description'],
            'tags': item['tags'],
            'css_classes': css_classes
        }
    }
示例#2
0
    def add_user(self, new_user, request):
        root = firstpyramid.root_factory(request)

        root['users'].update({
            new_user['username']: {
                'password': hash_password(new_user['password']),
                'name': new_user['name']
            }
        })

        transaction.commit()
示例#3
0
    def add_item(self, new_item, request):
        root = firstpyramid.root_factory(request)

        storage = root['images']
        if storage:
            new_key = sorted(storage.keys())[-1] + 1
        else:
            new_key = 1

        new_item['image'] = Blob(new_item['image'].file.read())

        self.update_item(new_key, new_item, request)
        return new_key
示例#4
0
 def get_users(self, request):
     root = firstpyramid.root_factory(request)
     return dict(root['users'])
示例#5
0
 def update_item(self, key, value, request):
     root = firstpyramid.root_factory(request)
     root['images'].update({key: value})
     transaction.commit()
示例#6
0
 def get_items(self, request):
     root = firstpyramid.root_factory(request)
     return dict(root['images'])
示例#7
0
 def get_item(self, item_id, request):
     root = firstpyramid.root_factory(request)
     return root['images'][item_id]
示例#8
0
def full_image_view(request):
    root = firstpyramid.root_factory(request)
    item_id = request.url.split('/')[-1]
    item = root['images'].get(int(item_id))
    return {'image': b64(item['image'])}