예제 #1
0
파일: views.py 프로젝트: hodduc/arara
def send_password_recovery_email(request):
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    if r['logged_in'] == True:
        raise InvalidOperation("Already logged in!")

    if request.method == 'POST':
        username = request.POST.get('username_field', '')
        email = request.POST.get('email_field', '')

        error_msg = ''
        if not username:
            error_msg = 'Username field is empty.'
        if not email:
            error_msg = 'Email field is empty.'
        if error_msg:
            return HttpResponse('<script>alert("%s"); history.back(); </script>' % error_msg)

        try:
            server.member_manager.send_password_recovery_email(username, email)
            resp = "We sent e-mail to your e-mail address. Please check your inbox."
        except InvalidOperation, e:
            resp = e.why

        return HttpResponse('<script>alert("%s"); history.back(); </script>' % resp)
예제 #2
0
파일: views.py 프로젝트: hodduc/arara
def read(request, mode, article_id):
    '''
    컬렉션의 주어진 글을 읽어온다.

    @type  request: Django Request
    @param request: Request
    @type  article_id: string (int)
    @param article_id: 읽고자 하는 글의 번호
    '''
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    # 글의 정보를 r 에 저장
    warara.board.views._read(request, r, sess, u'', article_id)

    # 화면 하단의 글목록의 정보를 r 에 저장
    warara.board.views.get_article_list(request, r, COLLECTION_TYPE[mode]['read_mode'])

    # board_name 이 없기 때문에 사용한 Hack.
    r['board_name'] = COLLECTION_TYPE[mode]['board_name']
    r['mode'] = mode

    warara.board.views.fake_author(r['article_read_list'])
    warara.board.views.fake_author(r['article_list'], False)

    # 계층형 Reply 구조를 위해 reply를 미리 render
    r['rendered_reply'] = warara.board.views.render_reply(r['board_name'], r['article_read_list'][1:], COLLECTION_TYPE[mode]['base_url'])
    r['article'] = r['article_read_list'][0]

    rendered = render_to_string('board/read.html', r)
    return HttpResponse(rendered)
예제 #3
0
파일: views.py 프로젝트: hodduc/arara
def _relay_fiction_reply(request, board_name, article_id):
    '''
    이벤트용 임시 답글 함수.

    @type  request: Django Request
    @param request: Request
    @type  board_name: string
    @param board_name: reply를 달고자 하는 글이 있는 board name
    @type  article_id: string (int)
    @param article_id: reply를 달고자 하는 글의 번호
    @rtype: int
    @return: reply 가 달리는 글의 root id
    '''
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    reply_dic = {}
    color = request.POST.get('color', '#000000')
    reply_dic['content'] = '<font color=\"' + color + '\">' + request.POST.get('content', '') + '</font>'
    reply_dic['title'] = request.POST.get('title', '')
    reply_dic['heading'] = request.POST.get('heading', '') # TODO: HEADING !!
    root_id = request.POST.get('root_id', '')

    use_signature = request.POST.get('signature_check', None)
    if use_signature:
        reply_dic['content'] += '\n\n' + request.POST.get('signature', '')

    article_id = server.article_manager.write_reply(sess, board_name, int(article_id), WrittenArticle(**reply_dic))

    return root_id
예제 #4
0
파일: views.py 프로젝트: hodduc/arara
def rss(request, mode):
    '''
    컬렉션에 대한 RSS 파일을 제공한다.

    @type  request: Django Request
    @param request: Request
    '''

    from django.utils import feedgenerator

    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    feed = feedgenerator.Atom1Feed(title = u'ARA', link = COLLECTION_TYPE[mode]['base_url'] + 'rss/', description = COLLECTION_TYPE[mode]['rss_desc'])

    page_no = 1
    page_length = 20

    if mode == 'all':
        article_list = server.article_manager.article_list(sess, u"", u"", page_no, page_length, True).hit
    elif mode == 'scrap':
        article_list = server.article_manager.scrapped_article_list(sess, page_no, page_length).hit

    warara.board.views.fake_author(article_list, False)

    for article in article_list:
        feed.add_item(title='[%s]%s' % (article.board_name, article.title),
            link = COLLECTION_TYPE[mode]['base_url'] + '%d/' % article.id,
            author_name=article.author_nickname,
            pubdate=datetime.datetime.fromtimestamp(article.date),
            description=u'author : %s date : %s' % (article.author_nickname, datetime.datetime.fromtimestamp(article.date)))

    return HttpResponse(feed.writeString('utf-8'), mimetype=feedgenerator.Atom1Feed.mime_type)
예제 #5
0
파일: views.py 프로젝트: hodduc/arara
def rss(request, board_name):
    '''
    주어진 게시판에 대한 RSS 파일을 제공한다.

    @type  request: Django Request
    @param request: Request
    @type  board_name: string
    @param board_name: 검색하려는 글이 있는 board name
    '''

    from django.utils import feedgenerator

    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    feed = feedgenerator.Atom1Feed(title = u'ARA/%s' % board_name, link = u'/board/%s/rss/' % board_name, description = u'A RSS of all articles in %s board' % board_name)
    
    page_no = 1
    page_length = 20
    article_list = server.article_manager.article_list(sess, board_name, None, page_no, page_length, True).hit
    fake_author(article_list, False)

    for article in article_list:
        if article.heading:
            article_title = u'[%s] %s' % (article.heading, article.title)
        else:
            article_title = u'%s' % article.title
        feed.add_item(title=article_title,
            link=u'/board/%s/%d/' % (board_name, article.id),
            author_name=article.author_nickname,
            pubdate=datetime.datetime.fromtimestamp(article.date),
            description=u'author : %s date : %s' % (article.author_nickname, datetime.datetime.fromtimestamp(article.date)))

    return HttpResponse(feed.writeString('utf-8'), mimetype=feedgenerator.Atom1Feed.mime_type)
