예제 #1
0
def a_mgrApplication_03_VIEW_Detail(request, object_id):  
    contextDict = {}
    obj2detail = a_mgrApplication_03.objectsAll.get(pk=object_id)
    QS2 = subscription_01.objects.filter(application=obj2detail, auto_citizen__exact=request.META['duo_citizen'])
    if QS2.count(): objectList = [obj2detail, 'unsubscribe']
    else:           objectList = [obj2detail, 'subscribe']   
    
    contextDict['vTitle'] = obj2detail
    contextDict['main_1'] = a_mgrApplication_03.processTemplate_01(request, 'a_mgrApplication_03/templates/BLOCK_Detail.html', contextDict={'object': objectList})
    return a_mgrApplication_03.processTemplate_01(request, 'BASE.html', contextDict, mode='view') 
예제 #2
0
def a_mgrApplication_03_VIEW_genericUserAppSubscriptionToggle(request):
    # Determine if there is a subscription
    contentTypeObj = ContentType.objects.get(name__exact=request.POST['content_type'])
    QS = genericUserAppSubscription.objects.filter(
                                                   auto_object_id__exact        = request.POST['object_id'],
                                                   auto_content_type__exact     = contentTypeObj,
                                                   auto_citizen__exact          = request.META['duo_citizen']
                                                   ) 

    if QS.count():
        QS.delete()
#        print "*** subscription deleteted"    
    else:
        newSubscription = genericUserAppSubscription()
        newSubscription.auto_content_object = contentTypeObj.model_class().objects.get(pk=request.POST['object_id'])
        newSubscription.save(request=request)    
#        print "*** subscription added"    

    # HACK: To ensure this view returns a request object
    contextDict = {}
    return a_mgrApplication_03.processTemplate_01(request, 'BASE.html', contextDict, mode='view') 
예제 #3
0
def a_mgrApplication_03_VIEW_List(request):
    contextDict = {}    
    objectList  = []
    
    subList = []
    notList = []

    if (request.META['citizen_rights'] == secDict['s_developer']):
        QS = a_mgrApplication_03.objects.order_by('name')
    else:
        QS = a_mgrApplication_03.objects.exclude(released=False).order_by('name')
        
    for x in QS:
        QS2 = subscription_01.objects.filter(application=x, auto_citizen__exact=request.META['duo_citizen'])
        if QS2.count(): subList.append([x, 'unsubscribe'])
        else:           notList.append([x, 'subscribe'])    
        
    objectList = subList + notList 


    contextDict['main_1'] = a_mgrApplication_03.processTemplate_02_withPagination(request, 'a_mgrApplication_03/templates/BLOCK_List.html', contextDict={'objectList':objectList}, contextPaginationKey='objectList')
    return a_mgrApplication_03.processTemplate_01(request, 'BASE.html', contextDict, mode='view')
예제 #4
0
def a_mgrApplication_03_VIEW_genericUserAppVote(request, mode, vote):
#    print "*************************************************************"
#    print "*** a_mgrApplication_03_VIEW_genericUserAppVote"
#    print "request.POST = %s" % (request.POST)
#    print "request.POST['object_id'] = %s"    % (request.POST['object_id'])
#    print "request.POST['content_type'] = %s" % (request.POST['content_type'])
#    print "request.META['duo_citizen'] = %s"  % (request.META['duo_citizen'])

    # Get users current vote
    contentTypeObj = ContentType.objects.get(name__exact=request.POST['content_type'])
#    contentTypeObj = ContentType.objects.get(name__exact='p_problem_01')
    try:
        usersCurrentVote = genericUserAppVote.objects.get(
                                                       auto_object_id__exact        = request.POST['object_id'],
#                                                       auto_object_id__exact        = 1,
                                                       auto_content_type__exact     = contentTypeObj,
                                                       mode__exact                  = mode,
                                                       auto_citizen__exact          = request.META['duo_citizen'],
                                                       )
        
        if int(usersCurrentVote.vote) == int(vote):     # Delete existing vote if it equals the same vote because this means the citizen toggled it off
            usersCurrentVote.delete(request=request)
        else:                                           # save new vote for citizen 
            usersCurrentVote.vote = vote
            usersCurrentVote.save(request=request)    
    except ObjectDoesNotExist:
        usersCurrentVote = genericUserAppVote()
        usersCurrentVote.auto_content_object = contentTypeObj.model_class().objects.get(pk=request.POST['object_id'])
