mirror of
https://github.com/Superredstone/patrickcanal.it.git
synced 2026-09-20 17:51:12 +02:00
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
from django.conf import settings
|
|
from django.http.response import FileResponse, HttpResponseBadRequest
|
|
from django.utils.translation import gettext as _
|
|
from django.views.generic import DetailView, ListView, TemplateView
|
|
from post_office import mail
|
|
|
|
from portfolio import forms, models
|
|
|
|
|
|
class PortfolioView(TemplateView):
|
|
template_name = "index.html"
|
|
|
|
def get_context_data(self, **kwargs):
|
|
contact_form = forms.ContactForm()
|
|
return {
|
|
"job_experiences": models.JobExperience.objects.all().order_by("-start"),
|
|
"contact_form": contact_form,
|
|
}
|
|
|
|
|
|
class ProjectList(TemplateView):
|
|
template_name = "project_list.html"
|
|
|
|
|
|
class ContactSend(TemplateView):
|
|
template_name = "contact_thanks.html"
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
form = forms.ContactForm(request.POST)
|
|
|
|
if not form.is_valid():
|
|
return HttpResponseBadRequest(_("Invalid request"))
|
|
|
|
mail.send(
|
|
subject=form.cleaned_data["subject"],
|
|
message=form.cleaned_data["message"],
|
|
sender=settings.EMAIL_HOST_USER,
|
|
cc=form.cleaned_data["email"],
|
|
recipients=[settings.EMAIL_CONTACT],
|
|
)
|
|
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
|
|
class CompanyLogo(DetailView):
|
|
model = models.Company
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
company = self.get_object()
|
|
return FileResponse(company.logo)
|
|
|
|
|
|
class ProjectListQuery(ListView):
|
|
template_name = "project_list_query.html"
|
|
model = models.Project
|
|
|
|
def get_queryset(self):
|
|
query = self.request.GET.get("query")
|
|
if not query:
|
|
return super().get_queryset()
|
|
|
|
return super().get_queryset().filter(name__contains=query)
|