Exemplo n.º 1
0
def tab(request):
    t = loader.get_template("tab.html")
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)

    context["side_list"] = [""]
    context["page_tab_user"] = "******"

    tabs = Tab.objects.all()
    user_tabs = list()
    for tab in tabs:
        try:
            if tab.is_public:
                user_tabs.append(tab)
            tab_user = TabUsers.objects.filter(tab=tab, user=request.user).count()
            if tab_user is not 0:
                user_tabs.append(tab)
        except Exception as e:
            print e
    paginator = Paginator(user_tabs, 10)

    page = request.GET.get("page", 1)
    try:
        context["tabs"] = paginator.page(page)
    except PageNotAnInteger:
        context["tabs"] = paginator.page(1)
    except EmptyPage:
        context["tabs"] = paginator.page(paginator.num_pages)
    context["index_info"] = my_utils.get_index_list(context["tabs"].number, paginator.num_pages)

    return HttpResponse(t.render(context))
Exemplo n.º 2
0
def topic(request):
    t = loader.get_template('topic.html')
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)
    
    context['user_favorite_topics'] = my_utils.get_favorite_topics(request.user)
    
    context['side_list']=['search_topic']
    my_utils.prepare_search_topic(context)
    
    context['page_topic'] = "selected"
    context['topics']=list()
    
    context['popular_topics'] = Topic.objects.filter(reference_count__gt=0,topic_name__gt='').order_by("-reference_count")[:20]
    # try:
#         topics = 
#     except:
#         pass
    
    try:
        keyword = request.GET.get('q', '')
        query_type = Q()
        if keyword is not '':
            print keyword
            query_type = Q(topic_name__istartswith=keyword)
        
        search_index = request.GET.get('index', '')
        print search_index
        if search_index is not '':
            if search_index in map(chr, range(65, 91)):
                query_type = Q(topic_name__istartswith=search_index)
            elif search_index == 'number':
                query_type = Q(topic_name__gt="0",topic_name__lt="9")
            else:
                this_index,next_index=my_utils.next_search_index(search_index)
                query_type = Q(topic_name__gt=this_index, topic_name__lt=next_index)
        
        topics = Topic.objects.filter(query_type, topic_name__gt='',reference_count__gt=0).order_by('topic_name')
        
        
        paginator = Paginator(topics, 15)
        
        page = request.GET.get('page', 1)
        try:
            context['topics'] = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            context['topics'] = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            context['topics'] = paginator.page(paginator.num_pages)
        
        context['index_info'] = my_utils.get_index_list(context['topics'].number, paginator.num_pages)
        
        
    except Exception as e:
        print str(e)
        
    
    return HttpResponse(t.render(context))
Exemplo n.º 3
0
def dashboard(request):
    if not request.user.is_staff:
        return HttpResponseNotFound() 
    t = loader.get_template('admin/dashboard.html')
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)
    context['side_list']=['']
    context['current_user'] = request.user
    context['page_dashboard'] = "selected"
    
    members = User.objects.filter(is_active=True)
    members_list = list()
    
    date_before = request.GET.get('type', 7)
    time = now_datetime()  - dt.timedelta(int(date_before))
    if int(date_before) is 30:
    	context['month'] = 'selected'
    else:
    	context['week'] = 'selected'
    context['queries'] = 'type=' + str(date_before)
    
    failers_list = list()
    for member in members:
    	try:
    	    item = dict()
    	    item['username'] = member.username
    	    item['last_name'] = member.last_name
    	    item['id'] = member.id
    	    count = Message.objects.filter(is_deleted=False,author=member,reg_date__gt=time).count()
    	    item['feeds'] = count
    	    
    	    count2 = Comment.objects.filter(is_deleted=False,author=member,reg_date__gt=time).count()
    	    item['comments'] = count2
    	    item['score'] = count + count2 * 0.5
    	    members_list.append(item)
    	    if item['score'] == 0.0:
    	        failers_list.append(item)
    	except:
    	    pass
    
    members_list = [y for (x,y) in sorted([(i['score'],i) for i in members_list], reverse=True)]
    
    context['failers'] = failers_list
    paginator = Paginator(members_list, 10)
        
    page = request.GET.get('page', 1)
    try:
        context['members'] = paginator.page(page)
    except PageNotAnInteger:
        context['members'] = paginator.page(1)
    except EmptyPage:
        context['members'] = paginator.page(paginator.num_pages)
    context['index_info'] = my_utils.get_index_list(context['members'].number, paginator.num_pages)
    
    return HttpResponse(t.render(context))
