Example #1
0
def view_plus_tag(label, tag_type, tagged, tagged_for) :
    """
    """
    tags = get_tags(tagged=tagged, tagged_for=tagged_for, tag_type=tag_type)
    return {'label':label,
            'tags' : tags,
            'tagged_class' : tagged.__class__.__name__,
            'tagged_id' : tagged.id,
            'tag_type' : tag_type}
Example #2
0
def tag_cloud(n, size, search_types, tag_search_url='explore_filtered'):
    if not search_types:
        search_types = None
    tags = get_tags(tagged=search_types)
    counts = tag_counts(n=n, tag_set=tags)
    if counts:
        tag_levels = scale_tag_weights(counts)
        tag_levels.sort(keyword_sort)
    else:
        tag_levels = []
    return {'tags': tag_levels, 'size': size, 'tag_search_url': tag_search_url}
Example #3
0
def tag_cloud(n, size, search_types, tag_search_url='explore_filtered'):
    if not search_types:
        search_types = None
    tags = get_tags(tagged=search_types)
    counts = tag_counts(n=n, tag_set=tags)
    if counts :
        tag_levels = scale_tag_weights(counts)
        tag_levels.sort(keyword_sort)
    else :
        tag_levels = []
    return {'tags':tag_levels, 'size':size, 'tag_search_url':tag_search_url}
Example #4
0
def plus_tag(label, tag_type, tagged, tagged_for) :
    """XXX update to deal with tagged for and tagged by
    """

    if tagged.__class__ == TemplateSecureWrapper:
        tagged = tagged.obj()
    if tagged_for.__class__ == TemplateSecureWrapper:
        tagged_for == tagged_for.obj()
    tags = get_tags(tagged=tagged, tagged_for=tagged_for, tag_type=tag_type)

    return {'label':label,
            'tags' : tags, 
            'tagged_class' : tagged.__class__.__name__ ,
            'tagged_id' : tagged.id,
            'tag_type' : tag_type}
Example #5
0
def view_plus_tag(label, tag_type, tagged, tagged_for):
    """
    """
    if not tag_type:
        tag_type = None
    if not tagged_for:
        tagged_for = None
    if tagged == '':
        tagged = None
    tags = get_tags(tagged=tagged, tagged_for=tagged_for, tag_type=tag_type)
    return {
        'label': label,
        'tags': tags,
        'tagged_class': tagged.__class__.__name__,
        'tagged_id': tagged.id,
        'tag_type': tag_type
    }
Example #6
0
def plus_tag(label, tag_type, tagged, tagged_for):
    """XXX update to deal with tagged for and tagged by
    """

    if tagged.__class__ == TemplateSecureWrapper:
        tagged = tagged.obj()
    if tagged_for.__class__ == TemplateSecureWrapper:
        tagged_for == tagged_for.obj()
    if tagged_for == '':
        tagged_for = None
    if tag_type == '':
        tag_type = 'tag'
    tags = get_tags(tagged=tagged, tagged_for=tagged_for, tag_type=tag_type)

    return {
        'label': label,
        'tags': tags,
        'tagged_class': tagged.__class__.__name__,
        'tagged_id': tagged.id,
        'tag_type': tag_type
    }
Example #7
0
def show_resource(context, item):
    if item.in_agent.obj.place.name == settings.VIRTUAL_HUB_NAME:
        group_label = "group"
    else:
        group_label = hub_name().lower()

    if item.__class__.__name__ == 'SecureWrapper':
        item = item.get_inner()

    if item.__class__.__name__ == "WikiPage":
        url_name = "view_WikiPage"
        url_name = group_label + "s:" + url_name
        url = reverse(url_name, args=[item.in_agent.obj.id, item.name])
    elif item.__class__.__name__ == "Resource":
        #url_name = context.current_app + ":view_Resource"
        url_name = 'view_Resource'
        url_name = group_label + "s:" + url_name
        url = reverse(url_name, args=[item.in_agent.obj.id, item.name])
        #download_url = item.download_url()

    tags = get_tags(item)
    #item = TemplateSecureWrapper(item)
    return {'resource': item, 'resource_url': url, 'tags': tags}
Example #8
0
def show_resource(context, item):
    if item.in_agent.obj.place.name == settings.VIRTUAL_HUB_NAME :
        group_label = "group"
    else:
        group_label = hub_name().lower()

    if item.__class__.__name__ == 'SecureWrapper' :
        item = item.get_inner()


    if item.__class__.__name__ == "WikiPage":
        url_name = "view_WikiPage"
        url_name = group_label + "s:"+ url_name
        url = reverse(url_name, args=[item.in_agent.obj.id, item.name])
    elif item.__class__.__name__ == "Resource":
        #url_name = context.current_app + ":view_Resource"
        url_name = 'view_Resource'
        url_name = group_label+"s:"+url_name
        url = reverse(url_name, args=[item.in_agent.obj.id, item.name])
        #download_url = item.download_url()

    tags = get_tags(item)
    #item = TemplateSecureWrapper(item)
    return {'resource':item, 'resource_url':url, 'tags':tags}
