def plus_links(context, target_class, target_id, errors=None, form_data=None) : """links should be checked for the view permission """ target_cls = ContentType.objects.get(id=target_class).model_class() target = target_cls.objects.get(id=target_id) target = secure_wrap(target, context.get('request').user, interface_names=['CreateLink']) links = get_links_for(target, context) links = [(link, hasattr(link, 'delete')) for link in links] can_create = hasattr(target, 'create_Link') return { 'links' :links, 'target':target, 'can_create':can_create, 'target_id':target_id, 'target_class_name':target_cls.__name__, 'errors':errors, 'form_data':form_data }
def plus_links(context, target_class, target_id, errors=None, form_data=None): """links should be checked for the view permission """ target_cls = ContentType.objects.get(id=target_class).model_class() target = target_cls.objects.get(id=target_id) target = secure_wrap(target, context.get('request').user, interface_names=['CreateLink']) links = get_links_for(target, context) links = [(link, hasattr(link, 'delete')) for link in links] can_create = hasattr(target, 'create_Link') return { 'links': links, 'target': target, 'can_create': can_create, 'target_id': target_id, 'target_class_name': target_cls.__name__, 'errors': errors, 'form_data': form_data }
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))