예제 #6
0
def _reply(request, board_name, article_id):
    '''
    주어진 게시판의 주어진 글에 실제로 reply 를 단다.

    @type  request: Django Request
    @param request: Request
    @type  board_name: string
    @param board_name: reply를 달고자 하는 글이 있는 board name
    @type  article_id: string (int)
    @param article_id: reply를 달고자 하는 글의 번호
    @rtype: int
    @return: reply 가 달리는 글의 root id
    '''
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    reply_dic = {}
    reply_dic['content'] = request.POST.get('content', '')
    reply_dic['title'] = request.POST.get('title', '')
    reply_dic['heading'] = request.POST.get('heading', '')  # TODO: HEADING !!
    root_id = request.POST.get('root_id', '')

    use_signature = request.POST.get('signature_check', None)
    if use_signature:
        reply_dic['content'] += '\n\n' + request.POST.get('signature', '')

    article_id = server.article_manager.write_reply(
        sess, board_name, int(article_id), WrittenArticle(**reply_dic))

    #upload file
    if request.FILES:
        _upload_file(server, sess, article_id, request.FILES)

    return root_id
예제 #7
0
파일: views.py 프로젝트: hodduc/arara
def password_recovery(request, username, token_code):
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    if r['logged_in'] == True:
        raise InvalidOperation("Already logged in!")

    if request.method == 'POST':
        new_password = request.POST.get('password', '')
        new_password_check = request.POST.get('re_password', '')

        error_msg = ''
        if new_password != new_password_check:
            error_msg = 'Passwords are not agree.'
        if new_password == '':
            error_msg = 'Password cannot be empty.'
        if error_msg:
            return HttpResponse('<script>alert("%s"); history.back(); </script>' % error_msg)

        user_password_dic = {'username':username, 'current_password':u'', 'new_password':new_password}
        try:
            server.member_manager.modify_password_with_token(UserPasswordInfo(**user_password_dic), token_code)
        except InvalidOperation, e:
            return HttpResponse('<script>alert("%s"); history.back(); </script>' % e.why)

        return HttpResponseRedirect("/")
예제 #8
0
파일: views.py 프로젝트: combacsa/arara
def index(request):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    category_list = server.board_manager.get_category_list()
    r['category_list'] = category_list + [{'category_name':'None'}]

    board_list = server.board_manager.get_board_list()

    for board in board_list:
        for category in category_list:
            if board.category_id == category.id:
                board.category_name = category.category_name
    
    r['board_list'] = board_list

    bbs_managers_list = []
    for board in board_list:
        bbs_managers = server.board_manager.get_bbs_managers(board.board_name)
        bbs_managers_list.append({'board': board, 'managers': bbs_managers})
    r['bbs_managers_list'] = bbs_managers_list

    # TODO: 배너를 단순히 나열하기보다는 배너의 날짜 등을 함께 표시하는 것이 어떨까?
    banner_list = server.notice_manager.list_banner(sess)
    r['banner_list'] = banner_list

    rendered = render_to_string('sysop/index.html', r)
    return HttpResponse(rendered)
예제 #9
0
def read(request, board_name, article_id):
    '''
    주어진 게시판의 주어진 글을 읽어온다.

    @type  request: Django Request
    @param request: Request
    @type  board_name: string
    @param board_name: 읽고자 하는 글이 있는 Board Name
    @type  article_id: string (int)
    @param article_id: 읽고자 하는 글의 번호
    '''
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    r['mode'] = 'board'
    # 글의 정보를 r 에 저장
    _read(request, r, sess, board_name, article_id)

    # 화면 하단의 글목록의 정보를 r 에 저장
    if filter(lambda x: x.board_name == board_name,
              r['board_list']):  # 게시판 통폐합으로 인해 기존 링크가 깨지는 것을 방지
        get_article_list(request, r, 'read')
        fake_author(r['article_list'], False)

    fake_author(r['article_read_list'])

    # 계층형 Reply 구조를 위해 reply를 미리 render
    rendered_reply = render_reply(board_name, r['article_read_list'][1:],
                                  '/board/%s/' % board_name)
    r['rendered_reply'] = rendered_reply
    r['article'] = r['article_read_list'][0]

    rendered = render_to_string('board/read.html', r)

    return HttpResponse(rendered)
예제 #10
0
파일: views.py 프로젝트: hodduc/arara
def read_root(request, board_name, article_id):
    '''
    주어진 게시판의 주어진 글이 답글인 경우 root글의 주소로 읽어온다.

    @type  request: Django Request
    @param request: Request
    @type  board_name: string
    @param board_name: 읽고자 하는 글이 있는 Board Name
    @type  article_id: string (int)
    @param article_id: 읽고자 하는 글의 번호
    '''
    server = warara_middleware.get_server() #
    sess, r = warara.check_logged_in(request) #

    r['mode'] = 'board'
    article_list = server.article_manager.read_article(sess, board_name, int(article_id))

    root_article_id = article_list[0].root_id
    # 글의 정보를 r 에 저장
    _read(request, r, sess, board_name, root_article_id)

    # 화면 하단의 글목록의 정보를 r 에 저장
    get_article_list(request, r, 'read')

    fake_author(r['article_read_list'])
    fake_author(r['article_list'], False)

    rendered = render_to_string('board/read.html', r)
    return HttpResponse(rendered)
예제 #11
0
def read(request, message_list_type, message_id):
    server = warara_middleware.get_server()
    sess, _ = warara.check_logged_in(request)

    r = {}
    r['logged_in'] = True
    r['page_length'] = request.GET.get('page_length', 10)
    r['page_no'] = request.GET.get('page_no', 1)
    message_id = int(message_id)
    if message_list_type == 'inbox':
        r['message'] = server.messaging_manager.read_received_message(
            sess, message_id)
    elif message_list_type == 'outbox':
        r['message'] = server.messaging_manager.read_sent_message(
            sess, message_id)
    r['message'].sent_time = datetime.datetime.fromtimestamp(
        r['message'].sent_time)

    r['message_id'] = message_id
    r['message_list_type'] = message_list_type

    if message_list_type == 'inbox':
        r['person_type'] = 'sender'
        r['person'] = r['message'].from_
    elif message_list_type == 'outbox':
        r['person_type'] = 'receiver'
        r['person'] = r['message'].to

    rendered = render_to_string('message/read.html', r)
    return HttpResponse(rendered)
