Ejemplo n.º 1
0
def proxied_invited_signup(
    request, invite, form_class=SignupForm, template_name="account/accepted_signup.html", success_url=None
):
    # request.user is the user who has invited / authorized the signup

    if success_url is None:
        success_url = get_default_redirect(request)
    display_name = "Visitor"
    sponsor = request.user  # the actual user who authorized this acceptance

    if request.method == "POST":
        form = form_class(request.POST)

        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password1"]

            invite.invited.become_member(username, accepted_by=sponsor, password=password)
            user = authenticate(username=username, password=password)

            auth_login(request, user)
            user.message_set.create(
                message=ugettext("Successfully logged in as %(username)s.") % {"username": user.username}
            )

            # Now, what happens if this invite came with a group?
            if invite.group:
                group = secure_wrap(invite.group, sponsor)
                group.add_member(user)

            return HttpResponseRedirect(success_url)

    else:

        form = form_class()

        applicant = invite.invited
        if applicant:
            form.data["email_address"] = applicant.email_address
            form.data["first_name"] = ""
            form.data["last_name"] = ""
            form.data["username"] = ""

            display_name = ""

        else:
            form.email_address = ""
            form.username = ""

    request.user = request.old_user

    return render_to_response(
        template_name,
        {"form": form, "submit_url": request.build_absolute_uri(), "display_name": display_name},
        context_instance=RequestContext(request),
    )
Ejemplo n.º 2
0
def profile_field(request, other_user, classname, fieldname, *args, **kwargs) :
    """ Get the value of one field from the user profile, so we can write an ajaxy editor """
    print "In profile_field"
    print "username %s, classname %s, fieldname %s" % (other_user.username,classname,fieldname)
    p = secure_wrap(other_user.get_profile(), request.user)

    if classname == 'Profile' :
        return one_model_field(request, p, ProfileForm, fieldname, kwargs.get('default', ''),[p.user])
    elif classname == 'HostInfo' :
        return one_model_field(request, p.get_host_info(), HostInfoForm, fieldname, kwargs.get('default', ''), [p.user])
Ejemplo n.º 3
0
def profile_field(request, other_user, classname, fieldname, *args, **kwargs) :
    """ Get the value of one field from the user profile, so we can write an ajaxy editor """
    print "In profile_field"
    print "username %s, classname %s, fieldname %s" % (other_user.username,classname,fieldname)
    p = secure_wrap(other_user.get_profile(), request.user)

    if classname == 'Profile' :
        return one_model_field(request, p, ProfileForm, fieldname, kwargs.get('default', ''),[p.user])
    elif classname == 'HostInfo' :
        return one_model_field(request, p.get_host_info(), HostInfoForm, fieldname, kwargs.get('default', ''), [p.user])
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
def proxied_signup(
    request, application, form_class=SignupForm, template_name="account/accepted_signup.html", success_url=None
):
    # request.user is the user who has invited / authorized the signup
    if success_url is None:
        success_url = get_default_redirect(request)

    # because this is a signup request that has an application object, we expect the application

    display_name = "Visitor"
    sponsor = request.user  # the actual user who authorized this acceptance
    if request.method == "POST":
        form = form_class(request.POST)

        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password1"]

            application.applicant.become_member(username, accepted_by=sponsor, password=password)
            user = authenticate(username=username, password=password)

            auth_login(request, user)
            user.message_set.create(
                message=ugettext("Successfully logged in as %(username)s.") % {"username": user.username}
            )

            # Now, what happens if this application or invite came with a group?
            if application.group:
                group = secure_wrap(application.group, sponsor)
                group.add_member(user)

            # application.delete()
            return HttpResponseRedirect(success_url)

    else:

        form = form_class()

        applicant = application.get_inner().applicant
        if applicant:
            form.data["email_address"] = applicant.email_address
            form.data["first_name"] = applicant.first_name
            form.data["last_name"] = applicant.last_name
            form.data["username"] = applicant.first_name.lower().strip() + "." + applicant.last_name.lower().strip()
            # normalize and uniquify
            display_name = form.data["first_name"] + " " + form.data["last_name"]

        else:
            form.email_address = ""
            form.username = ""

    # the outstanding issue is how to make sure that the form we're rendering comes back here
    # ie. with the hmac, let's pass it down as a "submit_url"

    # we must now switch back to the original user (probably Anon) back ... otherwise it thinks we're
    # logged in as the proxy, which circumvents showing the signup form
    request.user = request.old_user

    return render_to_response(
        template_name,
        {"form": form, "submit_url": request.build_absolute_uri(), "display_name": display_name},
        context_instance=RequestContext(request),
    )
