Ejemplo n.º 1
0
def premium(request):
    """
    Page to become premium.
    """
    if request.related_user.is_premium:
        return render(request, "account/already_premium.html", get_context())

    forms = payment.get_payment_forms(request.related_user, request)
    return render(request, "account/premium.html", get_context(payment_forms=forms))
Ejemplo n.º 2
0
def base(request):
    """
    Providing base variables.

    :param request:        the request to be processed
    """
    return get_context()
Ejemplo n.º 3
0
def home(request):
    """
    Home view. Rendering first forms.
    """
    search_form = forms.SimpleSearchForm()
    registration_form = forms.RegistrationForm()
    return render(
        request, "home.html",
        get_context(search_form=search_form, registration_form=registration_form)
    )
Ejemplo n.º 4
0
def tools(request):
    """
    Display the tools (DownloadableFile objects) to the user.
    """
    tool_files = defaultdict(list)
    for tool in DownloadableFile.objects.all().order_by("file_type", "index"):
        tool_files[tool.file_type].append(tool)

    return render(
        request, "espace/tools.html",
        get_context(tool_files=dict(tool_files), kinds=DownloadableFile.KINDS)
    )
Ejemplo n.º 5
0
def register(request, social=None, type=None):
    """
    Register view. Allow user creation.
    """
    if not type:
        if request.method == "POST":
            form = forms.RegistrationForm(request.POST)
            if form.is_valid():
                form.save(request)
            else:
                return render(request, "registration/register.html", get_context(social=social, form=form))
        else:
            form = forms.RegistrationForm()
            return render(request, "registration/register.html", get_context(social=social, form=form))
    else:
        if not has_user_related(request.user):
            UserInfo.create_user(dj_user=request.user, type=type)
        else:
            return redirect('account')

    return HttpResponseRedirect('/confirmation/')
Ejemplo n.º 6
0
def search(request):
    """
    Search view.
    """
    data = request.POST if request.method == "POST" else request.GET
    search_type = data.get("type")
    if request.user.is_authenticated():
        related = get_user_related(request.user)
        favorites = related.favorites.all()
        if not search_type and isinstance(related, Prestataire):
            search_type = "famille"
    else:
        favorites = []

    search_type = "prestataire" if search_type not in ["famille", "prestataire"] else search_type
    if search_type == "famille":
        FormClass = forms.FamilleSearchForm
        objects = Famille.objects.filter(compute_user_visibility_filters(request.user))
        template = "search/famille.html"
    else:
        FormClass = forms.PrestataireSearchForm
        objects = Prestataire.objects.filter(compute_user_visibility_filters(request.user))
        template = "search/prestataire.html"

    form = FormClass({"pc": data.get("postal_code")})

    if not settings.ALLOW_BASIC_PLAN_IN_SEARCH:
        objects = objects.filter(plan=UserInfo.PLANS["premium"])

    if data.get("postal_code"):
        objects = objects.filter(Q(postal_code=data["postal_code"]) | Q(city=data["postal_code"]))
    objects = objects.order_by("-updated_at")
    objects = [obj for obj in objects if obj.visibility_score_is_enough]

    total_search_results = len(objects)
    nb_search_results = min(settings.NB_SEARCH_RESULTS, total_search_results)
    objects = objects[:nb_search_results]
    result_template = get_result_template_from_user(request, search_type)
    return render(
        request, template,
        get_context(
            search_form=form, results=objects, result_template=result_template,
            nb_search_results=nb_search_results, ordering=form.ordering_dict,
            favorites=favorites, user=request.user, search_type=search_type,
            max_nb_search_results=settings.NB_SEARCH_RESULTS,
            total_search_results=total_search_results
        )
    )
Ejemplo n.º 7
0
def account(request):
    check_plan_expiration(related=request.related_user)
    url_hash = ""
    if request.method == "POST":
        account_forms = forms.AccountFormManager(instance=request.related_user, data=request.POST, files=request.FILES)
        url_hash = account_forms.form_submitted
        if account_forms.is_valid():
            account_forms.save()
            return HttpResponseRedirect('/mon-compte/?success#%s' % url_hash)
    else:
        account_forms = forms.AccountFormManager(instance=request.related_user)

    return render(
        request, 'account/%s.html' % account_forms.instance_type,
        get_context(related=request.related_user, url_hash=url_hash, **account_forms.forms)
    )
Ejemplo n.º 8
0
def profile(request, type, uid):
    """
    Display the profile of a user.
    A nice 404 view is shown to the user
    if the profile does not exist OR the profile
    is not premium.
    A nice 401 view is shown to the user if the
    profile didn't want to show itself to the user
    or globally.
    """
    if type not in ("famille", "prestataire"):
        raise Http404

    context = {}

    if type == "famille":
        ModelClass = Famille
        RatingClass = FamilleRatings
        RatingFormClass = forms.RatingFamilleForm
    else:
        ModelClass = Prestataire
        RatingClass = PrestataireRatings
        RatingFormClass = forms.RatingPrestataireForm

    try:
        user = ModelClass.objects.get(pk=uid)
    except ModelClass.DoesNotExist:
        return render(request, "profile/404.html", status=404)

    # the user can view its own profile but others cannot if he is not premium
    if request.related_user != user and not user.is_premium:
        return render(request, "profile/404.html", status=404)

    if not user.profile_access_is_authorized(request):
        return render(request, "profile/401.html", status=401)

    if has_user_related(request.user):
        related_user = get_user_related(request.user)
        context["related_user"] = related_user
        context["favorited"] = related_user.favorites.filter(object_id=user.pk, object_type=type.title()).count()

        # users cant vote for themselves or twice for a user
        if user != related_user and not RatingClass.user_has_voted_for(related_user, user):
            rating = RatingClass(user=user, by=related_user.simple_id)
            context["rating_form"] = RatingFormClass(instance=rating)

    return render(request, "profile/%s.html" % type, get_context(profile=user, **context))
Ejemplo n.º 9
0
def advanced(request):
    """
    Render the advanved settings view. It is called by several views.
    """
    FormClass = forms.PrestataireAdvancedForm
    if isinstance(request.related_user, Famille):
        FormClass = forms.FamilleAdvancedForm

    if request.method == "POST":
        form = FormClass(instance=request.related_user, data=request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/mon-compte/parametres-avances/?success')
    else:
        form = FormClass(instance=request.related_user)

    return render(request, "account/advanced.html", get_context(form=form))
Ejemplo n.º 10
0
 def test_get_context(self):
     self.assertIn("site_title", utils.get_context())
     self.assertIn("site_title", utils.get_context(other="value"))
     self.assertEqual(utils.get_context(other="value")["other"], "value")
Ejemplo n.º 11
0
def premium_success(request):
    return render(request, "account/premium.html", get_context(action="success"))