예제 #1
0
def e_thread_03_VIEW_Thread(request, instance, indent, mode):
    returnList      = []
    indentIncrement = 1
    
    QS = e_thread_03.objects.filter(auto_object_id__exact=instance.id,auto_content_type__exact=ContentType.objects.get_for_model(instance)).order_by('auto_createdTimeStamp')
    count = QS.count()
    
    # ---------------------------------------------------------
    if mode == 'link' or mode == 'min_link':
        if count == 0:      
            if request.META['duo_citizen'] is not None: 
                if request.META['duo_citizen'].authenticated == 1:  linkText = "add comment"
                else:                                               linkText = "no comments"
            else:                                                   linkText = "no comments"
        elif count == 1:                                            linkText = "1 comment"
        elif count > 1:                                             linkText = "%s comments" % (count)
        
        if linkText:
            if mode == 'link' or (mode == 'min_link' and count > 0):
                detailedViewName = "%s_VIEW_Detail" % (instance.__class__.__name__)                  
                
                if hasattr(instance, 'getUrl_detail'):   
                    link = instance.getUrl_detail(request, linkText)
                else:                               
                    link = "<a href='%s'>%s</a>" % (reverse(detailedViewName, kwargs = {'object_id':instance.id},       urlconf=getattr(request, "urlconf", settings.ROOT_URLCONF)) , linkText)
                returnList.append(link)
        
    # ---------------------------------------------------------
    elif mode == 'context':
        parentClassInstance = registeredClassInfo.get_classObject_fromContentTypeId(instance.auto_content_type_id)
        parentInstance      = parentClassInstance.objects.get(id=instance.auto_object_id)
        detailedViewName = "%s_VIEW_Detail" % (parentInstance.__class__.__name__)
        
        if hasattr(parentInstance, 'getUrl_detail'):   
            link = parentInstance.getUrl_detail(request, "context")            
        else:                                     
            link = "<a href='%s'>%s</a>" % (reverse(detailedViewName, kwargs = {'object_id':parentInstance.id},       urlconf=getattr(request, "urlconf", settings.ROOT_URLCONF)) , "context")
        returnList.append(link)
        
    # ---------------------------------------------------------
    elif mode == 'parent':
        parentClassInstance = registeredClassInfo.get_classObject_fromContentTypeId(instance.auto_content_type_id)
        parentInstance      = parentClassInstance.objects.get(id=instance.auto_object_id)        
        link = "<a href='#%s'>%s</a>" % (parentInstance.id,"parent")
        returnList.append(link)
        
    # ---------------------------------------------------------
    elif mode == 'unseen_permalink_parent':
        parentClassInstance         = registeredClassInfo.get_classObject_fromContentTypeId(instance.auto_content_type_id)
        parentInstance              = parentClassInstance.objects.get(id=instance.auto_object_id) 

        if instance.__class__.__name__ == 'e_thread_03':
            detailedViewName = "%s_VIEW_Detail" % (parentInstance.__class__.__name__)
            
            if hasattr(parentInstance, 'getUrl_detail'):   
                link = parentInstance.getUrl_detail(request, "parent")                 
            else:                                     
                link = "<a href='%s'>%s</a>" % (reverse(detailedViewName, kwargs = {'object_id':parentInstance.id},       urlconf=getattr(request, "urlconf", settings.ROOT_URLCONF)) , "parent")
            returnList.append(link)
        
    # ---------------------------------------------------------
    elif mode == 'permalink':
        detailedViewName    = "%s_VIEW_Detail" % (instance.__class__.__name__)
        
        if hasattr(instance, 'getUrl_detail'):   
            link = instance.getUrl_detail(request, "permalink")               
        else:                               
            link = "<a href='%s'>%s</a>" % (reverse(detailedViewName, kwargs = {'object_id':instance.id},        urlconf=getattr(request, "urlconf", settings.ROOT_URLCONF)) , "permalink")
        returnList.append(link)
        
    # ---------------------------------------------------------
    elif mode == 'indentedchildren':
        detailedViewName    = "%s_VIEW_Detail" % (instance.__class__.__name__)
        if hasattr(instance, 'getUrl_detail'):   
            link = instance.getUrl_detail(request, "more replies")               
        else:                               
            link = "<a href='%s'>%s</a>" % (reverse(detailedViewName, kwargs = {'object_id':instance.id},       urlconf=getattr(request, "urlconf", settings.ROOT_URLCONF)) , "more replies")
        returnList.append(link)

    # ---------------------------------------------------------
    elif mode == 'start':
        if request.META['duo_citizen'] is not None: 
            if request.META['duo_citizen'].authenticated == 1:   
                returnList.append(e_thread_03_VIEW_Thread(request, instance, indent, mode="internal_form"))
            else:                                               
                returnList.append("<br><span class='mmh-replyErrorText'>Your account has to be authenticated before you can comment.</span>")
        else:
            returnList.append('<br><span class="mmh-replyErrorText">You must be signed in to comment.</span>')

        for x in QS:
            returnList.append(e_thread_03_VIEW_Thread(request, x, indent, mode="entry"))

    # ---------------------------------------------------------
    elif mode == 'entry':
        
        max_indent = 8
        
        returnList.append(e_thread_03.processTemplate_01(request, 'e_thread_03/templates/BLOCK_Entry.html', {'object':instance,'indent':indent,'remainder':14-indent,'max_indent':max_indent}))
        new_indent = indent + indentIncrement
        
        if indent < max_indent:
            for x in QS:
                returnList.append(e_thread_03_VIEW_Thread(request, x, new_indent, mode="entry"))
            
    # ---------------------------------------------------------
    elif mode == 'internal_form':
        returnList.append(e_thread_03_FORM_ThreadEntry(request, instance, indent, 14-indent))

    # ---------------------------------------------------------
    else:
        returnList.append("Error: unknown mode (%s)" % (mode))
     
    return ''.join(returnList)
예제 #2
0
def e_thread_03_VIEW_BBcode(request, object_id):  
    try:
        obj2detail = e_thread_03.objectsAll.get(pk=object_id)
        return e_thread_03.processTemplate_01(request, 'e_thread_03/templates/BLOCK_BBcode.html', {'object': obj2detail}, mode='view')
    except  ObjectDoesNotExist:
        raise Http404