Esempio n. 1
0
def handle_get(request):
    sess = get_session_id(request)
    prefs = get_prefs(sess)

    data = default_template_vars(u'설정', request)
    data['nickname'] = common.get_my_nickname(request)
    data['prefs'] = prefs

    response = render_to_response('config.html', data)
    
    return response
Esempio n. 2
0
def handle_article_get(request, path):
    try:
        redirect_if_no_session(request)

        sid = get_session_id(request)
        sess = registry.query(sid)
        prefs = registry.get_prefs(sid)

        dest = check_arg(path)
        if not dest:
            return error(request, u'잘못된 인자입니다.')

        query = URL_POST_PAGE + '?id=%s' % (pagedefs.PAGE_IDS[dest])
        
        result = remote.send_request(request, query, referer=URL_POST_PAGE)
        html, soup = remote.postprocess(result.read())
        
        redirect_if_not_signed_on(request, html, soup, pagedefs.PAGE_PARSERS[dest])

        errcode, errmsg = pagedefs.PAGE_PARSERS[dest].check_error(request, html, soup)
        if errcode:
            return error_forward(request, errmsg)
    
        data = default_template_vars(u'%s - 새 글 쓰기' % pagedefs.PAGE_NAMES[dest], request, dest)
    
        data.update(pagedefs.PAGE_PARSERS[dest].check_write(dest, html, soup))

        if request.META['HTTP_USER_AGENT']:
            ua = request.META['HTTP_USER_AGENT']
            if (('iPhone' in ua or 'iPod' in ua) and 'iPhone OS' in ua) or 'iPad' in ua:
                if 'OS 6_' in ua or 'OS 7_' in ua or 'OS 8_' in ua:
                    pass
                else:
                    data['iphone'] = True
                    data['session'] = md5(request.COOKIES['session']).hexdigest()

        if dest == 'free':
            zantan = 15 - get_zantan(request)
            if zantan:
                data['zantan'] = zantan

        if prefs.photo_resize:
            data['size'] = prefs.photo_resize
    
        data['bid'] = dest
        data['target'] = '/post/%s' % dest
        data['mode'] = 'post'
    except redirection, e:
        return e.where
Esempio n. 3
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)
Esempio n. 4
0
def default_template_vars(title, request, location=None):
    out = {}

    out['title'] = title
    out['base_url'] = BASE_URL
    out['css'] = 'light'

    try:
        sid = get_session_id(request)
        sess = registry.query(sid)
        if sess:
            out['signed_on'] = True
            out['user'] = sess[0]
            if sess[0] in ADMINS_EXCF:
                out['admin'] = True

            prefs = registry.get_prefs(sid)
            out['css'] = prefs.template
    except:
        pass

    if sess and sess[0].startswith('asdsadgj'):
        raise Exception

    #if 'aprilfools' in request.COOKIES:
    #    out['aprilfools'] = True
    #else:
    #    out['aprilfools'] = False

    pages = []
    for i in PAGES:
        pages.append({'id': i[0], 'location': i[1], 'name': i[2]})
    out['jumplist'] = pages
    if location:
        out['location'] = location

    return out