Beispiel #1
0
def forum_password_page(request):
    ub = get_user_by_cookie(request)
    if ub == False:
        return auth_fail_tip()
    if request.method == 'GET':
        return render(request, 'forum_update_password.html',
                      {'meta': get_page_meta(request)})
    elif request.method == 'POST':
        param = request.POST
        if check_password(param['old_password'], ub.password) == False:
            return user_tip_page('Operation Fail',
                                 'Your old password is not correct',
                                 jump_to_back=True)
        if param['new_password1'] != param['new_password2']:
            return user_tip_page('Operation Fail',
                                 'Two passwords do not match',
                                 jump_to_back=True)
        if check_password_length(param['new_password1']) == False:
            return user_tip_page('Operation Fail',
                                 'Password length must be between 6 and 15',
                                 jump_to_back=True)
        # Use this to logout, just write a false to the cookie
        record_login(request, '', '', False)
        return user_tip_page(
            'Operation Successful',
            'Your password has been updated. Please login again.',
            jump_to_login=True)
Beispiel #2
0
def forum_password_page(request):
    ub = get_user_by_cookie(request)
    if ub == False:
        return auth_fail_tip()
    if request.method == 'GET':
        return render(request,'forum_update_password.html',
                      {'meta': get_page_meta(request)})
    elif request.method == 'POST':
        param = request.POST
        if check_password(param['old_password'],ub.password) == False:
            return user_tip_page('Operation Fail',
                                 'Your old password is not correct',
                                 jump_to_back=True)
        if param['new_password1'] != param['new_password2']:
            return user_tip_page('Operation Fail',
                                 'Two passwords do not match',
                                 jump_to_back=True)
        if check_password_length(param['new_password1']) == False:
            return user_tip_page('Operation Fail',
                                 'Password length must be between 6 and 15',
                                 jump_to_back=True)
        # Use this to logout, just write a false to the cookie
        record_login(request,'','',False)
        return user_tip_page('Operation Successful',
                             'Your password has been updated. Please login again.',
                             jump_to_login=True)
Beispiel #3
0
def forum_profile_page(request):
    ub = get_user_by_cookie(request)
    meta = get_page_meta(request)
    if ub == False:
        return user_tip_page('Authorization Fail','You need to login first',
                             jump_to_back=True,jump_to_main=True)
    pt = ProfileType.objects.all()
    return render(request,'forum_profile_page.html',{'meta': meta,
                                                     'profile_type': pt})
Beispiel #4
0
def forum_profile_page(request):
    ub = get_user_by_cookie(request)
    meta = get_page_meta(request)
    if ub == False:
        return user_tip_page('Authorization Fail',
                             'You need to login first',
                             jump_to_back=True,
                             jump_to_main=True)
    pt = ProfileType.objects.all()
    return render(request, 'forum_profile_page.html', {
        'meta': meta,
        'profile_type': pt
    })
Beispiel #5
0
def sync_all_board(request):
    ret = check_forum_system_admin(request)
    if ret == False:
        return user_not_authentic_error_page()
    elif ret == None:
        return user_not_login_error_page()

    boards = BoardBasic.objects.all()
    for i in boards:
        synchronize_board_statistics(request, i.bid)

    return user_tip_page('Operation Successful',
                         "The forum has been synchronized",
                         jump_to_main=True)
Beispiel #6
0
def sync_all_board(request):
    ret = check_forum_system_admin(request)
    if ret == False:
        return user_not_authentic_error_page()
    elif ret == None:
        return user_not_login_error_page()

    boards = BoardBasic.objects.all()
    for i in boards:
        synchronize_board_statistics(request,i.bid)
        
    return user_tip_page('Operation Successful',
                         "The forum has been synchronized",
                         jump_to_main=True)
Beispiel #7
0
def forum_uploadimage_page(request):
    if request.method == 'POST':
        form = ImageForm(request.POST, request.FILES)
        if form.is_valid():
            ub = get_user_by_cookie(request)
            if ub == False:
                raise Http404
            else:
                ue = ub.userextend
            ue.image = form.cleaned_data['img']
            ue.save()
            return user_tip_page(
                'Image Uploaded Successfuly',
                'Now you can refresh the page and see a change',
                jump_to_back=True,
                meta=get_page_meta(request))
        else:
            raise Http404
    else:
        form = ImageForm()
        return render(request, 'forum_upload_image.html', {'form': form})
Beispiel #8
0
def forum_uploadimage_page(request):
    if request.method == 'POST':
        form = ImageForm(request.POST,request.FILES)
        if form.is_valid():
            ub = get_user_by_cookie(request)
            if ub == False:
                raise Http404
            else:
                ue = ub.userextend
            ue.image = form.cleaned_data['img']
            ue.save()
            return user_tip_page('Image Uploaded Successfuly',
                                 'Now you can refresh the page and see a change',
                                 jump_to_back=True,
                                 meta=get_page_meta(request))
        else:
            raise Http404
    else:
        form = ImageForm()
        return render(request,'forum_upload_image.html',
                      {'form': form})