Exemplo n.º 4
0
def authority(request):
    if not request.user.is_staff:
        return HttpResponseNotFound() 
    t = loader.get_template('admin/authority.html')
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)
    context['side_list']=['']
    context['current_user'] = request.user
    context['page_authority'] = "selected"
    
    try:
        category = request.GET.get('category','')
        query_type = Q()
        
        if category == '1':
            context['show_staff']='selected'
            query_type = Q(user__is_staff=True, is_deactivated=False)
        elif category == '2':
            context['show_deactivated']='selected'
            query_type = Q(is_deactivated=True)
        else:
            context['show_user']='******'
            query_type = Q(user__is_staff=False, is_deactivated=False)
        
        members = UserProfile.objects.filter(query_type & ~Q(user = request.user), user__is_active=True).order_by('user__username')
        members_list = list()
        for member in members:
            try:
                try:
                    member.picture = member_profile.picture.url
                except:
                    member.picture = "/media/default.png"
                members_list.append(member)
            except:
                pass
        
        paginator = Paginator(members_list, 10)
        
        page = request.GET.get('page', 1)
        try:
            context['members'] = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            context['members'] = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            context['members'] = paginator.page(paginator.num_pages)
        
        context['index_info'] = my_utils.get_index_list(context['members'].number, paginator.num_pages)
        
    except Exception as e:
        print str(e)
    
    return HttpResponse(t.render(context))   
Exemplo n.º 5
0
def main(request):
    t = loader.get_template('poll.html')
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)
    
    context['page_poll'] = "selected"
    context['side_list']=['']
    context['user_favorite_topics'] = my_utils.get_favorite_topics(request.user)
    
    try:
        polls = Poll.objects.filter(is_deleted=False).order_by('-reg_date')
        polls_list = list()
        for poll in polls:
            try:
                member_profile = UserProfile.objects.get(user=poll.author)
                try:
                    poll.author.picture = member_profile.picture.url
                except:
                    poll.author.picture = "/media/default.png"
                polls_list.append(poll)
            except:
                pass
        
        paginator = Paginator(polls_list, 15)
        
        page = request.GET.get('page', 1)
        try:
            context['polls'] = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            context['members'] = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            context['polls'] = paginator.page(paginator.num_pages)
        
        context['index_info'] = my_utils.get_index_list(context['polls'].number, paginator.num_pages)
        
    except Exception as e:
        print str(e)
    
    return HttpResponse(t.render(context))
Exemplo n.º 6
0
def tab_admin(request):
    if not request.user.is_staff:
        return HttpResponseNotFound()
    t = loader.get_template("admin/tab.html")
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)
    context["side_list"] = [""]
    context["current_user"] = request.user
    context["page_tab"] = "selected"

    tab_name = request.POST.get("tab_name", "")
    is_public = request.POST.get("is_public", False)

    if tab_name is not "":
        ## create tab
        try:
            new_tab = Tab(name=tab_name, is_public=is_public)
            new_tab.save()
            context["tab_message"] = "Tab '" + tab_name + "' is created."
        except Exception as e:
            print e
            context["tab_message"] = "Tab '" + tab_name + "' is not created. Check again."

    tabs = Tab.objects.all()
    paginator = Paginator(tabs, 10)

    page = request.GET.get("page", 1)
    try:
        context["tabs"] = paginator.page(page)
    except PageNotAnInteger:
        context["tabs"] = paginator.page(1)
    except EmptyPage:
        context["tabs"] = paginator.page(paginator.num_pages)
    context["index_info"] = my_utils.get_index_list(context["tabs"].number, paginator.num_pages)

    return HttpResponse(t.render(context))
Exemplo n.º 7
0
def tab_manage(request, tab_id):
    if not request.user.is_staff:
        return HttpResponseNotFound()

    t = loader.get_template("admin/tab_manage.html")
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)
    context["side_list"] = [""]
    context["current_user"] = request.user
    context["page_tab"] = "selected"

    tab = get_object_or_404(Tab, id=tab_id, is_public=False)

    context["tab_name"] = tab.name
    context["tab_id"] = tab.id

    if request.POST.get("add_user", False):
        try:
            username = request.POST.get("add_user", "")
            new_user = User.objects.get(username=username)
            new_relation = TabUsers.objects.get_or_create(tab=tab, user=new_user)[0]
            new_relation.save()
        except:
            print "add failed"

    if request.POST.get("delete_user", False):
        try:
            username = request.POST.get("delete_user", "")
            user = User.objects.get(username=username)
            relation = TabUsers.objects.get(tab=tab, user=user)
            relation.delete()
        except:
            print "add failed"

    tab_users = TabUsers.objects.filter(tab=tab).order_by("-reg_date")

    paginator_tab = Paginator(tab_users, 5)

    tab_page = request.GET.get("tab_page", 1)

    try:
        context["tab_users"] = paginator_tab.page(tab_page)
    except PageNotAnInteger:
        context["tab_users"] = paginator_tab.page(1)
    except EmptyPage:
        context["tab_users"] = paginator_tab.page(paginator_tab.num_pages)
    context["index_info_tab"] = my_utils.get_index_list(context["tab_users"].number, paginator_tab.num_pages)

    users = UserProfile.objects.filter(is_deactivated=False, user__is_active=True)

    paginator = Paginator(users, 10)
    page = request.GET.get("page", 1)
    try:
        context["users"] = paginator.page(page)
    except PageNotAnInteger:
        context["users"] = paginator.page(1)
    except EmptyPage:
        context["users"] = paginator.page(paginator.num_pages)
    context["index_info"] = my_utils.get_index_list(context["users"].number, paginator.num_pages)

    context["tab_page"] = tab_page
    context["index"] = page

    return HttpResponse(t.render(context))
