diff --git a/contact/admin.py b/contact/admin.py index 8c38f3f..633ae9f 100644 --- a/contact/admin.py +++ b/contact/admin.py @@ -1,3 +1,11 @@ from django.contrib import admin -# Register your models here. +from .models import Feedback + + +@admin.register(Feedback) +class LocationAdmin(admin.ModelAdmin): + list_display = ('subject', 'name', 'date', 'message',) + list_display_links = ('subject',) + search_fields = ('name', 'message', 'subject',) + list_per_page = 30 diff --git a/contact/forms.py b/contact/forms.py new file mode 100644 index 0000000..0f16877 --- /dev/null +++ b/contact/forms.py @@ -0,0 +1,25 @@ +from django import forms +from django.conf import settings +from django.core.mail import send_mail + +from .models import Feedback + + +class FeedbackForm(forms.ModelForm): + + class Meta: + model = Feedback + exclude = ['ip', 'agent'] + + def __init__(self, *args, **kwargs): + super(FeedbackForm, self).__init__(*args, **kwargs) + self.fields['name'].widget.attrs.update({'class': 'uk-input', 'placeholder': 'Name'}) + self.fields['email'].widget.attrs.update({'class': 'uk-input', 'placeholder': 'E-mail'}) + self.fields['subject'].widget.attrs.update({'class': 'uk-input', 'placeholder': 'Subject'}) + self.fields['message'].widget.attrs.update({'class': 'uk-textarea', 'placeholder': 'Message'}) + + def send_email(self): + subject = "Gallery Feedback: " + self.cleaned_data['subject'] + from_email = self.cleaned_data['email'] + message = self.cleaned_data['message'] + send_mail(subject, message, from_email, [settings.EMAIL_TO]) diff --git a/contact/migrations/0001_initial.py b/contact/migrations/0001_initial.py new file mode 100644 index 0000000..fde2d6f --- /dev/null +++ b/contact/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 5.1.4 on 2025-02-02 19:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Feedback', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=150, verbose_name='Name')), + ('email', models.EmailField(max_length=150, verbose_name='E-mail')), + ('date', models.DateTimeField(auto_now_add=True, verbose_name='Sended')), + ('subject', models.CharField(max_length=150, verbose_name='Subject')), + ('message', models.TextField(verbose_name='Message')), + ], + ), + ] diff --git a/contact/models.py b/contact/models.py index 71a8362..6f97d55 100644 --- a/contact/models.py +++ b/contact/models.py @@ -1,3 +1,12 @@ from django.db import models -# Create your models here. + +class Feedback(models.Model): + name = models.CharField(max_length=150, verbose_name="Name") + email = models.EmailField(max_length=150, verbose_name="E-mail") + date = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name="Sended") + subject = models.CharField(max_length=150, verbose_name="Subject") + message = models.TextField(verbose_name="Message") + + def __str__(self): + return '{}'.format(self.name) diff --git a/contact/templates/contact/main.html b/contact/templates/contact/main.html index c8e9603..74e7104 100644 --- a/contact/templates/contact/main.html +++ b/contact/templates/contact/main.html @@ -3,7 +3,59 @@ {% block title %} Gallery : Contact {% endblock %} - + {% block content %} - Contact me! + +
{% endblock %} \ No newline at end of file diff --git a/contact/urls.py b/contact/urls.py index cb535ad..51d8b14 100644 --- a/contact/urls.py +++ b/contact/urls.py @@ -5,5 +5,5 @@ from . import views app_name = 'contact' urlpatterns = [ - path('', views.Main.as_view(), name='main_url'), + path('', views.Contact.as_view(), name="contact_url") ] diff --git a/contact/views.py b/contact/views.py index 4f0ac6f..6b9525b 100644 --- a/contact/views.py +++ b/contact/views.py @@ -1,6 +1,25 @@ -from django.shortcuts import render -from django.views.generic import TemplateView +from django.contrib import messages +from django.shortcuts import redirect, render +from django.views.generic.base import View + +from .forms import FeedbackForm +from .models import Feedback -class Main(TemplateView): - template_name = "contact/main.html" +class Contact(View): + + def post(self, request): + form = FeedbackForm(request.POST or None) + if form.is_valid(): + profile = form.save(commit=False) + profile.save() + form.send_email() + messages.success(request, 'Your message was sent successfully! Thank you!') + return redirect('gallery:main_url') + else: + messages.warning(request, 'Error occured while sending message.') + return render(request, 'contact/main.html', {'form': form}) + + def get(self, request): + form = FeedbackForm() + return render(request, 'contact/main.html', {'form': form}) diff --git a/static/img/profile.png b/static/img/profile.png new file mode 100644 index 0000000..0f5b1ff Binary files /dev/null and b/static/img/profile.png differ diff --git a/templates/base_dark.html b/templates/base_dark.html index b9809d2..4b02b28 100644 --- a/templates/base_dark.html +++ b/templates/base_dark.html @@ -37,7 +37,7 @@