def view_resource(request, group, resource_name, template_name="plus_resources/view.html", current_app='plus_groups', **kwargs): if not group: raise Http404(_('This group does not exist')) try: obj = Resource.objects.plus_get(request.user, name=resource_name, in_agent=group.get_ref()) except Resource.DoesNotExist: raise Http404 if not request.user.is_authenticated(): request.user = get_anon_user() try: obj.get_all_sliders perms_bool = True except PlusPermissionsNoAccessException: perms_bool = False try: obj.comment can_comment = True except PlusPermissionsNoAccessException: can_comment = False edit = has_access(request.user, obj, 'Resource.Editor') tags = get_tags_for_object(obj, request.user) if obj.get_inner().created_by: created_by = obj.get_inner().created_by.get_display_name() else: created_by = None return render_to_response(template_name, { 'upload': TemplateSecureWrapper(obj), 'page_title': obj.title, 'created_by': created_by, 'permissions': perms_bool, 'can_comment': can_comment, 'can_edit': edit, 'tags': tags }, context_instance=RequestContext( request, current_app=current_app))
def view_resource(request, group, resource_name, template_name="plus_resources/view.html", current_app='plus_groups', **kwargs): if not group : raise Http404(_('This group does not exist')) try: obj = Resource.objects.plus_get(request.user, name=resource_name, in_agent=group.get_ref()) except Resource.DoesNotExist: raise Http404 if not request.user.is_authenticated(): request.user = get_anon_user() try: obj.get_all_sliders perms_bool = True except PlusPermissionsNoAccessException: perms_bool = False try : obj.comment can_comment=True except PlusPermissionsNoAccessException: can_comment=False edit = has_access(request.user, obj, 'Resource.Editor') tags = get_tags_for_object(obj, request.user) if obj.get_inner().created_by : created_by = obj.get_inner().created_by.get_display_name() else : created_by = None return render_to_response(template_name, { 'upload' : TemplateSecureWrapper(obj), 'page_title' : obj.title, 'created_by' : created_by, 'permissions' : perms_bool, 'can_comment' : can_comment, 'can_edit' : edit, 'tags': tags }, context_instance=RequestContext(request, current_app=current_app))
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))
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))