def apply(request, form_class=HubPlusApplicationForm, template_name="account/apply_form.html"): user = request.user if user.__class__ == AnonymousUser: user = get_anon_user() hubs = TgGroup.objects.hubs() if request.method == "POST": form = form_class(request.POST) if form.is_valid(): application_to = form.save(request.user) return render_to_response( 'plus_contacts/application_thanks.html', { 'application_to': application_to, "head_title": _('Thanks for your application'), "head_title_status": '' }, context_instance=RequestContext(request)) else: form = form_class() default_country = form.data.get('country', False) and form.data['country'] or "UK" country_field = form.fields['country'].widget.render( "country", default_country) return render_to_response(template_name, { "form": form, 'country_field': country_field, "hubs": hubs, "head_title": _("Like to join us?"), "head_title_status": '', }, context_instance=RequestContext(request))
def apply(request, form_class=HubPlusApplicationForm, template_name="account/apply_form.html"): user = request.user if user.__class__ == AnonymousUser : user = get_anon_user() # XXX there's a dedicated function for this, replace hubs = TgGroup.objects.filter(level='member').exclude(place__name=settings.VIRTUAL_HUB_NAME) if request.method == "POST": form = form_class(request.POST) if form.is_valid(): contact, application = form.save(user) return render_to_response('plus_contacts/application_thanks.html',{ 'group' : form.cleaned_data['group'], "head_title" : 'Thanks for your application', "head_title_status" : '', },context_instance=RequestContext(request)) else : print "invalid form" else: form = form_class() return render_to_response(template_name, { "form": form, "hubs":hubs, "head_title": "Like to join us?", "head_title_status" : '', }, context_instance=RequestContext(request))
def apply(request, group, current_app='plus_groups', **kwargs): if request.user == get_anon_user(): return HttpResponseRedirect(reverse('acct_apply')) if Application.objects.filter(status=PENDING, group=group, applicant_object_id=request.user.id, applicant_content_type=ContentType.objects.get_for_model(User)).count(): request.user.message_set.create(message=_("You have already have a pending application to %(group_name)s.") % {'group_name': group.get_display_name()}) else: group.apply(request.user, request.user) # add reason for applying form here request.user.message_set.create(message=_("Application to %(group_name)s sent.") % {'group_name': group.get_display_name()}) return HttpResponseRedirect(reverse(current_app + ':group', args=(group.id,)))
def group(request, group, template_name="plus_groups/group.html", current_app='plus_groups', **kwargs): tag_string = '' tags = tag_string.split('+') search = request.GET.get('search', '') order = request.GET.get('order', '') explicit_order = '' if order: explicit_order = order try: tags.remove('') except ValueError: pass user = request.user if not user.is_authenticated(): user = get_anon_user() request.user = user members = group.get_users()[:10] member_count = group.get_no_members() hosts = group.get_admin_group().get_users()[:10] host_count = group.get_admin_group().get_no_members() can_join = False apply = False leave = False invite = False can_comment = False message = False add_link = False can_tag = False if user.is_authenticated(): if user.is_direct_member_of(group.get_inner()): leave = True try : group.invite_member invite = True except Exception, e :# user doesn't have invite permission pass else : try : group.join can_join = True except Exception, e: # user doesn't have join permission pass try : if not can_join : group.apply apply = True except Exception, e : # user doesn't have apply permission pass
def invite(request, group, template_name='plus_groups/invite.html', current_app='plus_groups', **kwargs): if request.user == get_anon_user(): return HttpResponseRedirect(reverse('acct_invite')) if request.POST : form = TgGroupMemberInviteForm(request.POST) if form.is_valid() : invited = form.cleaned_data['invited'] from apps.plus_groups.models import invite_to_group invite_to_group(group,invited,request.user,form.cleaned_data['special_message']) message = _("You have invited %(invited)s to %(group)s.") % {'invited':invited,'group':group.get_display_name()} request.user.message_set.create(message=message) return HttpResponseRedirect(reverse(current_app + ':group',args=(group.id,))) else : form = TgGroupMemberInviteForm() return render_to_response(template_name,{ 'form' : form, 'group' : group, 'group_id' : group.id, }, context_instance=RequestContext(request, current_app=current_app))
def apply(request, form_class=HubPlusApplicationForm, template_name="account/apply_form.html"): user = request.user if user.__class__ == AnonymousUser: user = get_anon_user() hubs = TgGroup.objects.hubs() if request.method == "POST": form = form_class(request.POST) if form.is_valid(): application_to = form.save(request.user) return render_to_response( "plus_contacts/application_thanks.html", { "application_to": application_to, "head_title": _("Thanks for your application"), "head_title_status": "", }, context_instance=RequestContext(request), ) else: form = form_class() default_country = form.data.get("country", False) and form.data["country"] or "UK" country_field = form.fields["country"].widget.render("country", default_country) return render_to_response( template_name, { "form": form, "country_field": country_field, "hubs": hubs, "head_title": _("Like to join us?"), "head_title_status": "", }, context_instance=RequestContext(request), )
def process_request(self, request): if not request.user.is_authenticated() : request.user = get_anon_user() return None
user = context['request'].user 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,