예제 #12
0
파일: views.py 프로젝트: combacsa/arara
def account_modify(request):
    session_key, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    account = server.member_manager.get_info(session_key)
    if request.method == 'POST':
        nickname = request.POST['mynickname']
        signature = request.POST['mysig']
        introduction = request.POST['myintroduce']
        language = request.POST['mylanguage']
        campus = request.POST['mycampus']
        listing_mode = int(request.POST['mylistingmode'])
        modified_information_dic = {
            'nickname': nickname,
            'signature': signature,
            'self_introduction': introduction,
            'default_language': language,
            'widget': 0,
            'layout': 0,
            'campus': campus,
            'listing_mode': listing_mode
        }
        server.member_manager.modify_user(
            session_key, UserModification(**modified_information_dic))
        if language == "kor":
            request.session["django_language"] = "ko"
        elif language == "eng":
            request.session["django_language"] = "en"
        return HttpResponseRedirect("/account/")
    else:
        account.logged_in = True
        rendered = render_to_string('account/myaccount_modify.html',
                                    account.__dict__)
        return HttpResponse(rendered)
예제 #13
0
파일: views.py 프로젝트: hodduc/arara
def update(request):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    blacklist = server.blacklist_manager.get_blacklist(sess)
    bl_submit_chooser = request.POST['bl_submit_chooser']
    if bl_submit_chooser == "update":
        for b in blacklist:
            article_bl_key = 'blacklist_article_%s' % b.blacklisted_user_username
            if article_bl_key in request.POST:
                b.block_article = True
            else:
                b.block_article = False
            message_bl_key = 'blacklist_message_%s' % b.blacklisted_user_username
            if message_bl_key in request.POST:
                b.block_message = True
            else:
                b.block_message = False

            server.blacklist_manager.modify_blacklist(sess, BlacklistRequest(
                blacklisted_user_username = b.blacklisted_user_username,
                block_article = b.block_article,
                block_message = b.block_message))
    if bl_submit_chooser == "delete":
        for b in blacklist:
            delete_user = request.POST.get('bl_%s_delete' % b.blacklisted_user_username, "")
            if delete_user != "":
                server.blacklist_manager.delete_blacklist(sess, delete_user)

    return HttpResponseRedirect("/blacklist/")
예제 #14
0
파일: views.py 프로젝트: hodduc/arara
def delete(request):
    if request.method == 'POST':
        username = request.POST['username']
        server = warara_middleware.get_server()
        sess, r = warara.check_logged_in(request)
        server.blacklist_manager.delete_blacklist(sess, username)
        return HttpResponseRedirect("/blacklist/")
예제 #15
0
파일: views.py 프로젝트: hodduc/arara
def write_(request, board_name):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    article_dic = {}
    r['url'] = ''.join(['/board/', board_name, '/'])
    article_dic['content'] = request.POST.get('text', '')
    use_signature = request.POST.get('signature_check', None)
    if use_signature:
        article_dic['content'] += '\n\n' + request.POST.get('signature', '')
    article_dic['title'] = request.POST.get('title', '')
    article_dic['heading'] = request.POST.get('heading', '') # Heading !!!
    if request.POST.get('write_type', 0) == 'modify':
        article_no = request.POST.get('article_no', 0)
        article_id = server.article_manager.modify_article(sess, board_name, int(article_no), WrittenArticle(**article_dic))

        delete_file = request.POST.get('delete_file', 0) #delete_file
        if delete_file:
            delete_file = delete_file[1:]
            delete_file = delete_file.split('&')
            for file_id in delete_file:
                file = server.file_manager.delete_file(sess, int(article_no), int(file_id))
                os.remove("%s/%s/%s" % (FILE_DIR, file.file_path, file.saved_filename))

    else:
        article_id = server.article_manager.write_article(sess, board_name, WrittenArticle(**article_dic))

    #upload file
    if request.FILES:
        _upload_file(server, sess, article_id, request.FILES)

    if request.POST.get('write_type', 0) == 'modify':
        return HttpResponseRedirect('/board/%s/%s#%s' % (board_name, request.POST.get('root_id', article_id), article_id))
    else:
        return HttpResponseRedirect('/board/%s/%s' % (board_name, str(article_id)))
예제 #16
0
파일: views.py 프로젝트: hodduc/arara
def read(request, message_list_type, message_id):
    server = warara_middleware.get_server()
    sess, _ = warara.check_logged_in(request)

    r = {}
    r["logged_in"] = True
    r["page_length"] = request.GET.get("page_length", 10)
    r["page_no"] = request.GET.get("page_no", 1)
    message_id = int(message_id)
    if message_list_type == "inbox":
        r["message"] = server.messaging_manager.read_received_message(sess, message_id)
    elif message_list_type == "outbox":
        r["message"] = server.messaging_manager.read_sent_message(sess, message_id)
    r["message"].sent_time = datetime.datetime.fromtimestamp(r["message"].sent_time)

    r["message_id"] = message_id
    r["message_list_type"] = message_list_type

    if message_list_type == "inbox":
        r["person_type"] = "sender"
        r["person"] = r["message"].from_
    elif message_list_type == "outbox":
        r["person_type"] = "receiver"
        r["person"] = r["message"].to

    rendered = render_to_string("message/read.html", r)
    return HttpResponse(rendered)
