Exemple #1
0
def create(request):
    form = OccurrenceForm(request.POST)

    if not form.is_valid():
        return render(request, "occurrences/occurrence_form.html", {"form": form})
    occurrence = form.save(commit=False)
    occurrence.guest = request.user
    occurrence.unit = request.user.unit
    occurrence.community = request.user.community

    occurrence.save()

    # Send email
    _send_user_mail(
        "Nova ocorrência criada",
        request.user.community.email,
        occurrence.guest,
        "occurrences/occurrence_email.txt",
        {"occurrence": occurrence},
    )

    _send_manager_mail(
        "Nova ocorrência criada",
        request.user.community.email,
        occurrence.guest,
        "occurrences/occurrence_manager_email.txt",
        {"occurrence": occurrence},
    )

    messages.success(request, "Ocorrência criada com sucesso. Uma mensagem será encaminhada ao seu e-mail.")
    return HttpResponseRedirect(r("occurrences:my_occurrences_list"))
Exemple #2
0
def register(request):
    template_name = 'accounts/register_form.html'
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            user = form.save()
            user = authenticate(
                username=user.email, password=form.cleaned_data['password1']
            )
            login(request, user)#login para pegar os dados e enviar email
            #Send register email
            _send_manager_mail('Cadastro de usuário',
                   request.user.community.email,
                   user,
                   'accounts/register_user_email.txt',
                   {'user': user})
            logout(request)#logout para sair do sistema até ser ativado

            messages.error(request, 'Falta pouco para você começar utilizar o AppSíndico. Aguarde a liberação de acesso pelo seu síndico.')
            return HttpResponseRedirect(r('home'))
    else:
        form = RegisterForm()
    context = {
        'form': form,
    }
    return render(request, template_name, context)
Exemple #3
0
def close_occurrence(request, pk):
    try:
        occurrence = Occurrence.objects.get(pk=pk)
    except Occurrence.DoesNotExist:
        raise Http404

    if request.method == "POST":
        occurrence.close_occurrence()

        # Send email
        _send_user_mail(
            "Ocorrência resolvida",
            request.user.community.email,
            occurrence.guest.email,
            "occurrences/close_occurrence_email.txt",
            {"occurrence": occurrence},
        )

        _send_manager_mail(
            "Ocorrência resolvida",
            request.user.community.email,
            occurrence.guest.email,
            "occurrences/close_occurrence_manager_email.txt",
            {"occurrence": occurrence},
        )

        messages.success(request, "Ocorrência concluída com sucesso.")
        return HttpResponseRedirect(r("occurrences:my_occurrences_list"))
Exemple #4
0
def create(request):
        form = ContactForm(request.POST)
        if not form.is_valid():
            return render(request, 'home.html',
                          {'form': form})

        contact = form.save()

        #Send contact email
        _send_manager_mail('Solicitação de informações',
                   settings.DEFAULT_FROM_EMAIL,
                   contact.email,
                   'contact_email.txt',
                   {'contact': contact})

        messages.success(request, 'Sua solicitação foi cadastrada com sucesso.')
        return HttpResponseRedirect(r('home'))
Exemple #5
0
def accompaniment(request, pk):
    try:
        occurrence = Occurrence.objects.get(pk=pk)
        replies = occurrence.reply_set.all()
    except Occurrence.DoesNotExist:
        raise Http404

    if request.method == "POST":
        form = ReplyForm(request.POST)

        if form.is_valid():
            reply = form.save(commit=False)
            reply.reply_guest = request.user
            reply.occurrence_id = pk
            reply.save()

            form = ReplyForm()

            # Send email
            _send_user_mail(
                "Ocorrência atualizada",
                request.user.community.email,
                occurrence.guest.email,
                "occurrences/reply_email.txt",
                {"reply": reply},
            )

            _send_manager_mail(
                "Ocorrência atualizada",
                request.user.community.email,
                occurrence.guest.email,
                "occurrences/reply_manager_email.txt",
                {"reply": reply},
            )

            messages.success(request, "Mensagem registrada com sucesso")

    else:
        form = ReplyForm()

    return render(
        request,
        "occurrences/occurrence_accompaniment.html",
        {"form": form, "occurrence": occurrence, "replies": replies},  # retorna formulario em branco depois do envio
    )