コード例 #1
0
def tagframe(request, username, tagframe_name):
     tf = Tag_Frame.objects.using(username).get(name=tagframe_name)
     tags = Tag.objects.using(username).all().order_by('name')
     #TODO: need this?
     theme = __get_view_theme(request)
     private =    theme['private'] 
     #print 'private', private     
     return render_to_response('tagframes/tagframe.html',{'tag_tree':tf,\
                            'tags':tags, 'sort':'', 'username':request.user.username,'profile_username':username,  'private':private}, \
                    context_instance=RequestContext(request,  {'true_words':true_words, 'all_words':all_words, 'false_words':false_words}))
コード例 #2
0
ファイル: views.py プロジェクト: yejia/osl_notebook
def tagframe(request, username, tagframe_name):
    tf = Tag_Frame.objects.using(username).get(name=tagframe_name)
    tags = Tag.objects.using(username).all().order_by('name')
    #TODO: need this?
    theme = __get_view_theme(request)
    private = theme['private']
    #print 'private', private
    return render_to_response('tagframes/tagframe.html',{'tag_tree':tf,\
                           'tags':tags, 'sort':'', 'username':request.user.username,'profile_username':username,  'private':private}, \
                   context_instance=RequestContext(request,  {'true_words':true_words, 'all_words':all_words, 'false_words':false_words}))
コード例 #3
0
ファイル: views.py プロジェクト: yejia/osl_notebook
def area(request, username, area_id):  
    #print 'areaname', areaname
    if request.method == 'POST': 
        #below copied from index. merge. TODO:
        post = request.POST.copy()
        tag_names = post.getlist('item[tags][]')
        #Don't allow creating new tag frame here for now. TODO:
        try:
            tag_ids = [Tag_Frame.objects.using(request.user.username).get(name=tag_name).id for tag_name in tag_names]
        except ObjectDoesNotExist:
            messages.error(request, _("It is not a valid tag! Please enter a valid tag."))
            return HttpResponseRedirect('/'+username+'/areas/area/'+area_id+'/')        
        #TF = getTagFrame(username)        
        #tag_ids = [get_object_or_404(TF, name=tag_name).id for tag_name in tag_names]      
             
        A = getArea(request.user.username)
        a = A.objects.get(id=post.get('id'))
        a.owner_name = request.user.username
        a.name = post.get('name')
        a.desc = post.get('desc')
        a.private = post.get('private', False)
        #TODO: warn of empty root_note_frame and root_tag_frame. They cannot be null
        if post.get('root_note_frame'):
            a.root_note_frame = Frame.objects.using(request.user.username).get(id=post.get('root_note_frame'))
        if tag_ids:  
            a.root_tag_frame = Tag_Frame.objects.using(request.user.username).get(id=tag_ids[0])  
        a.save() 
           
    
    area = Area.objects.using(username).get(id=area_id)
       
    area.owner_name = username
    area.root_tag_frame.owner_name = username
    area.root_note_frame.owner_name = username
    #tags = Tag_Frame.objects.using(username).all().order_by('name')
    if username == request.user.username:
        area_tags_names = area.get_all_tags()#area.root_tag_frame.get_offsprings()
    else:        
        area_tags_names = area.get_public_tags()    
    
    #area_tags =  Tag.objects.using(username).filter(name__in=area.get_all_tags())
    area_tags_with_count = []
    area_question_tags_with_count = []
    area_project_tags_with_count = []
    for t in area_tags_names:
        
        note_list = Note.objects.using(username).filter(tags__name = t, deleted=False)
        area_tags_with_count.append([t, note_list.count()])
        #question note list
        #For now, I think just use snippet is ok. 
        q_note_list = Snippet.objects.using(username).filter(tags__name = t,  deleted=False)
        q_note_list =  q_note_list.filter(tags__name = 'question')
        q_count = q_note_list.count()
        if q_count:
            area_question_tags_with_count.append([t, q_count])
        
            
        
        p_note_list =  note_list.filter(tags__name = 'projects')
        p_count = p_note_list.count()
        if p_count:
            area_project_tags_with_count.append([t, p_count])
    
    resource_tags_with_count = []        
    for r_tag in resource_tags:
        r_note_list = Note.objects.using(username).filter(tags__name = r_tag, deleted=False)
        r_note_list = r_note_list.filter(tags__name__in=area_tags_names).distinct()
        r_count = r_note_list.count()
        for r in r_note_list:
            r.owner_name = username
            #print 'r.get_note_type()', r.get_note_type()
            if r.get_note_type() == 'Frame':
                r_count -= 1 
            
            #    print 'removing the frame'
            #    r_note_list.remove(r)
                
        
        if r_count:
            
            resource_area_tags_with_count = []
            for at in area_tags_names:
                r_a_notes = r_note_list.filter(tags__name = at).distinct()
                r_a_note_list = [n for n in r_a_notes] 
                for ran in r_a_note_list:
                    ran.owner_name = username 
                    if ran.get_note_type() == 'Frame':
                        r_a_note_list.remove(ran)
                
                
                ra_count = len(r_a_note_list)
                #print '[at, ra_count]', [at, ra_count]
                #print 'r_a_note_list', r_a_note_list.values('id')
                if ra_count:
                    resource_area_tags_with_count.append([at, ra_count])
                    
            resource_tags_with_count.append([r_tag, r_count, resource_area_tags_with_count])        
    #print 'resource_tags_with_count', resource_tags_with_count  
    groups = Group.objects.exclude(id__in=[g.id for g in area.get_groups()])
    editAreaForm = AddAreaForm(instance=area)
    tags = Tag_Frame.objects.using(username).all().order_by('name')
    
#===============================================================================
#    if username == request.user.username:
#        book_uri_prefix = '/'+username
#    else:
#        book_uri_prefix = '/social/'+username    
#===============================================================================
    
    #TODO:need this?
    theme = __get_view_theme(request)
    private =    theme['private'] 
    return render_to_response('areas/area.html',{'area':area,  'area_tags_with_count':area_tags_with_count, \
                                                 'area_question_tags_with_count':area_question_tags_with_count, 
                                                 'area_project_tags_with_count':area_project_tags_with_count,
                                                 'resource_tags_with_count':resource_tags_with_count,
                                                 'editAreaForm':editAreaForm,'tags':tags, \
                            'username':request.user.username,'profile_username':username,  'private':private, 'groups':groups}, \
                    context_instance=RequestContext(request,  {'book_uri_prefix':'/'+username+'/areas/area/'+area.name,
                                                              }))