示例#1
0
文件: helpers.py 项目: jab/radarpost
def create_test_mailbox(name=TEST_MAILBOX_ID, server=TEST_SERVER):
    try:
        couchdb = Server(server)
        return _create_mailbox(couchdb, name)
    except PreconditionFailed:        
        del couchdb[name]
        return _create_mailbox(couchdb, name)
示例#2
0
def create_test_mailbox(config=None, name=TEST_MAILBOX_ID):
    if config is None: 
        config = load_test_config()
    try:
        couchdb = Server(config['couchdb.address'])
        return _create_mailbox(couchdb, name)
    except PreconditionFailed:        
        del couchdb[name]
        return _create_mailbox(couchdb, name)
示例#3
0
def create_mailbox(request, mailbox_slug):
    """
    create a mailbox.  request.POST may contain
    a json object with initial mailbox info.
    """
    if not request.context.user.has_perm(PERM_CREATE_MAILBOX):
        return HttpResponse(status=401)
    
    try:
        info = None
        if request.body:
            try:
                info = _mailbox_info_json(request)
            except:
                return HttpResponse(status=400)
        
        ctx = request.context
        dbname = ctx.get_database_name(mailbox_slug)
        mb = _create_mailbox(ctx.get_couchdb_server(), dbname)
        if info is not None and len(info) > 0:
            mbinfo = MailboxInfo.get(mb)
            for k, v in info.items():
                setattr(mbinfo, k, v)
            mbinfo.store(mb)

        return HttpResponse(status=201)
    except PreconditionFailed:
        return HttpResponse(status=409)