Example #9
0
def profile(request, username, template_name="profiles/profile.html"):
    other_user = get_object_or_404(User, username=username)
    other_user.save()
    
    p = other_user.get_profile()
    p.save()

    if request.user.is_authenticated():

        is_friend = Friendship.objects.are_friends(request.user, other_user)
        is_following = Following.objects.is_following(request.user, other_user)
        other_friends = Friendship.objects.friends_for_user(other_user)
        if request.user == other_user:
            is_me = True
        else:
            is_me = False
    else:
        other_friends = []
        is_friend = False
        is_me = False
        is_following = False
    
    if is_friend:
        invite_form = None
        previous_invitations_to = None
        previous_invitations_from = None
    else:
        if request.user.is_authenticated() and request.method == "POST":
            if request.POST["action"] == "invite":
                invite_form = InviteFriendForm(request.user, request.POST)
                if invite_form.is_valid():
                    invite_form.save()
            else:
                invite_form = InviteFriendForm(request.user, {
                    'to_user': username,
                    'message': ugettext("Let's be friends!"),
                })
                if request.POST["action"] == "accept": # @@@ perhaps the form should just post to friends and be redirected here
                    invitation_id = request.POST["invitation"]
                    try:
                        invitation = FriendshipInvitation.objects.get(id=invitation_id)
                        if invitation.to_user == request.user:
                            invitation.accept()
                            request.user.message_set.create(message=_("You have accepted the friendship request from %(from_user)s") % {'from_user': invitation.from_user})
                            is_friend = True
                            other_friends = Friendship.objects.friends_for_user(other_user)
                    except FriendshipInvitation.DoesNotExist:
                        pass
        else:
            invite_form = InviteFriendForm(request.user, {
                'to_user': username,
                'message': ugettext("Let's be friends!"),
            })
    previous_invitations_to = FriendshipInvitation.objects.filter(to_user=other_user, from_user=request.user)
    previous_invitations_from = FriendshipInvitation.objects.filter(to_user=request.user, from_user=other_user)
    
    if is_me:
        if request.method == "POST":
            if request.POST["action"] == "update":
                profile_form = ProfileForm(request.POST, instance=other_user.get_profile())
                if profile_form.is_valid():
                    profile = profile_form.save(commit=False)
                    profile.user = other_user
                    profile.save()
            else:
                profile_form = ProfileForm(instance=other_user.get_profile())
        else:
            profile_form = ProfileForm(instance=other_user.get_profile())
    else:
        profile_form = None

    interests = get_tags(tagged=other_user.get_profile(), tagged_for=other_user, tag_type='interest')
    skills = get_tags(tagged = other_user.get_profile(), tagged_for=other_user, tag_type='skill')
    needs = get_tags(tagged = other_user.get_profile(), tagged_for=other_user, tag_type='need')

    profile = other_user.get_profile()
    user = request.user


    if not user.is_authenticated():
        user = get_anon_user()

    user_type = ContentType.objects.get_for_model(other_user)
    other_user_tweets = Tweet.objects.filter(sender_type=user_type, sender_id=other_user.id).order_by("-sent") # other_user
    if other_user_tweets :
        latest_status = other_user_tweets[0]
        dummy_status = DisplayStatus(
            defaultfilters.safe( defaultfilters.urlize(latest_status.html())),
                                 defaultfilters.timesince(latest_status.sent) )
    else : 
        dummy_status = DisplayStatus('No status', '')
    profile = secure_wrap(profile, user)
    try:
        profile.get_all_sliders
        perms_bool = True
    except PlusPermissionsNoAccessException:
        perms_bool = False
    profile = TemplateSecureWrapper(profile)

    search_type = 'profile_list' 
    search_types = narrow_search_types()
    search_types_len = len(search_types)
    search_type_label = search_types[0][1][2]

    return render_to_response(template_name, {
            "profile_form": profile_form,
            "is_me": is_me,
            "is_friend": is_friend,
            "is_following": is_following,
            "other_user": other_user,
            "profile":profile,
            "other_friends": other_friends,
            "invite_form": invite_form,
            "previous_invitations_to": previous_invitations_to,
            "previous_invitations_from": previous_invitations_from,
            "head_title" : "%s" % other_user.get_profile().get_display_name(),
            "head_title_status" : dummy_status,
            "host_info" : other_user.get_profile().get_host_info(),
            "skills" : skills,
            "needs" : needs,
            "interests" : interests,
            "other_user_tweets" : other_user_tweets,
            "permissions":perms_bool,
            "search_type":search_type,
            "search_type_label":search_type_label,
            "search_types_len":search_types_len
            }, context_instance=RequestContext(request))
Example #10
0
from apps.plus_resources.models import Resource
import os, sys
from apps.plus_tags.models import get_tags, tag_delete

for r in Resource.objects.all():

    if r.created_by: creator = r.created_by.username
    else: creator = 'no created_by'

    print
    print '%s, %s, %s, %s' % (r.title, creator, r.license,
                              r.in_agent.obj.get_display_name())

    if r.license == 'Copyright 2009, Psychosocial Network':
        r.license = 'not specified'
        r.save()

    tags = get_tags(r)
    for t in tags:
        print t.keyword.encode('utf-8'), t.tag_type, t.tagged_for

    if r.resource:
        print r.resource

    else:
        import ipdb
        ipdb.set_trace()
        print "NO RESOURCE"