Ejemplo n.º 6
0
def proxied_signup(request, application, form_class=SignupForm,
                   template_name="account/accepted_signup.html", success_url=None):
    # if we've got here, we already know that this function was called 
    # with request.user as the agent who's inviting / authorizing this new member
    # so we don't need to explicitly test.

    if success_url is None:
        success_url = get_default_redirect(request)

    # because this is a signup request that has an application object, we expect the application

    display_name = "Visitor"
    sponsor = request.user # the actual user who authorized this acceptance
    if request.method == "POST":
        form = form_class(request.POST)
        
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']

            application.applicant.become_member(username, accepted_by=sponsor, password = password)
            user = authenticate(username=username, password=password)
            display_name = application.applicant.get_display_name()
            
            auth_login(request, user)
            user.message_set.create(
                message=ugettext("Successfully logged in as %(username)s.") % {
                'username': user.username
            })

            # Now, what happens if this application or invite came with a group?
            if application.group :
                group = secure_wrap(application.group, sponsor)
                group.add_member(user)                   

            #application.delete()
            return HttpResponseRedirect(success_url)
        else :

            print form.errors
    else:

        form = form_class()
        try :
            applicant = application.get_inner().applicant
            form.email_address = applicant.email_address
            form.username = "******" % (applicant.first_name, applicant.last_name)
            display_name = form.username
        except :
            form.email_address = ''
            form.username = ''
            

        

    # the outstanding issue is how to make sure that the form we're rendering comes back here
    # ie. with the hmac, let's pass it down as a "submit_url"

    # we must now get the original user (probably Anon) back ... otherwise it thinks we're
    # logged in as the proxy, which circumvents showing the signup form
    request.user = request.old_user         

    return render_to_response(template_name, {
        "form": form,
        "submit_url" : request.build_absolute_uri(),
        "display_name" : display_name        
    }, context_instance=RequestContext(request))
Ejemplo n.º 7
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))
Ejemplo n.º 8
0
def proxied_invited_signup(request,
                           invite,
                           form_class=SignupForm,
                           template_name="account/accepted_signup.html",
                           success_url=None):
    # request.user is the user who has invited / authorized the signup

    if success_url is None:
        success_url = get_default_redirect(request)
    display_name = "Visitor"
    sponsor = request.user  # the actual user who authorized this acceptance

    if request.method == "POST":
        form = form_class(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']

            invite.invited.become_member(username,
                                         accepted_by=sponsor,
                                         password=password)
            user = authenticate(username=username, password=password)

            auth_login(request, user)
            user.message_set.create(
                message=ugettext("Successfully logged in as %(username)s.") %
                {'username': user.username})

            # Now, what happens if this invite came with a group?
            if invite.group:
                group = secure_wrap(invite.group, sponsor)
                group.add_member(user)

            return HttpResponseRedirect(success_url)

    else:

        form = form_class()

        applicant = invite.invited
        if applicant:
            form.data['email_address'] = applicant.email_address
            form.data['first_name'] = ''
            form.data['last_name'] = ''
            form.data['username'] = ''

            display_name = ''

        else:
            form.email_address = ''
            form.username = ''

    request.user = request.old_user

    return render_to_response(template_name, {
        "form": form,
        "submit_url": request.build_absolute_uri(),
        "display_name": display_name
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 9
0
def proxied_signup(request,
                   application,
                   form_class=SignupForm,
                   template_name="account/accepted_signup.html",
                   success_url=None):
    # request.user is the user who has invited / authorized the signup
    if success_url is None:
        success_url = get_default_redirect(request)

    # because this is a signup request that has an application object, we expect the application

    display_name = "Visitor"
    sponsor = request.user  # the actual user who authorized this acceptance
    if request.method == "POST":
        form = form_class(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']

            application.applicant.become_member(username,
                                                accepted_by=sponsor,
                                                password=password)
            user = authenticate(username=username, password=password)

            auth_login(request, user)
            user.message_set.create(
                message=ugettext("Successfully logged in as %(username)s.") %
                {'username': user.username})

            # Now, what happens if this application or invite came with a group?
            if application.group:
                group = secure_wrap(application.group, sponsor)
                group.add_member(user)

            #application.delete()
            return HttpResponseRedirect(success_url)

    else:

        form = form_class()

        applicant = application.get_inner().applicant
        if applicant:
            form.data['email_address'] = applicant.email_address
            form.data['first_name'] = applicant.first_name
            form.data['last_name'] = applicant.last_name
            form.data['username'] = applicant.first_name.lower().strip(
            ) + '.' + applicant.last_name.lower().strip()
            #normalize and uniquify
            display_name = form.data['first_name'] + ' ' + form.data[
                'last_name']

        else:
            form.email_address = ''
            form.username = ''

    # the outstanding issue is how to make sure that the form we're rendering comes back here
    # ie. with the hmac, let's pass it down as a "submit_url"

    # we must now switch back to the original user (probably Anon) back ... otherwise it thinks we're
    # logged in as the proxy, which circumvents showing the signup form
    request.user = request.old_user

    return render_to_response(template_name, {
        "form": form,
        "submit_url": request.build_absolute_uri(),
        "display_name": display_name
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 10
0
    try :
        status = FeedItem.feed_manager.get_status(sender)
        status_since = defaultfilters.timesince(status.sent)
        status_text = status.short
    except FeedItem.DoesNotExist, e :
        status_since = ''
        status_text = ''

    path = context['request'].path
    
    can_update_status = False
    if sender.__class__.__name__ == 'User' :
        from apps.plus_permissions.default_agents import get_anon_user
        if sender.username != get_anon_user().username :
            secure = secure_wrap(sender.get_profile(), user)
            can_update_status = secure.has_interface('Profile.Editor')
    else :
        try :
            sender.get_inner()
            secure = sender
        except :

            secure = secure_wrap(sender, user)
        can_update_status = secure.has_interface(secure.get_inner().__class__.__name__ + '.Editor') 


    return {
        'sender':sender,
        'current_user':user,
        'path':path,