Exemplo n.º 8
0
def main(request):
    t = loader.get_template('member.html')
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)
    
    context['side_list']=['search_member']
    context['page_member'] = "selected"
    my_utils.prepare_search_topic(context)
    
    try:
        keyword = request.GET.get('q', '')
        search_index = request.GET.get('index', '')
        query_type = Q()
        if keyword is not '':
            print keyword
            query_type = Q(username__icontains=keyword) | Q(last_name__icontains=keyword)
        
        if search_index is not '':
            if search_index in map(chr, range(65, 91)):
                query_type = Q(username__istartswith=search_index)
            elif search_index == 'number':
                query_type = Q(username__gt="0",username__lt="9")
            else:
                this_index,next_index=my_utils.next_search_index(search_index)
                query_type = Q(username__gt=this_index, username__lt=next_index)
        
        members = User.objects.filter(query_type, is_active=True).order_by('username')
        members_list = list()
        for member in members:
            try:
                member_profile = UserProfile.objects.get(user=member)
                member.profile = member_profile
                try:
                    member.picture = my_utils.get_user_thumbnail(member)
                except:
                    member.picture = "/media/default.png"
                if not member_profile.is_deactivated:
                    members_list.append(member)
            except:
                pass
        
        paginator = Paginator(members_list, 15)
        
        page = request.GET.get('page', 1)
        try:
            context['members'] = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            context['members'] = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            context['members'] = paginator.page(paginator.num_pages)
        
        context['index_info'] = my_utils.get_index_list(context['members'].number, paginator.num_pages)
        
    except Exception as e:
        print str(e)
        
    
    
    return HttpResponse(t.render(context))
Exemplo n.º 9
0
def stats_topic(request):
    if not request.user.is_staff:
        return HttpResponseNotFound()
    
    t = loader.get_template('admin/stats_topic.html')
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)
    
    context['page_stats_by_topic'] = 'selected'
    
    context['side_list']=['search_topic']
    my_utils.prepare_search_topic(context)
    
    
    
    now = dt.datetime.now().isocalendar()
    this_week_start,this_week_end = get_week_days(now[0],now[1])
    this_week_end = this_week_end + dt.timedelta(1)
    last_week_start,last_week_end = this_week_start - dt.timedelta(7),this_week_end - dt.timedelta(7)
    
    this_week_topics = Topic.objects.filter(reg_date__range=(this_week_start,this_week_end), topic_name__gt="")
    for topic in this_week_topics:
        try:
            topic.recent_message=''
            recent_message = TopicTimeline.objects.filter(topic=topic).order_by('-update_date')[:1][0]
            topic.recent_message=recent_message.message.contents
        except Exception as e:
            print str(e)
            pass
    context['this_week_topics'] = this_week_topics     
    context['this_week_length'] = Topic.objects.filter(reg_date__range=(this_week_start,this_week_end), topic_name__gt="").count()
    context['last_week_length'] = Topic.objects.filter(reg_date__range=(last_week_start,last_week_end), topic_name__gt="").count()
    if context['last_week_length'] == 0:
        context['increase_rate'] = 100.0
    else:
        context['increase_rate'] = (float(context['this_week_length']) - context['last_week_length'])/context['last_week_length'] * 100
    
    
    try:
        keyword = request.GET.get('q', '')
        query_type = Q()
        if keyword is not '':
            print keyword
            query_type = Q(topic_name__istartswith=keyword)
        
        search_index = request.GET.get('index', '')
        print search_index
        if search_index is not '':
            if search_index in map(chr, range(65, 91)):
                query_type = Q(topic_name__istartswith=search_index)
            elif search_index == 'number':
                query_type = Q(topic_name__gt="0",topic_name__lt="9")
            else:
                this_index,next_index=my_utils.next_search_index(search_index)
                query_type = Q(topic_name__gt=this_index, topic_name__lt=next_index)
        
        topics = Topic.objects.filter(query_type, topic_name__gt='').order_by('topic_name')
        for topic in topics:
            try:
                topic.recent_message=''
                recent_message = TopicTimeline.objects.filter(topic=topic).order_by('-update_date')[:1][0]
                topic.recent_message=recent_message.message.contents
            except Exception as e:
                print str(e)
                pass
                
        paginator = Paginator(topics, 5)
        
        page = request.GET.get('page', 1)
        try:
            context['topics'] = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            context['topics'] = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            context['topics'] = paginator.page(paginator.num_pages)
        
        context['index_info'] = my_utils.get_index_list(context['topics'].number, paginator.num_pages)
        
        
    except Exception as e:
        print str(e)
    
    
    return HttpResponse(t.render(context))