def pay_membership(request, username): other_user = User.objects.get(username=username) # Show payment form if you are upgrading yourself if request.user == other_user: chapters = Network.objects.filter(chapter_info__isnull=False, member_users=request.user, is_active=True) form = MembershipForm(chapters=chapters) form.helper.action = reverse('profile_pay_membership2', kwargs={'username': username}) return render_to_response( 'creditcard/new_payment.html', {'form': form}, context_instance=RequestContext(request) ) # Admins / chapter execs can upgrade anyone's membership elif request.user.has_module_perms("profiles") or is_exec_over(other_user, request.user): other_user.get_profile().pay_membership() message = loader.get_template("profiles/member_upgraded.html") c = Context({'user': other_user.visible_name()}) request.user.message_set.create(message=message.render(c)) return HttpResponseRedirect(reverse('profile_detail', kwargs={'username': username })) # should not happen.. duh duh duh! else: return render_to_response('denied.html', context_instance=RequestContext(request))
def pay_membership(request, username): other_user = User.objects.get(username=username) # Show payment form if you are upgrading yourself if request.user == other_user: chapters = Network.objects.filter(chapter_info__isnull=False, member_users=request.user, is_active=True) form = MembershipForm(chapters=chapters) form.helper.action = reverse('profile_pay_membership2', kwargs={'username': username}) return render_to_response('creditcard/new_payment.html', {'form': form}, context_instance=RequestContext(request)) # Admins / chapter execs can upgrade anyone's membership elif request.user.has_module_perms("profiles") or is_exec_over( other_user, request.user): other_user.get_profile().pay_membership() message = loader.get_template("profiles/member_upgraded.html") c = Context({'user': other_user.visible_name()}) request.user.message_set.create(message=message.render(c)) return HttpResponseRedirect( reverse('profile_detail', kwargs={'username': username})) # should not happen.. duh duh duh! else: return render_to_response('denied.html', context_instance=RequestContext(request))
def test_is_exec_over(self): self.assertEquals(True, is_exec_over(self.user_one, self.user_one)) self.assertEquals(True, is_exec_over(self.user_two, self.user_one)) self.assertEquals(False, is_exec_over(self.user_three, self.user_one)) self.assertEquals(True, is_exec_over(self.user_four, self.user_one)) self.assertEquals(False, is_exec_over(self.user_one, self.user_four)) self.assertEquals(False, is_exec_over(self.user_two, self.user_four)) self.assertEquals(True, is_exec_over(self.user_three, self.user_four)) self.assertEquals(True, is_exec_over(self.user_four, self.user_four))
def pay_membership2(request, username): other_user = User.objects.get(username=username) # Show payment form if you are upgrading yourself if request.user == other_user: if request.method == 'POST': chapters = Network.objects.filter(chapter_info__isnull=False, member_users=request.user, is_active=True) f = MembershipForm(request.POST, chapters=chapters) if f.is_valid(): # will have to do some sku-building once we have chapters in if f.cleaned_data['chapter'] == "none": product = Product.objects.get(sku=f.cleaned_data['membership_type']) created = False else: product, created = Product.objects.get_or_create(sku="%s-%s" % (f.cleaned_data['membership_type'], f.cleaned_data['chapter'])) if created: # TODO: un-hardcode? Fix so we don't need to do this dynamically? if f.cleaned_data['membership_type'] == 'studues': product.amount = "20.00" product.name = "Student membership (%s)" % f.cleaned_data['chapter'] product.save() elif f.cleaned_data['membership_type'] == 'produes': product.amount = "40.00" product.name = "Professional membership (%s)" % f.cleaned_data['chapter'] product.save() else: # uhh....!!! pass form = PaymentForm(initial={'products':product.sku}) form.user = other_user form.helper.action = reverse('profile_pay_preview', kwargs={'username': username}) return render_to_response( 'creditcard/new_payment.html', {'form': form}, context_instance=RequestContext(request) ) else: f.helper.action = reverse('profile_pay_membership2', kwargs={'username': username}) return render_to_response( 'creditcard/new_payment.html', {'form': f}, context_instance=RequestContext(request) ) # what kind of error to throw...? # Admins / chapter execs can upgrade anyone's membership elif request.user.has_module_perms("profiles") or is_exec_over(other_user, request.user): other_user.get_profile().pay_membership() message = loader.get_template("profiles/member_upgraded.html") c = Context({'user': other_user.visible_name()}) request.user.message_set.create(message=message.render(c)) return HttpResponseRedirect(reverse('profile_detail', kwargs={'username': username })) # should not happen.. duh duh duh! else: return render_to_response('denied.html', context_instance=RequestContext(request))
def profile(request, username, template_name="profiles/profile.html", extra_context=None): other_user = get_object_or_404(User, username=username) if not other_user.is_active: return render_to_response('profiles/deleted.html', {}, context_instance=RequestContext(request)) """ This is really really neat code, but dunno where to put it since address is now handled via ajax widget...!! # if changed city, prompt to update networks if profile_form.cleaned_data['city'] != other_user.get_profile().city: # join new network # TODO: use geocoding to find closest network(s) try: network = Network.objects.get(name=profile_form.cleaned_data['city'], network_type='R') if not network.user_is_member(other_user): message = loader.get_template("profiles/suggest_network.html") c = Context({'network': network, 'action': 'join'}) request.user.message_set.create(message=message.render(c)) except Network.DoesNotExist: pass # leave old network try: network = Network.objects.get(name=other_user.get_profile().city, network_type='R') if network.user_is_member(other_user): message = loader.get_template("profiles/suggest_network.html") c = Context({'network': network, 'action': 'leave', 'user': other_user}) request.user.message_set.create(message=message.render(c)) except Network.DoesNotExist: pass """ if extra_context == None: extra_context = {} profile = other_user.get_profile() if profile.membership_expiry != None and profile.membership_expiry > date.today(): extra_context['regular'] = True if profile.membership_expiry == None or \ profile.membership_expiry < date.today() + timedelta(30): extra_context['renew'] = True # if template_name == None: # return pinaxprofile(request, username, extra_context=extra_context) # else: # return pinaxprofile(request, username, template_name, extra_context) if extra_context is None: extra_context = {} other_user = get_object_or_404(User, username=username) if request.user.is_authenticated(): is_friend = Friendship.objects.are_friends(request.user, other_user) if is_friend: invite_form = None previous_invitations_to = None previous_invitations_from = None if request.method == "POST": if request.POST.get("action") == "remove": # @@@ perhaps the form should just post to friends and be redirected here Friendship.objects.remove(request.user, other_user) request.user.message_set.create(message=_("You have removed %(from_user)s from friends") % {'from_user': other_user.visible_name()}) is_friend = False invite_form = InviteFriendForm(request.user, { 'to_user': username, 'message': ugettext("Let's be friends!"), }) else: if request.user.is_authenticated() and request.method == "POST": if request.POST.get("action") == "invite": # @@@ perhaps the form should just post to friends and be redirected here 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!"), }) invitation_id = request.POST.get("invitation", None) if request.POST.get("action") == "accept": # @@@ perhaps the form should just post to friends and be redirected here try: invitation = FriendshipInvitation.objects.get(id=invitation_id) if invitation.to_user == request.user: try: # have gotten IntegrityError from this... #573 invitation.accept() # (accepting an already-accepted invite, maybe?) except: pass request.user.message_set.create(message=_("You have accepted the friendship request from %(from_user)s") % {'from_user': invitation.from_user.visible_name()}) except FriendshipInvitation.DoesNotExist: pass elif request.POST.get("action") == "decline": # @@@ perhaps the form should just post to friends and be redirected here try: invitation = FriendshipInvitation.objects.get(id=invitation_id) if invitation.to_user == request.user: invitation.decline() request.user.message_set.create(message=_("You have declined the friendship request from %(from_user)s") % {'from_user': invitation.from_user.visible_name()}) except FriendshipInvitation.DoesNotExist: pass else: invite_form = InviteFriendForm(request.user, { 'to_user': username, 'message': ugettext("Let's be friends!"), }) 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) friends_qry = Friendship.objects.filter(Q(from_user=other_user) | Q(to_user=other_user))\ .select_related(depth=1).order_by('?')[:10] other_friends = [] for f in friends_qry: if f.to_user == other_user: other_friends.append(f.from_user) else: other_friends.append(f.to_user) if request.user == other_user: is_me = True else: is_me = False pending_requests = FriendshipInvitation.objects.filter(to_user=other_user, status=2).count() previous_invitations_to = FriendshipInvitation.objects.invitations(to_user=other_user, from_user=request.user) previous_invitations_from = FriendshipInvitation.objects.invitations(to_user=request.user, from_user=other_user) # friends & admins have visibility. has_visibility = is_friend or request.user.has_module_perms("profiles") if not has_visibility: #but so does your chapter's exec mygrps = Network.objects.filter(members__user=request.user, members__is_admin=True, is_active=True).order_by('name') if len(list(set(mygrps) & set(other_user.get_networks()))) > 0: has_visibility = True else: other_friends = [] is_friend = False is_me = False is_following = False pending_requests = 0 invite_form = None previous_invitations_to = None previous_invitations_from = None has_visibility = False return render_to_response(template_name, dict({ "is_me": is_me, "is_friend": is_friend, #"is_following": is_following, "is_exec_over": is_exec_over(other_user, request.user), "other_user": other_user, "other_friends": other_friends, "invite_form": invite_form, "previous_invitations_to": previous_invitations_to, "previous_invitations_from": previous_invitations_from, "pending_requests": pending_requests, "has_visibility": has_visibility, }, **extra_context), context_instance=RequestContext(request))
def pay_membership2(request, username): other_user = User.objects.get(username=username) # Show payment form if you are upgrading yourself if request.user == other_user: if request.method == 'POST': chapters = Network.objects.filter(chapter_info__isnull=False, member_users=request.user, is_active=True) f = MembershipForm(request.POST, chapters=chapters) if f.is_valid(): # will have to do some sku-building once we have chapters in if f.cleaned_data['chapter'] == "none": product = Product.objects.get( sku=f.cleaned_data['membership_type']) created = False else: product, created = Product.objects.get_or_create( sku="%s-%s" % (f.cleaned_data['membership_type'], f.cleaned_data['chapter'])) if created: # TODO: un-hardcode? Fix so we don't need to do this dynamically? if f.cleaned_data['membership_type'] == 'studues': product.amount = "20.00" product.name = "Student membership (%s)" % f.cleaned_data[ 'chapter'] product.save() elif f.cleaned_data['membership_type'] == 'produes': product.amount = "40.00" product.name = "Professional membership (%s)" % f.cleaned_data[ 'chapter'] product.save() else: # uhh....!!! pass form = PaymentForm(initial={'products': product.sku}) form.user = other_user form.helper.action = reverse('profile_pay_preview', kwargs={'username': username}) return render_to_response( 'creditcard/new_payment.html', {'form': form}, context_instance=RequestContext(request)) else: f.helper.action = reverse('profile_pay_membership2', kwargs={'username': username}) return render_to_response( 'creditcard/new_payment.html', {'form': f}, context_instance=RequestContext(request)) else: # you came here somehow... bookmarked page? # (viewing your own upgrade page, but not as a POST request) # bump you back to the form. return HttpResponseRedirect( reverse('profile_pay_membership', kwargs={'username': username})) # Admins / chapter execs can upgrade anyone's membership elif request.user.has_module_perms("profiles") or is_exec_over( other_user, request.user): other_user.get_profile().pay_membership() message = loader.get_template("profiles/member_upgraded.html") c = Context({'user': other_user.visible_name()}) request.user.message_set.create(message=message.render(c)) return HttpResponseRedirect( reverse('profile_detail', kwargs={'username': username})) # should not happen.. duh duh duh! else: return render_to_response('denied.html', context_instance=RequestContext(request))
def profile(request, username, template_name="profiles/profile.html", extra_context=None): other_user = get_object_or_404(User, username=username) if not other_user.is_active \ and not other_user.emailaddress_set.count() \ and request.user.has_module_perms("profiles"): return render_to_response('profiles/deleted.html', {}, context_instance=RequestContext(request)) """ This is really really neat code, but dunno where to put it since address is now handled via ajax widget...!! # if changed city, prompt to update networks if profile_form.cleaned_data['city'] != other_user.get_profile().city: # join new network # TODO: use geocoding to find closest network(s) try: network = Network.objects.get(name=profile_form.cleaned_data['city'], network_type='R') if not network.user_is_member(other_user): message = loader.get_template("profiles/suggest_network.html") c = Context({'network': network, 'action': 'join'}) request.user.message_set.create(message=message.render(c)) except Network.DoesNotExist: pass # leave old network try: network = Network.objects.get(name=other_user.get_profile().city, network_type='R') if network.user_is_member(other_user): message = loader.get_template("profiles/suggest_network.html") c = Context({'network': network, 'action': 'leave', 'user': other_user}) request.user.message_set.create(message=message.render(c)) except Network.DoesNotExist: pass """ if extra_context == None: extra_context = {} profile = other_user.get_profile() if profile.membership_expiry != None and profile.membership_expiry > date.today( ): extra_context['regular'] = True if profile.membership_expiry == None or \ profile.membership_expiry < date.today() + timedelta(30): extra_context['renew'] = True # if template_name == None: # return pinaxprofile(request, username, extra_context=extra_context) # else: # return pinaxprofile(request, username, template_name, extra_context) if extra_context is None: extra_context = {} other_user = get_object_or_404(User, username=username) if request.user.is_authenticated(): is_friend = Friendship.objects.are_friends(request.user, other_user) if is_friend: invite_form = None previous_invitations_to = None previous_invitations_from = None if request.method == "POST": if request.POST.get( "action" ) == "remove": # @@@ perhaps the form should just post to friends and be redirected here Friendship.objects.remove(request.user, other_user) request.user.message_set.create( message=_( "You have removed %(from_user)s from friends") % {'from_user': other_user.visible_name()}) is_friend = False invite_form = InviteFriendForm( request.user, { 'to_user': username, 'message': ugettext("Let's be friends!"), }) else: if request.user.is_authenticated() and request.method == "POST": if request.POST.get( "action" ) == "invite": # @@@ perhaps the form should just post to friends and be redirected here 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!"), }) invitation_id = request.POST.get("invitation", None) if request.POST.get( "action" ) == "accept": # @@@ perhaps the form should just post to friends and be redirected here try: invitation = FriendshipInvitation.objects.get( id=invitation_id) if invitation.to_user == request.user: try: # have gotten IntegrityError from this... #573 invitation.accept( ) # (accepting an already-accepted invite, maybe?) except: pass request.user.message_set.create( message= _("You have accepted the friendship request from %(from_user)s" ) % { 'from_user': invitation.from_user.visible_name() }) except FriendshipInvitation.DoesNotExist: pass elif request.POST.get( "action" ) == "decline": # @@@ perhaps the form should just post to friends and be redirected here try: invitation = FriendshipInvitation.objects.get( id=invitation_id) if invitation.to_user == request.user: invitation.decline() request.user.message_set.create( message= _("You have declined the friendship request from %(from_user)s" ) % { 'from_user': invitation.from_user.visible_name() }) except FriendshipInvitation.DoesNotExist: pass else: invite_form = InviteFriendForm( request.user, { 'to_user': username, 'message': ugettext("Let's be friends!"), }) 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) friends_qry = Friendship.objects.filter(Q(from_user=other_user) | Q(to_user=other_user))\ .select_related(depth=1).order_by('?')[:10] other_friends = [] for f in friends_qry: if f.to_user == other_user: other_friends.append(f.from_user) else: other_friends.append(f.to_user) if request.user == other_user: is_me = True else: is_me = False pending_requests = FriendshipInvitation.objects.filter( to_user=other_user, status=2).count() previous_invitations_to = FriendshipInvitation.objects.invitations( to_user=other_user, from_user=request.user) previous_invitations_from = FriendshipInvitation.objects.invitations( to_user=request.user, from_user=other_user) # friends & admins have visibility. has_visibility = is_friend or request.user.has_module_perms("profiles") if not has_visibility: #but so does your chapter's exec mygrps = Network.objects.filter(members__user=request.user, members__is_admin=True, is_active=True).order_by('name') if len(list(set(mygrps) & set(other_user.get_networks()))) > 0: has_visibility = True else: other_friends = [] is_friend = False is_me = False is_following = False pending_requests = 0 invite_form = None previous_invitations_to = None previous_invitations_from = None has_visibility = False uprofile = False if request.user.has_module_perms("profiles"): try: from stats.models import usage_profile uprofile = usage_profile(other_user) except: pass if request.user == other_user: # user can always see their own post, regardless of group visibility # (ie, if I write some posts to a private group then leave the group, # those posts should still show in this listing) topics = GroupTopic.objects.get_for_user(other_user) else: # start with all visible topics topics = GroupTopic.objects.visible(request.user) # then restrict further to only ones by the given user topics = GroupTopic.objects.get_for_user(other_user, topics) return render_to_response( template_name, dict( { "is_me": is_me, "is_friend": is_friend, #"is_following": is_following, "is_exec_over": is_exec_over(other_user, request.user), "other_user": other_user, "other_friends": other_friends, "invite_form": invite_form, "previous_invitations_to": previous_invitations_to, "previous_invitations_from": previous_invitations_from, "pending_requests": pending_requests, "has_visibility": has_visibility, "other_usage_profile": uprofile, "topics": topics }, **extra_context), context_instance=RequestContext(request))