Exemplo n.º 1
0
 def get(self, request):
     getLanguage(request)
     chats = Chat.objects.filter(members__in=[request.user.id])
     return render(
         request,
         "users/dialogs.html",
         {"user_profile": request.user, "chats": chats},
     )
Exemplo n.º 2
0
def profile(request):
    getLanguage(request)
    if request.method == "POST":
        u_form = UserUpdateForm(request.POST, instance=request.user)
        p_form = ProfileUpdateForm(
            request.POST, request.FILES, instance=request.user.profile
        )
        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()
            messages.success(request, "%s" % "Your profile has been updated")
            return redirect("profile")
    else:
        getLanguage(request)
        u_form = UserUpdateForm(instance=request.user)
        p_form = ProfileUpdateForm(instance=request.user.profile)
    context = {"u_form": u_form, "p_form": p_form}

    return render(request, "users/cabinet.html", context)
Exemplo n.º 3
0
def register(request):
    getLanguage(request)
    if request.method == "POST":
        form = UserRegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get("username")
            password = form.cleaned_data.get("password1")
            messages.success(
                request,
                "%s %s" % ("Your account has been created. Please login as", username),
            )
            form.save()
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect("create-profile")

    else:
        form = UserRegisterForm()
    return render(request, "users/reg.html", {"form": form})
Exemplo n.º 4
0
def fill_profile(request):
    getLanguage(request)
    usr = request.user
    form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.profile)
    if form.is_valid():
        country = form.cleaned_data.get("country")
        city = form.cleaned_data.get("city")
        language = form.cleaned_data.get("language")
        speciality = form.cleaned_data.get("speciality")
        skills = form.cleaned_data.get("skills")
        status = form.cleaned_data.get("status")
        bio = form.cleaned_data.get("bio")
        facebook = form.cleaned_data.get("facebook")
        linkedin = form.cleaned_data.get("linkedin")
        form.save()
        return redirect("deals-home")
    else:
        print(form.errors)
        messages.error(request, form.errors)
    return render(request, "users/fill_profile.html", context={"form": form})
Exemplo n.º 5
0
    def get(self, request, chat_id):
        getLanguage(request)
        chats = Chat.objects.filter(members__in=[request.user.id])
        try:
            chat = Chat.objects.get(id=chat_id)
            if request.user in chat.members.all():
                chat.message_set.filter(is_readed=False).exclude(
                    author=request.user
                ).update(is_readed=True)
            else:
                chat = None
        except Chat.DoesNotExist:
            chat = None

        return render(
            request,
            "users/messages.html",
            {
                "user_profile": request.user,
                "chat": chat,
                "form": MessageForm(),
                "chats": chats,
            },
        )