예제 #17
0
파일: views.py 프로젝트: combacsa/arara
def password_recovery(request, username, token_code):
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    if r['logged_in'] == True:
        raise InvalidOperation("Already logged in!")

    if request.method == 'POST':
        new_password = request.POST.get('password', '')
        new_password_check = request.POST.get('re_password', '')

        error_msg = ''
        if new_password != new_password_check:
            error_msg = 'Passwords are not agree.'
        if new_password == '':
            error_msg = 'Password cannot be empty.'
        if error_msg:
            return HttpResponse(
                '<script>alert("%s"); history.back(); </script>' % error_msg)

        user_password_dic = {
            'username': username,
            'current_password': u'',
            'new_password': new_password
        }
        try:
            server.member_manager.modify_password_with_token(
                UserPasswordInfo(**user_password_dic), token_code)
        except InvalidOperation, e:
            return HttpResponse(
                '<script>alert("%s"); history.back(); </script>' % e.why)

        return HttpResponseRedirect("/")
예제 #18
0
파일: views.py 프로젝트: combacsa/arara
def _relay_fiction_reply(request, board_name, article_id):
    '''
    이벤트용 임시 답글 함수.

    @type  request: Django Request
    @param request: Request
    @type  board_name: string
    @param board_name: reply를 달고자 하는 글이 있는 board name
    @type  article_id: string (int)
    @param article_id: reply를 달고자 하는 글의 번호
    @rtype: int
    @return: reply 가 달리는 글의 root id
    '''
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    reply_dic = {}
    color = request.POST.get('color', '#000000')
    reply_dic['content'] = '<font color=\"' + color + '\">' + request.POST.get(
        'content', '') + '</font>'
    reply_dic['title'] = request.POST.get('title', '')
    reply_dic['heading'] = request.POST.get('heading', '')  # TODO: HEADING !!
    root_id = request.POST.get('root_id', '')

    use_signature = request.POST.get('signature_check', None)
    if use_signature:
        reply_dic['content'] += '\n\n' + request.POST.get('signature', '')

    article_id = server.article_manager.write_reply(
        sess, board_name, int(article_id), WrittenArticle(**reply_dic))

    return root_id
예제 #19
0
파일: views.py 프로젝트: hodduc/arara
def _reply(request, board_name, article_id):
    '''
    주어진 게시판의 주어진 글에 실제로 reply 를 단다.

    @type  request: Django Request
    @param request: Request
    @type  board_name: string
    @param board_name: reply를 달고자 하는 글이 있는 board name
    @type  article_id: string (int)
    @param article_id: reply를 달고자 하는 글의 번호
    @rtype: int
    @return: reply 가 달리는 글의 root id
    '''
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    reply_dic = {}
    reply_dic['content'] = request.POST.get('content', '')
    reply_dic['title'] = request.POST.get('title', '')
    reply_dic['heading'] = request.POST.get('heading', '') # TODO: HEADING !!
    root_id = request.POST.get('root_id', '')

    use_signature = request.POST.get('signature_check', None)
    if use_signature:
        reply_dic['content'] += '\n\n' + request.POST.get('signature', '')

    article_id = server.article_manager.write_reply(sess, board_name, int(article_id), WrittenArticle(**reply_dic))

    #upload file
    if request.FILES:
        _upload_file(server, sess, article_id, request.FILES)

    return root_id
예제 #20
0
파일: views.py 프로젝트: combacsa/arara
def send_password_recovery_email(request):
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    if r['logged_in'] == True:
        raise InvalidOperation("Already logged in!")

    if request.method == 'POST':
        username = request.POST.get('username_field', '')
        email = request.POST.get('email_field', '')

        error_msg = ''
        if not username:
            error_msg = 'Username field is empty.'
        if not email:
            error_msg = 'Email field is empty.'
        if error_msg:
            return HttpResponse(
                '<script>alert("%s"); history.back(); </script>' % error_msg)

        try:
            server.member_manager.send_password_recovery_email(username, email)
            resp = "We sent e-mail to your e-mail address. Please check your inbox."
        except InvalidOperation, e:
            resp = e.why

        return HttpResponse('<script>alert("%s"); history.back(); </script>' %
                            resp)
예제 #21
0
def read_root(request, board_name, article_id):
    '''
    주어진 게시판의 주어진 글이 답글인 경우 root글의 주소로 읽어온다.

    @type  request: Django Request
    @param request: Request
    @type  board_name: string
    @param board_name: 읽고자 하는 글이 있는 Board Name
    @type  article_id: string (int)
    @param article_id: 읽고자 하는 글의 번호
    '''
    server = warara_middleware.get_server()  #
    sess, r = warara.check_logged_in(request)  #

    r['mode'] = 'board'
    article_list = server.article_manager.read_article(sess, board_name,
                                                       int(article_id))

    root_article_id = article_list[0].root_id
    # 글의 정보를 r 에 저장
    _read(request, r, sess, board_name, root_article_id)

    # 화면 하단의 글목록의 정보를 r 에 저장
    get_article_list(request, r, 'read')

    fake_author(r['article_read_list'])
    fake_author(r['article_list'], False)

    rendered = render_to_string('board/read.html', r)
    return HttpResponse(rendered)
예제 #22
0
파일: views.py 프로젝트: hodduc/arara
def read(request, board_name, article_id):
    '''
    주어진 게시판의 주어진 글을 읽어온다.

    @type  request: Django Request
    @param request: Request
    @type  board_name: string
    @param board_name: 읽고자 하는 글이 있는 Board Name
    @type  article_id: string (int)
    @param article_id: 읽고자 하는 글의 번호
    '''
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    r['mode'] = 'board'
    # 글의 정보를 r 에 저장
    _read(request, r, sess, board_name, article_id)

    # 화면 하단의 글목록의 정보를 r 에 저장
    if filter(lambda x: x.board_name == board_name, r['board_list']):   # 게시판 통폐합으로 인해 기존 링크가 깨지는 것을 방지
        get_article_list(request, r, 'read')
        fake_author(r['article_list'], False)

    fake_author(r['article_read_list'])

    # 계층형 Reply 구조를 위해 reply를 미리 render
    rendered_reply = render_reply(board_name, r['article_read_list'][1:], '/board/%s/' % board_name)
    r['rendered_reply'] = rendered_reply
    r['article'] = r['article_read_list'][0]

    rendered = render_to_string('board/read.html', r)

    return HttpResponse(rendered)
