示例#1
0
def handle_picup(request, path):
    if not request.FILES.has_key('filedata') and not request.POST.has_key('sid'):
        return HttpResponse('no image', mimetype='text/plain')

    try:
        url = uploader.upload(request, request.FILES['filedata'], size=0, sid=request.POST['sid'])
    except Exception, e:
        return HttpResponse(repr(e), mimetype='text/plain')
示例#2
0
def handle_article_post(request, path):
    try:
        redirect_if_no_session(request)
        sid = get_session_id(request)
        sess = registry.query(sid)
        
        dest = check_arg(path)
        if not dest:
            return error(request, u'잘못된 인자입니다.')

        try:
            subject = request.POST['subject'].encode(TARGET_ENCODING)
            contents = request.POST['contents'].encode(TARGET_ENCODING)
        
            if not subject or not contents:
                raise Exception
        except:
            return error(request, u'내용을 입력해 주셔야 합니다.')

	keys = map(lambda x: 'file%d' % x, sorted(map(lambda x: int(x[4:]), request.FILES.keys())))
        keys.reverse()
        for f in keys:
            try:
                prefs = registry.get_prefs(sid)
                url = uploader.upload(request, request.FILES[f], size=prefs.photo_resize, bid=dest, uid=sess[0])
                cx = '<img src=\'%s\' alt=\'%s\' />\n\n' % (url, request.FILES[f].name)
            except Exception, e:
                cx = u'업로드 실패하였습니다: <b>%s</b> (%s)\n\n' % (request.FILES[f].name, str(e))
                
            contents = cx.encode(TARGET_ENCODING) + contents
    
        query = {'subject': subject, 'memo': contents, 'mode': 'write', 'id': pagedefs.PAGE_IDS[dest], 'use_html': '1'}

        try:
            query['category'] = request.POST['category']
        except:
            pass

        l = remote.send_request(request, URL_POST, urllib.urlencode(query), referer=URL_REFERER)
        result, soup = remote.postprocess(l.read())

        redirect_if_not_signed_on(request, result, soup, pagedefs.PAGE_PARSERS[dest])

        errcode, errmsg = pagedefs.PAGE_PARSERS[dest].check_error(request, result, soup)
        if errcode:
            return error_forward(request, errmsg)