Beispiel #9
0
def auth_fail_tip():
    return user_tip_page('Authentication Fail',
                         'You need to login first',
                         jump_to_login=True,
                         jump_to_back=True)
Beispiel #10
0
def forum_thread_page(request, bid, page='1', thread_per_page='30'):
    """
    Display a page of threads, using the given page number and num_of_threads
    per page.
    """
    # Parameters are always passed using Unicode no matter what it is in the
    # regexp
    page = int(page)
    thread_per_page = int(thread_per_page)

    meta = get_page_meta(request)
    # We use cached data instead of doing query a each time. So please keep the
    # data synchronized
    try:
        board_basic = BoardBasic.objects.get(pk=bid)
    except ObjectDoesNotExist:
        return user_tip_page('Board Does Not Exist',
                             'Please check your URL',
                             jump_to_back=True,
                             meta=meta)
    else:
        thread_num = board_basic.thread_num
    # Do part of the queries here
    threads = ThreadBasic.objects.filter(bid__bid__exact=bid)
    other = threads.exclude(privilege__exact=-1).filter(
        hided__exact=False).order_by('-privilege', '-last_reply_time').all()
    # Only show these threads when it is the first page
    uppermost_temp = threads.filter(
        privilege__exact=-1, hided__exact=False).order_by('-last_reply_time')
    hidden_num = threads.filter(hided__exact=True).count()
    normal_thread_num = thread_num - uppermost_temp.count() - hidden_num
    #return debug_output(thread_num)
    if page == 1:
        # Just do the query
        uppermost = uppermost_temp.all()
    else:
        uppermost = []
        # These cannot be counted into the normal threads

    page_range = get_page_range(page, normal_thread_num, thread_per_page)
    # If there is no content on the first page then return a null set
    if page_range == False:
        if page == 1:
            other = []
            total_page = 1
        else:  # If not requesting page number 1, then just raise an error
            return user_tip_page('Page Does Not Exist',
                                 'Please check your page number',
                                 jump_to_back=True,
                                 meta=meta)
    else:
        other = other[page_range[0]:page_range[1]]
        total_page = page_range[2]

    #return HttpResponse(str(normal_thread_num),content_type='text/html')
    return render_to_response(
        'forum_thread.html',
        {
            'threads': {
                'uppermost': uppermost,
                'other': other,
            },  # Two parts
            'board_basic': board_basic,
            'thread_per_page': thread_per_page,
            'total_page': total_page,
            'current_page': page,
            'meta': meta
        },
        context_instance=RequestContext(request))  # CSRF
Beispiel #11
0
def forum_post_page(request, tid, page='1', post_per_page='30'):
    page = int(page)
    post_per_page = int(post_per_page)
    tid = int(tid)
    meta = get_page_meta(request)
    floor_name_num = FloorType.objects.count()

    try:
        thread_basic = ThreadBasic.objects.get(pk=tid)
    except ObjectDoesNotExist:
        return user_tip_page('Thread Does Not Exist',
                             'Please check your URL',
                             jump_to_back=True,
                             meta=meta)
    # Usually this won't happen, just here for safety and completeness
    try:
        board_basic = BoardBasic.objects.get(pk=thread_basic.bid.bid)
    except ObjectDoesNotExist:
        return user_tip_page('Thread Board Does Not Exist, Fatal Error',
                             'Please contact system administrator',
                             jump_to_back=True,
                             meta=meta)
    if thread_basic.hided == True:
        return user_tip_page('Cannot Access Thread',
                             'Thread has been locked',
                             jumo_to_back=True,
                             meta=meta)
    # privilege for the 1st floor is 2, other topped is 1, and normal is 0
    post_set = PostBasic.objects.filter(tid__tid__exact=tid).order_by(
        '-privilege', 'post_date')
    post_num = post_set.count()
    posts = post_set.all()
    index_range = get_page_range(page, post_num, post_per_page)
    # It is not possible since each thread must at least have one post
    # But we do it for safety and completeness
    if index_range == False and page != 1:
        return user_tip_page('Page Does Not Exist',
                             'Please check your page number',
                             jump_to_back=True,
                             meta=meta)
    elif index_range == False and page == 1:
        total_page = 1
        posts = []
    else:
        total_page = index_range[2]
        posts = posts[index_range[0]:index_range[1]]
    # A dictionary using pid as the key.
    #replies = {}
    #for i in posts:
    #    reply_one_post = ReplyBasic.objects.filter(pid__exact=i.pid).order_by('-post_date').all()
    #    replies[str(i.pid)] = reply_one_post

    return render_to_response('forum_post.html', {
        'board_basic': board_basic,
        'thread_basic': thread_basic,
        'posts': posts,
        'post_per_page': post_per_page,
        'floor_name_num': floor_name_num,
        'current_page': page,
        'total_page': total_page,
        'meta': meta
    },
                              context_instance=RequestContext(request))