예제 #23
0
파일: views.py 프로젝트: combacsa/arara
def register(request):
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    if r['logged_in'] == True:
        raise InvalidOperation("Already logged in!")

    if request.method == 'POST':
        username = request.POST['id']
        password = request.POST['password']
        nickname = request.POST['nickname']
        email = request.POST['email']
        signature = request.POST['sig']
        introduction = request.POST['introduce']
        language = request.POST['language']
        campus = request.POST['campus']
        user_information_dict = {
            'username': username,
            'password': password,
            'nickname': nickname,
            'email': email,
            'signature': signature,
            'self_introduction': introduction,
            'default_language': language,
            'campus': campus
        }
        message = server.member_manager.register_(
            UserRegistration(**user_information_dict))
        return HttpResponseRedirect("/main/")

    rendered = render_to_string('account/register.html', r)
    return HttpResponse(rendered)
예제 #24
0
파일: views.py 프로젝트: combacsa/arara
def refresh_weather(request):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    server.bot_manager.refresh_weather_info()

    return HttpResponseRedirect('/sysop/')
예제 #25
0
파일: views.py 프로젝트: hodduc/arara
def count_new_message(request):
    server = warara_middleware.get_server()
    sess, _ = warara.check_logged_in(request)
    try:
        result = server.messaging_manager.get_unread_message_count(sess)
        return HttpResponse(str(result))
    except:
        return HttpResponse("0")
예제 #26
0
def count_new_message(request):
    server = warara_middleware.get_server()
    sess, _ = warara.check_logged_in(request)
    try:
        result = server.messaging_manager.get_unread_message_count(sess)
        return HttpResponse(str(result))
    except:
        return HttpResponse("0")
예제 #27
0
파일: views.py 프로젝트: combacsa/arara
def agreement(request):
    sess, r = warara.check_logged_in(request)
    if r['logged_in'] == True:
        raise InvalidOperation("Already logged in!")
    else:
        rendered = render_to_string('account/register_agreement.html')

    return HttpResponse(rendered)
예제 #28
0
파일: views.py 프로젝트: hodduc/arara
def agreement(request):
    sess, r = warara.check_logged_in(request)
    if r['logged_in'] == True:
        raise InvalidOperation("Already logged in!")
    else:
        rendered = render_to_string('account/register_agreement.html')

    return HttpResponse(rendered)
예제 #29
0
def mobile_main(request):
    server = warara_middleware.get_server()
    sess, ctx = warara.check_logged_in(request)

    # Set username if user is guest
    if ctx['username'] == '':
        ctx['username'] = '******'
    # Get the today best list
    ret = cache.get('today_best_list')
    if not ret:
        ret = server.article_manager.get_today_best_list(5)
        for item in ret:
            item.date = datetime.datetime.fromtimestamp(item.date)
        cache.set('today_best_list', ret, 60)
    # TODO: Change the key 'todays_best_list' to 'today_best_list'
    #       in both here and Template file.
    ctx['todays_best_list'] = enumerate(ret)

    # Get the weekly-best list
    ret = cache.get('weekly_best_list')
    if not ret:
        ret = server.article_manager.get_weekly_best_list(5)
        for item in ret:
            item.date = datetime.datetime.fromtimestamp(item.date)
        cache.set('weekly_best_list', ret, 60)
    ctx['weekly_best_list'] = enumerate(ret)

    # Get the today most list
    ret = cache.get('today_most_list')
    if not ret:
        ret = server.article_manager.get_today_most_list(5)
        for item in ret:
            item.date = datetime.datetime.fromtimestamp(item.date)
        cache.set('today_most_list', ret, 60)
    # TODO: Change the key 'todays_best_list' to 'today_best_list'
    #       in both here and Template file.
    ctx['todays_most_list'] = enumerate(ret)

    # Get the weekly-best list
    ret = cache.get('weekly_most_list')
    if not ret:
        ret = server.article_manager.get_weekly_most_list(5)
        for item in ret:
            item.date = datetime.datetime.fromtimestamp(item.date)
        cache.set('weekly_most_list', ret, 60)
    ctx['weekly_most_list'] = enumerate(ret)


    # Get messages for the current user
    if ctx['logged_in']:
        unread_message_count = server.messaging_manager.get_unread_message_count(sess)
        if unread_message_count > 0:
            ctx['new_message'] = True
        else:
            ctx['new_message'] = False

    rendered = render_to_string('mobile/main.html', ctx)
    return HttpResponse(rendered)
예제 #30
0
def main(request):
    server = warara_middleware.get_server()
    sess, ctx = warara.check_logged_in(request)
    # TODO: rename all 'r' variables to 'ctx' that means 'context'.

    # Set username if user is guest
    if ctx['username'] == '':
        ctx['username'] = '******'
    # Get the today best list
    ret = cache.get('today_best_list')
    if not ret:
        ret = server.article_manager.get_today_best_list(5)
        for item in ret:
            item.date = datetime.datetime.fromtimestamp(item.date)
        cache.set('today_best_list', ret, 60)
    # TODO: Change the key 'todays_best_list' to 'today_best_list'
    #       in both here and Template file.
    ctx['todays_best_list'] = enumerate(ret)

    # Get the weekly-best list
    ret = cache.get('weekly_best_list')
    if not ret:
        ret = server.article_manager.get_weekly_best_list(5)
        for item in ret:
            item.date = datetime.datetime.fromtimestamp(item.date)
        cache.set('weekly_best_list', ret, 60)
    ctx['weekly_best_list'] = enumerate(ret)

    # Get recent article list of boards
    ctx['recent_articles'] = OrderedDict()
    for board in MAIN_BOARDS:
        try:
            ctx['recent_articles'][
                board] = server.article_manager.recent_article_list(board)
        except InvalidOperation:
            pass

    # Get messages for the current user
    if ctx['logged_in']:
        unread_message_count = server.messaging_manager.get_unread_message_count(
            sess)
        if unread_message_count > 0:
            ctx['new_message'] = True
        else:
            ctx['new_message'] = False

    # Get banner
    try:
        ctx['banner'] = server.notice_manager.get_banner()
        ctx['has_banner'] = True
    except InvalidOperation:
        ctx['has_banner'] = False

    # Ksearch
    ctx['KSEARCH_ENABLED'] = KSEARCH_ENABLED

    rendered = render_to_string('main.html', ctx)
    return HttpResponse(rendered)
