Exemple #1
0
def profile(request, user_slug):
    user = get_object_or_404(User, slug=user_slug)

    if user.id == request.me.id:
        goto = request.GET.get("goto")
        if goto:
            return redirect(goto)

    tags = Tag.objects.filter(is_visible=True).all()

    intro = Post.get_user_intro(user)
    projects = Post.objects.filter(author=user, type=Post.TYPE_PROJECT).all()
    active_tags = {t.tag_id for t in UserTag.objects.filter(user=user).all()}
    achievements = UserBadge.objects.filter(user=user)[:8]
    expertises = UserExpertise.objects.filter(user=user).all()
    posts = Post.objects_for_user(request.me)\
        .filter(author=user, is_visible=True)\
        .exclude(type__in=[Post.TYPE_INTRO, Post.TYPE_PROJECT])

    return render(
        request, "users/profile.html", {
            "user": user,
            "intro": intro,
            "projects": projects,
            "tags": tags,
            "active_tags": active_tags,
            "achievements": achievements,
            "expertise_form": ExpertiseForm(),
            "expertises": expertises,
            "posts": paginate(request, posts),
        })
Exemple #2
0
def add_expertise(request):
    if request.method == "POST":
        form = ExpertiseForm(request.POST)
        if form.is_valid():
            user_expertise = form.save(commit=False)
            user_expertise.user = request.me
            UserExpertise.objects.filter(
                user=request.me, expertise=user_expertise.expertise).delete()
            user_expertise.save()
            return {
                "status": "created",
                "expertise": {
                    "name": user_expertise.name,
                    "expertise": user_expertise.expertise,
                    "value": user_expertise.value,
                },
            }

    return {"status": "tipidor"}