Exemplo n.º 1
0
def FORM_ThreadEntry_processSuccess(*args):
    
    # args[0] = i (the instance)
    # args[1] = request
    # args[2] = cleanDataDict
    # args[3] = redirectReason ('edit' or 'add')
    
#    print "+++ args[0] = %s" % (args[0])
#    print "+++ args[1] = %s" % (args[1])
#    print "+++ args[2] = %s" % (args[2])
#    print "+++ args[3] = %s" % (args[3])

    parts = args[2]['hiddenUniqueIdentifier'].split(':', 1)

    # Use the value of the hidden variable hiddenWasEdited to determine if this is an edit of an existing item or an insert of a new one
    if args[2]['hiddenWasEdited'] == "1":
        try:
            instance = e_thread_03.objects.get(pk=parts[1])
            instance.comment = args[2]['comment']
            instance.edited  = True
            instance.save(request=args[1])
        except ObjectDoesNotExist:
            print "*** FORM_ThreadEntry_processSuccess: error the e_thread_03 item (id = %s) I'm trying to edit doesn't exist." % (parts[1])
    else:
        args[0].comment                 = args[2]['comment'].strip()
        args[0].auto_content_type_id    = parts[0]
        args[0].auto_object_id          = parts[1]
        args[0].save(request=args[1])
   
        parentClassInstance = registeredClassInfo.get_classObject_fromContentTypeId(parts[0])
        parentInstance      = parentClassInstance.objects.get(id=parts[1])
        
        # Add a reply tracking instance
        replyTrackingInstance = e_thread_replyTracking_03()
        replyTrackingInstance.post          = args[0]
        replyTrackingInstance.toCitizen     = parentInstance.auto_citizen
        replyTrackingInstance.save(request=args[1])
Exemplo n.º 2
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)