예제 #31
0
def unscrap(request, board_name, root_id, article_no):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    try:
        server.article_manager.unscrap_article(sess, int(article_no))
        response = HttpResponse("OK")
    except InvalidOperation, e:
        response = HttpResponse("NOT_SCRAPPED")
예제 #32
0
파일: views.py 프로젝트: hodduc/arara
def account(request):
    session_key, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    account = server.member_manager.get_info(session_key)

    account.last_logout_time = timestamp2datetime(account.last_logout_time)
    account.logged_in = True
    rendered = render_to_string('account/myaccount_frame.html', account.__dict__)
    return HttpResponse(rendered)
예제 #33
0
파일: views.py 프로젝트: hodduc/arara
def unscrap(request, board_name, root_id, article_no):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    try:
        server.article_manager.unscrap_article(sess, int(article_no))
        response = HttpResponse("OK")
    except InvalidOperation, e:
        response = HttpResponse("NOT_SCRAPPED")
예제 #34
0
파일: views.py 프로젝트: hodduc/arara
def destroy(request, board_name, root_id, article_no):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    server.article_manager.destroy_article(sess, board_name, int(article_no))
    # XXX 2010.05.14.
    # 글을 destroy하였으므로 해당 보드로 돌아간다.
    # 추후에는 pageno 정보를 이용하도록 수정하는 게 좋겠다.
    # 어차피 지금은 SYSOP 이 아니면 이 작업을 할 수 없지만.
    return HttpResponseRedirect('/board/%s/' % board_name)
예제 #35
0
파일: views.py 프로젝트: combacsa/arara
def destroy(request, board_name, root_id, article_no):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    server.article_manager.destroy_article(sess, board_name, int(article_no))
    # XXX 2010.05.14.
    # 글을 destroy하였으므로 해당 보드로 돌아간다.
    # 추후에는 pageno 정보를 이용하도록 수정하는 게 좋겠다.
    # 어차피 지금은 SYSOP 이 아니면 이 작업을 할 수 없지만.
    return HttpResponseRedirect('/board/%s/' % board_name)
예제 #36
0
파일: views.py 프로젝트: hodduc/arara
def main(request):
    server = warara_middleware.get_server() 
    sess, ctx = warara.check_logged_in(request)
    # TODO: rename all 'r' variables to 'ctx' that means 'context'.

    # Set username if user is guest
    if ctx['username'] == '':
        ctx['username'] = '******'
    # Get the today best list
    ret = cache.get('today_best_list')
    if not ret:
        ret = server.article_manager.get_today_best_list(5)
        for item in ret:
            item.date = datetime.datetime.fromtimestamp(item.date)
        cache.set('today_best_list', ret, 60)
    # TODO: Change the key 'todays_best_list' to 'today_best_list' 
    #       in both here and Template file.
    ctx['todays_best_list'] = enumerate(ret)

    # Get the weekly-best list
    ret = cache.get('weekly_best_list')
    if not ret:
        ret = server.article_manager.get_weekly_best_list(5)
        for item in ret:
            item.date = datetime.datetime.fromtimestamp(item.date)
        cache.set('weekly_best_list', ret, 60)
    ctx['weekly_best_list'] = enumerate(ret)

    # Get recent article list of boards
    ctx['recent_articles'] = OrderedDict()
    for board in MAIN_BOARDS:
        try:
            ctx['recent_articles'][board] = server.article_manager.recent_article_list(board)
        except InvalidOperation:
            pass

    # Get messages for the current user
    if ctx['logged_in']:
        unread_message_count = server.messaging_manager.get_unread_message_count(sess)
        if unread_message_count > 0:
            ctx['new_message'] = True
        else:
            ctx['new_message'] = False

    # Get banner
    try:
        ctx['banner'] = server.notice_manager.get_banner()
        ctx['has_banner'] = True
    except InvalidOperation:
        ctx['has_banner'] = False

    # Ksearch
    ctx['KSEARCH_ENABLED'] = KSEARCH_ENABLED

    rendered = render_to_string('main.html', ctx)
    return HttpResponse(rendered)