Beispiel #12
0
def auth_fail_tip():
    return user_tip_page('Authentication Fail','You need to login first',
                         jump_to_login=True,
                         jump_to_back=True)
Beispiel #13
0
def forum_thread_page(request,bid,page='1',thread_per_page='30'):
    """
    Display a page of threads, using the given page number and num_of_threads
    per page.
    """
    # Parameters are always passed using Unicode no matter what it is in the
    # regexp
    page = int(page)
    thread_per_page = int(thread_per_page)
    
    meta = get_page_meta(request)
    # We use cached data instead of doing query a each time. So please keep the
    # data synchronized
    try:
        board_basic = BoardBasic.objects.get(pk=bid)
    except ObjectDoesNotExist:
        return user_tip_page('Board Does Not Exist',
                             'Please check your URL',
                             jump_to_back=True,
                             meta=meta)
    else:
        thread_num = board_basic.thread_num
    # Do part of the queries here
    threads = ThreadBasic.objects.filter(bid__bid__exact=bid)
    other = threads.exclude(privilege__exact=-1).filter(hided__exact=False).order_by('-privilege','-last_reply_time').all()
    # Only show these threads when it is the first page
    uppermost_temp = threads.filter(privilege__exact=-1,hided__exact=False).order_by('-last_reply_time')
    hidden_num = threads.filter(hided__exact=True).count()
    normal_thread_num = thread_num - uppermost_temp.count() - hidden_num
    #return debug_output(thread_num)
    if page == 1:
        # Just do the query
        uppermost = uppermost_temp.all()
    else:
        uppermost = []
        # These cannot be counted into the normal threads
    
    page_range = get_page_range(page,normal_thread_num,thread_per_page)
    # If there is no content on the first page then return a null set
    if page_range == False:
        if page == 1:
            other = []
            total_page = 1
        else: # If not requesting page number 1, then just raise an error
            return user_tip_page('Page Does Not Exist',
                                 'Please check your page number',
                                 jump_to_back=True,meta=meta)
    else:
        other = other[page_range[0]:page_range[1]]
        total_page = page_range[2]
        
    #return HttpResponse(str(normal_thread_num),content_type='text/html')
    return render_to_response('forum_thread.html',
                            {'threads':
                             {'uppermost': uppermost,
                              'other': other,}, # Two parts
                             'board_basic': board_basic,
                             'thread_per_page': thread_per_page,
                             'total_page': total_page,
                             'current_page': page,
                             'meta': meta},
                              context_instance=RequestContext(request)) # CSRF 
Beispiel #14
0
def forum_post_page(request,tid,page='1',post_per_page='30'):
    page = int(page)
    post_per_page = int(post_per_page)
    tid = int(tid)
    meta = get_page_meta(request)
    floor_name_num = FloorType.objects.count()

    try:
        thread_basic = ThreadBasic.objects.get(pk=tid)
    except ObjectDoesNotExist:
        return user_tip_page('Thread Does Not Exist',
                             'Please check your URL',
                             jump_to_back=True,
                             meta=meta)
    # Usually this won't happen, just here for safety and completeness
    try:
        board_basic = BoardBasic.objects.get(pk=thread_basic.bid.bid)
    except ObjectDoesNotExist:
        return user_tip_page('Thread Board Does Not Exist, Fatal Error',
                             'Please contact system administrator',
                             jump_to_back=True,
                             meta=meta)
    if thread_basic.hided == True:
        return user_tip_page('Cannot Access Thread',
                             'Thread has been locked',
                             jumo_to_back=True,
                             meta=meta)
    # privilege for the 1st floor is 2, other topped is 1, and normal is 0
    post_set = PostBasic.objects.filter(tid__tid__exact=tid).order_by('-privilege','post_date')
    post_num = post_set.count()
    posts = post_set.all()
    index_range = get_page_range(page,post_num,post_per_page)
    # It is not possible since each thread must at least have one post
    # But we do it for safety and completeness
    if index_range == False and page != 1:
        return user_tip_page('Page Does Not Exist',
                             'Please check your page number',
                             jump_to_back=True,
                             meta=meta)
    elif index_range == False and page == 1:
        total_page = 1
        posts = []
    else:
        total_page = index_range[2]
        posts = posts[index_range[0]:index_range[1]]
    # A dictionary using pid as the key.
    #replies = {}
    #for i in posts:
    #    reply_one_post = ReplyBasic.objects.filter(pid__exact=i.pid).order_by('-post_date').all()
    #    replies[str(i.pid)] = reply_one_post
    
    return render_to_response('forum_post.html',
                              {'board_basic': board_basic,
                               'thread_basic': thread_basic,
                               'posts': posts,
                               'post_per_page': post_per_page,
                               'floor_name_num': floor_name_num,
                               'current_page': page,
                               'total_page': total_page,
                               'meta': meta},
                              context_instance=RequestContext(request))