def forms(request): q = request.GET.get("q", False) context = {"search_query": q} if q else {} try: kwargs = request.resolver_match.kwargs url_name = request.resolver_match.url_name if 'entity_slug' in kwargs: entity = Entity.objects.get(slug=kwargs['entity_slug']) initial = {'entity': entity.id} elif 'entity_id' in kwargs: entity = Entity.objects.get(id=kwargs['entity_id']) initial = {'entity': entity.id} else: entity = {} initial = {} if entity: context['questions_url'] = reverse("qna", args=(entity.slug,)) context['candidates_url'] = reverse("candidate_list", args=(entity.slug,)) else: context['questions_url'] = reverse("home") context['candidates_url'] = reverse("candidate_list") if url_name not in SPECIAL_ENTITY_FORM: context['entity_form'] = EntityChoiceForm(initial=initial, auto_id=False) except AttributeError: pass if not request.user.is_authenticated(): context["login_form"] = AuthenticationForm() # TODO: remove context["site"] = get_current_site(request) context["ANALYTICS_ID"] = getattr(settings, 'ANALYTICS_ID', False) return context
def forms(request): q = request.GET.get("q", False) context = {"search_query": q} if q else {} try: kwargs = request.resolver_match.kwargs url_name = request.resolver_match.url_name # many ways to pass an entity entity = getattr(request, 'entity', None) # import pdb; pdb.set_trace() if entity: pass elif 'entity_slug' in kwargs: entity = Entity.objects.get(slug=kwargs['entity_slug']) elif 'entity' in request.GET: entity = Entity.objects.get(id=request.GET['entity']) elif 'entity_slug' in request.GET: entity = Entity.objects.get(slug=request.GET['entity_slug']) context['entity'] = entity # where the magic happens: set local or global scope urls if entity: initial = {'entity': entity.id} context['questions_url'] = reverse("local_home", args=(entity.slug, )) context['candidates_url'] = reverse("candidate_list", args=(entity.slug, )) else: initial = {} context['questions_url'] = reverse("local_home") context['candidates_url'] = reverse("candidate_list") context['entity_form'] = EntityChoiceForm(initial=initial, auto_id=False) except AttributeError: pass if request.user.is_authenticated(): context["profile"] = request.user.profile else: context["login_form"] = AuthenticationForm() context["site"] = get_current_site(request) context["ANALYTICS_ID"] = getattr(settings, 'ANALYTICS_ID', False) context["FACEBOOK_APP_ID"] = os.environ.get('FACEBOOK_APP_ID', '') return context
def forms(request): q = request.GET.get("q", False) context = {"search_query": q} if q else {} try: kwargs = request.resolver_match.kwargs # many ways to pass an entity entity = getattr(request, 'entity', None) if entity: pass elif 'entity_id' in kwargs: entity = get_object_or_404(Entity, pk=kwargs['entity_id']) elif 'entity_slug' in kwargs: entity = get_object_or_404(Entity, slug=kwargs['entity_slug']) elif request.user.is_authenticated(): entity = request.user.profile.locality context['entity'] = entity # where the magic happens: set local or global scope urls if entity: initial = {'entity': entity.id} context['questions_url'] = reverse("local_home", args=(entity.id, )) else: initial = {} context['questions_url'] = reverse("home_page") context['entity_form'] = EntityChoiceForm(initial=initial, auto_id=False) except (AttributeError, Http404): pass if request.user.is_authenticated(): context["profile"] = request.user.profile else: context["login_form"] = AuthenticationForm() context["site"] = get_current_site(request) context["ANALYTICS_ID"] = getattr(settings, 'ANALYTICS_ID', False) context["FACEBOOK_APP_ID"] = os.environ.get('FACEBOOK_APP_ID', '') return context
def public_profile(request, username=None, pk=None): if username: user = get_object_or_404(User, username=username) else: user = get_object_or_404(User, username=pk) questions = user.questions.all() answers = user.answers.all() profile = user.profile user.avatar_url = profile.avatar_url() user.bio = profile.bio user.url = profile.url entity_form = EntityChoiceForm(initial={'entity': profile.locality.id}, auto_id=False) setattr(request, 'entity', profile.locality) context = RequestContext(request, { "candidate": user, "answers": answers, "questions": questions, }) # todo: support members as well as candidates return render(request, "user/public_profile.html", context)
def user_detail(request, username): user = get_object_or_404(User, username=username) questions = user.questions.all() answers = user.answers.all() profile = user.profile user.avatar_url = profile.avatar_url() user.bio = profile.bio user.url = profile.url entity_form = EntityChoiceForm(initial={'entity': profile.locality.id}, auto_id=False) context = RequestContext( request, { "candidate": user, "answers": answers, "questions": questions, "entity": profile.locality, "base_template": get_base_template(profile), "entity_form": entity_form, }) # todo: support members as well as candidates return render(request, "user/user_detail.html", context)