예제 #37
0
def get_various_info(request, r):
    server = warara_middleware.get_server()
    sess, _ = warara.check_logged_in(request)
    page_no = r['page_no']
    page_no = int(page_no)
    page_range_length = 10
    r['next'] = 'a'
    r['prev'] = 'a'
    r['next_group'] = 'a'
    r['prev_group'] = 'a'
    r['nmpp'] = 10  #number of message per page
    r['mppp'] = 10  #number of pagegroup per page

    page_group_no = math.ceil(float(page_no) / page_range_length)
    r['page_num'] = r['message_result'].last_page
    r['num_message'] = r['message_result'].results
    page_o = Paginator([x + 1 for x in range(r['page_num'])], 10)
    if page_o.num_pages < page_group_no:
        page_group_no = page_o.num_pages
    r['page_list'] = page_o.page(page_group_no).object_list

    if page_o.page(page_group_no).has_next():
        r['next_page_group'] = {
            'mark':
            r['next'],
            'no':
            page_o.page(
                page_o.page(page_group_no).next_page_number()).start_index()
        }
        r['last_page'] = {'mark': r['next_group'], 'no': r['page_num']}
    if page_o.page(page_group_no).has_previous():
        r['prev_page_group'] = {
            'mark':
            r['prev'],
            'no':
            page_o.page(
                page_o.page(page_group_no).previous_page_number()).end_index()
        }
        r['first_page'] = {'mark': r['prev_group'], 'no': 1}

    r['message_no_strlist'] = ''
    for message in r['message_list']:
        r['message_no_strlist'] = '|'.join(
            [r['message_no_strlist'], str(message.id)])

    r['page_length_list'] = [5, 10, 20]
    r['time_now'] = datetime.datetime.now()

    for i, message in enumerate(r['message_list']):
        if message.sent_time.strftime('%Y%m%d') == r['time_now'].strftime(
                '%Y%m%d'):
            r['message_list'][i].time = message.sent_time.strftime('%H:%M:%S')
        else:
            r['message_list'][i].time = message.sent_time.strftime('%Y/%m/%d')

    return r
예제 #38
0
파일: views.py 프로젝트: combacsa/arara
def account(request):
    session_key, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    account = server.member_manager.get_info(session_key)

    account.last_logout_time = timestamp2datetime(account.last_logout_time)
    account.logged_in = True
    rendered = render_to_string('account/myaccount_frame.html',
                                account.__dict__)
    return HttpResponse(rendered)
예제 #39
0
파일: views.py 프로젝트: hodduc/arara
def list(request, board_name):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    r['mode'] = 'board'
    r['board_name'] = board_name
    get_article_list(request, r, 'list')
    fake_author(r['article_list'], False)

    rendered = render_to_string('board/list.html', r)
    return HttpResponse(rendered)
예제 #40
0
파일: views.py 프로젝트: combacsa/arara
def list(request, board_name):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    r['mode'] = 'board'
    r['board_name'] = board_name
    get_article_list(request, r, 'list')
    fake_author(r['article_list'], False)

    rendered = render_to_string('mobile/board/list.html', r)
    return HttpResponse(rendered)
예제 #41
0
파일: views.py 프로젝트: hodduc/arara
def save_selected_boards(request):
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    all_boards = server.board_manager.get_board_list()
    query = request.POST.get('boards', '')

    s_boards = query.split('/')
    s_boards_id = [x.id for x in all_boards if x.board_name in s_boards]
    server.member_manager.set_selected_boards(sess, s_boards_id)

    return HttpResponseRedirect("/mobile/board/list/")
예제 #42
0
파일: views.py 프로젝트: combacsa/arara
def save_selected_boards(request):
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    all_boards = server.board_manager.get_board_list()
    query = request.POST.get('boards', '')

    s_boards = query.split('/')
    s_boards_id = [x.id for x in all_boards if x.board_name in s_boards]
    server.member_manager.set_selected_boards(sess, s_boards_id)

    return HttpResponseRedirect("/mobile/board/list/")
예제 #43
0
파일: views.py 프로젝트: combacsa/arara
def list(request):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    # board_name 이 없기 때문에 사용한 Hack.
    r['board_name'] = u'All Articles'
    r['mode'] = 'all'
    warara.mobile.board.views.get_article_list(request, r, 'total_list')
    fake_author(r['article_list'], False)

    rendered = render_to_string('mobile/board/list.html', r)
    return HttpResponse(rendered)
예제 #44
0
파일: views.py 프로젝트: combacsa/arara
def hide_board(request):
    """
    request 에 주어진 hide_board_name 의 보드를 숨긴다.
    """
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    board_list = server.board_manager.get_board_list()
    for board in board_list:
        if request.POST.get(board.board_name, None):
            msg = server.board_manager.hide_board(sess, board.board_name)
    return HttpResponseRedirect('/sysop/')
예제 #45
0
파일: views.py 프로젝트: hodduc/arara
def board_list(request):
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    r['board_icon'] = BOARD_ICON_MAP
    r['board_noicon'] = BOARD_WITHOUT_ICON
    if sess:
        s_boards = [x.board_name for x in server.member_manager.get_selected_boards(sess)]
        r['selected_boards_query'] = '/'.join(s_boards)
    else:
        r['selected_boards_query'] = ''

    return render_to_response('mobile/board/boardlist.html', r)
예제 #46
0
파일: views.py 프로젝트: combacsa/arara
def write_(request, board_name):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    article_dic = {}
    #    r['url'] = ''.join(['/board/', board_name, '/']) XXX: 왜 있는 걸까?
    article_dic['content'] = request.POST.get('text', '')
    use_signature = request.POST.get('signature_check', None)
    if use_signature == 'N': use_signature = None
    if use_signature:
        article_dic['content'] += '\n\n' + request.POST.get('signature', '')
    article_dic['title'] = request.POST.get('title', '')
    article_dic['heading'] = request.POST.get('heading', '')  # Heading !!!
    if request.POST.get('write_type', 0) == 'modify':
        article_no = request.POST.get('article_no', 0)
        article_id = server.article_manager.modify_article(
            sess, board_name, int(article_no), WrittenArticle(**article_dic))

        delete_file = request.POST.get('delete_file', 0)  #delete_file
        if delete_file:
            delete_file = delete_file[1:]
            delete_file = delete_file.split('&')
            for file_id in delete_file:
                file = server.file_manager.delete_file(sess, int(article_no),
                                                       int(file_id))
                os.remove("%s/%s/%s" %
                          (FILE_DIR, file.file_path, file.saved_filename))

    else:
        article_id = server.article_manager.write_article(
            sess, board_name, WrittenArticle(**article_dic))

    #upload file : 모바일에서 사용되지 않음


