コード例 #1
0
ファイル: views.py プロジェクト: kungfuloung/KflWeb
def threadtranslate(request, topicid, threadid):

    if not request.user.is_authenticated() or not request.user.is_active:               
        return HttpResponseRedirect('/homepage/')


    lan = setlanguage(request)
    user = request.user
    username = user.username
    userprofile = UserProfile.objects.get(user=user)


    if lan == 'en':
        form = ForumSearchForm_en
        form_post = ThreadPostForm()
    if lan == 'cn':
        form = ForumSearchForm_cn
        form_post = ThreadPostForm()
    
    state = []

    if userprofile.translator_status:



        allcategory = ThreadCategory.objects.all().order_by('pid')

        displayed_topic = Thread.objects.get(id=topicid)
        displayed_thread = ThreadContent.objects.get(id=threadid)



        if request.method == 'POST':
            form_post = ThreadPostForm(request.POST)
            
            if form_post.is_valid():
                # if lan == 'en':
                #     state.append('Successfully Posted!')
                # if lan == 'cn':
                #     state.append('成功送出!')                
                cd = form_post.cleaned_data



                language = Language.objects.get(pid=cd['language'])                

                topic = Thread.objects.get(id=topicid)

                for item in ThreadContent.objects.filter(of_thread=topic):
                    if item.language == language:
                        state.append('language existed!')
                        return render_to_response('discussion_translatepostview.html',{'allcategory':allcategory, 
                                                                                           'displayed_topic':displayed_topic, 
                                                                                           'displayed_thread':displayed_thread, 
                                                                                           'state':state, 'lan':lan, 'form':form, 'form_post':form_post}, RequestContext(request))                                


                thread = ThreadContent.objects.create(title=cd['title'],
                                      Content=cd['content'],
                                      language=language,
                                      posted_by=userprofile,
                                      posted_on=datetime.datetime.now(),
                                      of_thread=topic,
                                      )

                url = '/discussion/thread/'+threadid+'/'
                return HttpResponseRedirect(url)    
                
        return render_to_response('discussion_translatepostview.html',{'allcategory':allcategory, 
                                                                   'displayed_topic':displayed_topic, 
                                                                   'displayed_thread':displayed_thread, 
                                                                   'state':state, 'lan':lan, 'form':form, 'form_post':form_post}, RequestContext(request))        
    else:
        state.append('For translators only!')
        url = '/discussion/thread/'+threadid+'/'
        return HttpResponseRedirect(url)            
コード例 #2
0
ファイル: views.py プロジェクト: kungfuloung/KflWeb
def threadpost(request, categoryid):

    if not request.user.is_authenticated() or not request.user.is_active:               
        return HttpResponseRedirect('/homepage/')


    lan = setlanguage(request)
    user = request.user
    username = user.username
    userprofile = UserProfile.objects.get(user=user)


    if lan == 'en':
        form = ForumSearchForm_en

        form_post = ThreadPostForm(initial= {
                    'language': 1,}
                    )
    if lan == 'cn':
        form = ForumSearchForm_cn            
        form_post = ThreadPostForm(initial= {
                    'language': 2,}
                    )

    

    state = []

    allcategory = ThreadCategory.objects.all().order_by('pid')

    displayed_category = allcategory.get(pid=categoryid)



    if request.method == 'POST':
        form_post = ThreadPostForm(request.POST)
        
        if form_post.is_valid():
            if lan == 'en':
                state.append('Successfully Posted!')
            if lan == 'cn':
                state.append('成功送出!')                

            cd = form_post.cleaned_data

            language = Language.objects.get(pid=cd['language'])

            topic = Thread.objects.create(category=displayed_category, 
                                          update_on=datetime.datetime.now(),
                                          update_by=userprofile,
                                          )
            thread = ThreadContent.objects.create(title=cd['title'],
                                                  Content=cd['content'],
                                                  language=language,
                                                  posted_by=userprofile,
                                                  posted_on=datetime.datetime.now(),
                                                  of_thread=topic,
                                                  )

            url = '/discussion/category/'+categoryid+'/'
            return HttpResponseRedirect(url)    


    if displayed_category.pid == 1:
        if userprofile.master_status:
            return render_to_response('discussion_postview.html',{'allcategory':allcategory, 
                                                                  'displayed_category':displayed_category, 
                                                                  'userprofile':userprofile, 
                                                                  'state':state, 'lan':lan, 'form':form, 'form_post':form_post}, RequestContext(request))        
        else:
            if lan == 'en':
                state.append('Only masters can post questions here')
            if lan == 'cn':
                state.append('只有師父可以在此提問')
            return render_to_response('discussion_postview.html',{'allcategory':allcategory, 
                                                                  'displayed_category':displayed_category, 
                                                                  'userprofile':userprofile, 
                                                                  'state':state, 'lan':lan, 'form':form}, RequestContext(request))        
    else:
        return render_to_response('discussion_postview.html',{'allcategory':allcategory, 
                                                              'displayed_category':displayed_category, 
                                                              'userprofile':userprofile, 
                                                              'state':state, 'lan':lan, 'form':form, 'form_post':form_post}, RequestContext(request))