Example #11
0
from apps.plus_resources.models import Resource
import os, sys
from apps.plus_tags.models import get_tags, tag_delete

for r in Resource.objects.all() :

    if r.created_by : creator = r.created_by.username
    else : creator = 'no created_by'

    print 
    print '%s, %s, %s, %s' % (r.title, creator, r.license, r.in_agent.obj.get_display_name())

    if r.license == 'Copyright 2009, Psychosocial Network' :
        r.license = 'not specified'
        r.save()
     
    tags = get_tags(r)
    for t in tags :
        print t.keyword.encode('utf-8'), t.tag_type, t.tagged_for

    if r.resource :
        print r.resource
        
    else :
        import ipdb
        ipdb.set_trace()
        print "NO RESOURCE"
Example #12
0
def profile(request, username, template_name="profiles/profile.html"):
    #trellis.callInEventLoop(hello, "Tom")

    is_me = False
    user = request.user


    if request.user.is_authenticated() :
        if user.username == username :
            is_me = True
    else :
        user = get_anon_user()

    other_user = secure_wrap(get_object_or_404(User, username=username),user)

    is_following = Following.objects.is_following(request.user, other_user.get_inner())

    p = other_user.get_inner().get_profile()
    profile = secure_wrap(p,user)
    profile.user # trigger permission exception if no access
 
    can_change_avatar = False
    
    try :
        profile.change_avatar
        can_change_avatar = True
    except PlusPermissionsNoAccessException :
        pass

    interests = get_tags(tagged=other_user.get_inner().get_profile(), 
                         tagged_for=other_user.get_inner(), tag_type='interest')
    skills = get_tags(tagged = other_user.get_inner().get_profile(), 
                      tagged_for=other_user.get_inner(), tag_type='skill')
    needs = get_tags(tagged = other_user.get_inner().get_profile(), 
                     tagged_for=other_user.get_inner(), tag_type='need')

    user_type = ContentType.objects.get_for_model(other_user)

    # new style statuses
    tweets = FeedItem.feed_manager.get_from(other_user.get_inner()).order_by("-sent")
    if tweets :
        latest_status = tweets[0]
        status_since = defaultfilters.timesince(latest_status.sent)
    else:
        status_since = ''
    status_type = 'profile'

    try:
        profile.get_all_sliders
        perms_bool = True
    except PlusPermissionsNoAccessException:
        perms_bool = False

    profile = TemplateSecureWrapper(profile)

    search_type = 'profile_list' 
    search_types = narrow_search_types()
    search_types_len = len(search_types)
    search_type_label = search_types[0][1][2]


    host_info = p.get_host_info()
    host_info = secure_wrap(host_info, user, interface_names=['Viewer', 'Editor'])

    see_host_info = False
    try :
        host_info.user 
        see_host_info = True
    except :
        pass # can't see host_info
    host_info = TemplateSecureWrapper(host_info)
    
    hubs = other_user.get_inner().hubs()
    non_hub_groups = [(g.group_app_label() + ':group', g) for g in 
                      other_user.get_inner().groups.filter(level='member').exclude(id__in=hubs)]
    hubs = [(g.group_app_label() + ':group', g) for g in hubs]

    see_about = is_me or show_section(profile, ('about',))
    see_contacts = is_me or show_section(profile,('mobile','home','work','fax','website','address','email_address'))
    
    see_links = is_me
    links = get_links_for(other_user,RequestContext(request))
    if links :
        see_links = True

    can_tag = profile.has_interface('Profile.Editor')


    template_args = {
            "is_me": is_me,
            "is_following": is_following,
            "other_user": other_user.get_inner(), # XXX - should fix this get_inner
            "profile":profile,
            "can_change_avatar":can_change_avatar,

            "head_title" : "%s" % profile.get_display_name(),
            "status_type" : status_type,
            "status_since" : status_since,
            "host_info" : host_info,
            "skills" : skills,
            "needs" : needs,
            "interests" : interests,
            "other_user_tweets" : tweets,
            "permissions":perms_bool,
            "non_hub_groups":non_hub_groups,
            "hubs":hubs,
            "search_type":search_type,
            "search_types":search_types,
            "search_type_label":search_type_label,
            "search_types_len":search_types_len,
            "host_info":host_info, 
            "see_host_info":see_host_info,
            "see_about":see_about,
            "see_contacts":see_contacts,
            "see_links":see_links,
            "other_user_class":user_type.id,
            "other_user_id":other_user.id,
            "can_tag":can_tag,
            }
    labels = {'MAIN_HUB_LABEL':_('Main %s')%settings.HUB_NAME,
              'MAIN_HUB_DEFAULT':_("No %s selected")%settings.HUB_NAME}
    template_args.update(labels)

    return render_to_response(template_name, template_args, context_instance=RequestContext(request))