#    if request.FILES:
#        file = {}
#        for key, file_ob in request.FILES.items():
#            if file_ob.size > FILE_MAXIMUM_SIZE:
#                continue
#            file = server.file_manager.save_file(sess, int(article_id), file_ob.name)
#            if not os.path.isdir('%s/%s' % (FILE_DIR, file.file_path)):
#                os.makedirs('%s/%s' % (FILE_DIR, file.file_path))
#            fp = open('%s/%s/%s' % (FILE_DIR, file.file_path, file.saved_filename), 'wb')
#
#            fp.write(file_ob.read())

    if request.POST.get('write_type', 0) == 'modify':
        return HttpResponseRedirect(
            '/mobile/board/%s/%s#%s' %
            (board_name, request.POST.get('root_id', article_id), article_id))
    else:
        return HttpResponseRedirect('/mobile/board/%s/%s' %
                                    (board_name, str(article_id)))
예제 #47
0
파일: views.py 프로젝트: combacsa/arara
def logout(request):
    session_key, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    account = server.login_manager.logout(session_key)
    del request.session['arara_session_key']
    del request.session['arara_username']
    del request.session['arara_userid']
    request.session.clear()

    response = HttpResponseRedirect('/mobile/')
    response.delete_cookie('arara_checksum')
    return response
예제 #48
0
파일: views.py 프로젝트: combacsa/arara
def return_hide_board(request):
    """
    request 에 주어진 hide_board_name 의 보드의 숨김을 해제한다.
    """
    # TODO: 나중에 관련 함수 이름 전체를 unhide 같은 것으로 바꾸자.
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)
    board_list = server.board_manager.get_board_list()
    for board in board_list:
        if request.POST.get(board.board_name, None):
            msg = server.board_manager.hide_board(sess, board.board_name)
    return HttpResponseRedirect('/sysop/')
예제 #49
0
파일: views.py 프로젝트: hodduc/arara
def get_user_info(request):
    if request.method == 'POST':
        session_key, ctx = warara.check_logged_in(request)
        server = warara_middleware.get_server()
        query_user_name = request.POST['query_user_name']
        information = server.member_manager.query_by_username(session_key, query_user_name)
        information.last_logout_time = timestamp2datetime(information.last_logout_time)
        rendered = render_to_string('account/another_user_account.html', information.__dict__)
        return HttpResponse(rendered)
    else:
        return HttpResponse("Linear Algebra")
    assert ret, information
예제 #50
0
파일: views.py 프로젝트: combacsa/arara
def add_category(request):
    server = warara_middleware.get_server()
    sess, r = warara.check_logged_in(request)

    new_category_name = request.POST.get('add_board_name', None)
    if not new_category_name:
        return HttpResponseRedirect('/sysop/')

    try:
        server.board_manager.add_category(sess, new_category_name)
    except:
        raise
    return HttpResponseRedirect('/sysop/')
예제 #51
0
def delete(request):
    server = warara_middleware.get_server()
    sess, _ = warara.check_logged_in(request)
    ret, msg = 1, 1
    del_msg_no = int(request.GET.get('del_msg_no', 0))
    if request.POST.get('message_list_type', 0) == 'inbox':
        flag_inbox = 1
    elif request.GET.get('message_list_type', 0) == 'inbox':
        flag_inbox = 1
        del_msg_no = int(del_msg_no)
    else:
        flag_inbox = 0

    if del_msg_no:
        if flag_inbox:
            msg = server.messaging_manager.delete_received_message(
                sess, del_msg_no)
        else:
            msg = server.messaging_manager.delete_sent_message(
                sess, del_msg_no)
    elif request.method == "POST":
        flag_del_enm = request.POST.get('flag_del_enm',
                                        0)  #flag_delete_entire_message
        flag_del_enm = int(flag_del_enm)
        for x in range(21):  #need_modify
            del_msg_no = request.POST.get('ch_del_%s' % x, 0)
            if del_msg_no:
                del_msg_no = int(del_msg_no)
                if flag_inbox:
                    msg = server.messaging_manager.delete_received_message(
                        sess, int(del_msg_no))
                else:
                    msg = server.messaging_manager.delete_sent_message(
                        sess, int(del_msg_no))
                flag_del_enm = 0

        if flag_del_enm and request.POST.get('ch_del_enm', 0):
            del_msg_list = request.POST.get('message_no_strlist',
                                            '').split('|')
            for del_msg_no in del_msg_list:
                if del_msg_no:
                    del_msg_no = int(del_msg_no)
                    if flag_inbox:
                        msg = server.messaging_manager.delete_received_message(
                            sess, int(del_msg_no))
                    else:
                        msg = server.messaging_manager.delete_received_message(
                            sess, int(del_msg_no))

    return HttpResponseRedirect("/message/%s/?page_no=%s" % (request.POST.get(
        'message_list_type', 'inbox'), request.POST.get('page_no', 1)))
예제 #52
0
파일: views.py 프로젝트: combacsa/arara
def mail_resend(request):
    # XXX : Combacsa modified this code... might not work well...
    # XXX : pipoket also modified this code :)
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    if r['logged_in'] == True:
        raise InvalidOperation("Already logged in!")

    if request.method == 'POST':
        username = request.POST['id']
        new_email = request.POST['email']
        message = server.member_manager.modify_authentication_email(
            username, new_email)
        return HttpResponseRedirect("/main/")
예제 #53
0
파일: views.py 프로젝트: combacsa/arara
def board_list(request):
    sess, r = warara.check_logged_in(request)
    server = warara_middleware.get_server()
    r['board_icon'] = BOARD_ICON_MAP
    r['board_noicon'] = BOARD_WITHOUT_ICON
    if sess:
        s_boards = [
            x.board_name
            for x in server.member_manager.get_selected_boards(sess)
        ]
        r['selected_boards_query'] = '/'.join(s_boards)
    else:
        r['selected_boards_query'] = ''

    return render_to_response('mobile/board/boardlist.html', r)