#        usersCurrentVote.auto_content_object = contentTypeObj.model_class().objects.get(pk=1)
        usersCurrentVote.mode                = mode
        usersCurrentVote.vote                = vote
        usersCurrentVote.save(request=request)    

    # HACK: To ensure this view returns a request object
    contextDict = {}
    return a_mgrApplication_03.processTemplate_01(request, 'BASE.html', contextDict, mode='view') 
예제 #5
0
    def render(self, context):
        returnList = []
        
        # Get the request variable from the context
        request = resolve_variable('request', context)  
        
        if settings.DEBUG:
            for param in self.requiredParam:
                if param not in self.paramDict:
                    self.errorList.append("Did not find self.requiredParam : %s" % (param))
               
        for key, value in self.resolveDict.items():
             self.paramDict[key] = value.resolve(context)

        # -----------------------------------------------------
        urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)        
        
#        if request.META['duo_citizen']:
        try:
            totalInstance = genericUserAppVoteTotal.objects.get(
                                                           auto_object_id__exact        = self.paramDict['OBJECT'].id,
                                                           auto_content_type__exact     = ContentType.objects.get_for_model(self.paramDict['OBJECT']),
                                                           mode__exact                  = self.paramDict['MODE'],
                                                            )      
            currentTotal = totalInstance.total
        except ObjectDoesNotExist:
            currentTotal = 0
        
        try:
            usersCurrentVote = genericUserAppVote.objects.get(
                                                           auto_object_id__exact        = self.paramDict['OBJECT'].id,
                                                           auto_content_type__exact     = ContentType.objects.get_for_model(self.paramDict['OBJECT']),
                                                           mode__exact                  = self.paramDict['MODE'],
                                                           auto_citizen__exact          = request.META['duo_citizen'],
                                                           )
        except ObjectDoesNotExist:
            usersCurrentVote = ''

        currentVote = ''
        if usersCurrentVote:
            if   usersCurrentVote.vote == 1:  
                currentVote = 'up'
                possibleTotals = [currentTotal, currentTotal - 1, currentTotal - 2]
            elif usersCurrentVote.vote == -1: 
                currentVote = 'down'
                possibleTotals = [currentTotal + 2, currentTotal + 1, currentTotal]
        else:
            possibleTotals = [currentTotal + 1, currentTotal, currentTotal - 1]
            
        
        returnList.append(a_mgrApplication_03.processTemplate_01(
                                                                 request, 
                                                                 'BT_vote.html', 
                                                                 contextDict={
                                                                              'object_id'               : self.paramDict['OBJECT'].id,
                                                                              'content_type'            : ContentType.objects.get_for_model(self.paramDict['OBJECT']),
                                                                              'ajaxProcessingUrlUp'     : reverse('a_mgrApplication_03_VIEW_genericUserAppVote', kwargs = {'mode':self.paramDict['MODE'], 'vote': 1}, urlconf=urlconf),
                                                                              'ajaxProcessingUrlDown'   : reverse('a_mgrApplication_03_VIEW_genericUserAppVote', kwargs = {'mode':self.paramDict['MODE'], 'vote':-1}, urlconf=urlconf),
                                                                              'currentVote'             : currentVote,
                                                                              'currentTotal'            : currentTotal,
                                                                              'vote_1'                  : possibleTotals[0],
                                                                              'vote_2'                  : possibleTotals[1],
                                                                              'vote_3'                  : possibleTotals[2],
                                                                              }
                                                                     ))            
        # -----------------------------------------------------
        
        if settings.DEBUG:
            for x in self.errorList:
                returnList.append("<br/>%s"%(x))

        return ''.join(returnList)