예제 #1
0
파일: ajax.py 프로젝트: lypinggan/42ic
def get_event_more(viewname,page,slug):

    if viewname == 'all':
        if cache.get('event_list-all-html-page-'+str(page)):
            e_html = cache.get('event_list-all-html-page-'+str(page))
        else:
            a = Event.query.all_list().paginate(page,10)
            e_html = ''
            for e in a.items:
                e_html += render_template( 'event_list.html',e=e)
            cache.set('event_list-all-html-page-'+str(page),e_html,10)
    else:
        if viewname == 'mine':
            event_user_list = Event_User.query.mine_list(g.user.id).paginate(page,10)
        elif viewname == 'talk':
            event_user_list = Event_User.query.talk_list(g.user.id).paginate(page,10)
        elif viewname == 'question':
            event_user_list = Event_User.query.question_list(g.user.id).paginate(page,10)
        elif viewname == 'topic':
            event_user_list = Event_User.query.topic_list(g.user.id).paginate(page,10)
        else:
            abort(404)
        e_html = ''
        #try:
        for eu in event_user_list.items:
            if cache.get('event-id-'+str(eu.event_id)):
                e_html += cache.get('event-id-'+str(eu.event_id))
            else:
                e = Event.query.get(eu.event_id)
                h = render_template('event_list.html',e=e)
                cache.set('event-id-'+str(eu.event_id),h,100)
                e_html += h         
    return e_html
예제 #2
0
파일: group.py 프로젝트: lypinggan/42ic
def group_view(slug, page=1):
    groupinfo = Group.query.urlname_get_info(slug)
    #如果没有指定就默认为第一页
    if (request.args.get("page", '').strip()):
        page = int(request.args.get("page", '').strip())
    else:
        page = 1
    
    #检查是否有发言权限
    if g.user:
        is_join = Group_User.query.is_join(groupinfo.id,g.user.id)
        if is_join is None:
            is_join = 0
    else:
        is_join = 0
    #最近加入小组的用户(有缓存)
    if cache.get('group-'+slug+'recently_join_user'):
        recently_join_user = cache.get('group-'+slug+'recently_join_user')
    else:
        recently_join_user = Group_User.query.recently_join_user(groupinfo.id)
        cache.set('group-'+slug+'recently_join_user',recently_join_user,600)
    
    #获取该小组的主题列表
    topic_list = Group_Topic.query.get_topic_list(groupinfo.id).\
                    paginate(page, per_page=30)
    page_url = lambda page: '?page='+str(page)
    return render_template( 'group/g_index.html',groupinfo=groupinfo,\
            is_join=is_join,recently_join_user=recently_join_user,\
            topic_list=topic_list, page_url=page_url)
예제 #3
0
파일: dbc.py 프로젝트: lypinggan/42ic
def get_mini_attachment_file_url(value):

    r = re.compile(r'\[file\](\d+)\[/file\]')
    #获取ID号
    p = r.findall(value.group())
    if cache.get('get_mini_Attachment'+p[0]):
        return cache.get('get_mini_Attachment'+p[0])
    else:
        a = Attachment.query.filter(Attachment.id == p[0] ).first()
        if a:
            if a.type_no == 1:#如果文件类型等于1则为图片,其他为非显示的文件
                html = u'<img src="%s">' % (app.config['UPFILE_URL']+'200/'+a.file_new_name)
            else:
                if a.file_size >1048576:
                    filesize = str(a.file_size/1048576)+'MB'
                elif a.file_size >1024:
                    filesize = str(a.file_size/1024)+'KB'
                else:
                    filesize = str(a.file_size)+'B'
                html = u'附件ID%s:<a href="%s">%s</a>(%s)' % \
                (p[0], url_for('upload.download_file',aid = p[0]), a. file_old_name,filesize)
            cache.set('get_mini_Attachment'+p[0],html,5000)
            return html
        else:
            cache.set('get_mini_Attachment'+p[0],'',5000)
            return ''
예제 #4
0
파일: frontend.py 프로젝트: lypinggan/42ic
def index():
    if not g.user:
        loginform = LoginForm()
        signupform = SignupForm()
        return render_template( 'hi.html',loginform=loginform,signupform=signupform)
    if (request.args.get("view", '').strip()):
        viewname = request.args.get("view", '').strip()
    else:
        viewname = "mine"#如果没有指定就默认为全部

    if viewname == 'all':
        if cache.get('event_list-all-html'):
            e_html = cache.get('event_list-all-html')
        else:
            a = Event.query.all_list().paginate(1,20)
            e_html = ''
            for e in a.items:
                e_html += render_template( 'event_list.html',e=e)
            cache.set('event_list-all-html',e_html,20)
    else:
        if viewname == 'mine':
            event_user_list = Event_User.query.mine_list(g.user.id).paginate(1,20)
        elif viewname == 'talk':
            event_user_list = Event_User.query.talk_list(g.user.id).paginate(1,20)
        elif viewname == 'question':
            event_user_list = Event_User.query.question_list(g.user.id).paginate(1,20)
        elif viewname == 'topic':
            event_user_list = Event_User.query.topic_list(g.user.id).paginate(1,20)
        else:
            abort(404)
        e_html = ''
        #try:
        for eu in event_user_list.items:
            if cache.get('event-id-'+str(eu.event_id)):
                e_html += cache.get('event-id-'+str(eu.event_id))
            else:
                e = Event.query.get(eu.event_id)
                h = render_template('event_list.html',e=e)
                cache.set('event-id-'+str(eu.event_id),h,100)
                e_html += h         
            '''
            if cache.get('event-id-'+str(eu.id)):
                event_list.append(cache.get('event-id-'+str(eu.id)))
            else:
                event = Event.query.get(eu.id)
                #cache.set('event-id-'+str(eu.id),event,6000)
                event_list.append(event)
            '''
        #except:
        #    event_list = None
    #return ''
    return render_template( 'index.html',viewname=viewname,e_html=e_html)
예제 #5
0
파일: frontend.py 프로젝트: lypinggan/42ic
def ajax_question_search():
    keywords = request.args.get("q", '').strip()
    html = ''
    if cache.get("/search/ajax"+keywords):
        html = cache.get("/search/ajax"+keywords)
    else:
        question_list = Question.query.search(keywords).limit(9).all()
        html += '<ul>'
        for q in question_list:
            html += '<li><a href="/question/'+str(q.id)+'">'+q.title+'</a></li>'
        html += '</ul>'
        cache.set("/search/ajax"+keywords,html,60)

    return html
예제 #6
0
파일: online.py 프로젝트: lypinggan/42ic
def guest_session():
    g.user = False
    if 'id' not in session:
        session['id'] = uuid.uuid4()
    if not cache.get('session_guest_user_'+str(session['id'])):
        cache.set('session_guest_user_'+str(session['id']), 'online', 900)
예제 #7
0
파일: online.py 프로젝트: lypinggan/42ic
def login_session():
    if cache.get('session_login_uid_'+str(session['user_id'])):
        g.user =  cache.get('session_login_uid_'+str(session['user_id']))
    else:
        g.user = User.query.filter_by( id = session['user_id'] ).first()
        cache.set('session_login_uid_'+str(session['user_id']), g.user, 900)