first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 22:27:56 +03:00
commit d9f1ea341e
1021 changed files with 70645 additions and 0 deletions

0
contact/__init__.py Normal file
View File

11
contact/admin.py Normal file
View File

@@ -0,0 +1,11 @@
from django.contrib import admin
from .models import Contact
# Register your models here.
class ContactAdmin(admin.ModelAdmin):
list_display = ('name', 'email', 'subject', 'created_at')
list_filter = ('created_at',)
search_fields = ('name', 'email', 'subject', 'message')
readonly_fields = ('created_at', 'updated_at')
admin.site.register(Contact, ContactAdmin)

5
contact/apps.py Normal file
View File

@@ -0,0 +1,5 @@
from django.apps import AppConfig
class ContactConfig(AppConfig):
name = 'contact'

View File

@@ -0,0 +1,32 @@
# Generated by Django 6.0 on 2026-01-15 11:59
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Contact',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=254, verbose_name='Ad Soyad ')),
('email', models.CharField(max_length=254, verbose_name='Eposta Adresi ')),
('subject', models.CharField(max_length=254, verbose_name='Konu ')),
('message', models.CharField(max_length=254, verbose_name='Mesaj ')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Oluşturulma Tarihi')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Güncelleme Tarihi')),
],
options={
'verbose_name': 'Contact',
'verbose_name_plural': 'Contact',
'db_table': 'contacts',
'ordering': ['created_at'],
},
),
]

View File

@@ -0,0 +1,22 @@
# Generated by Django 6.0 on 2026-01-15 12:39
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('contact', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AddField(
model_name='contact',
name='user',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Kullanıcı'),
preserve_default=False,
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 6.0 on 2026-01-15 12:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('contact', '0002_contact_user'),
]
operations = [
migrations.AlterField(
model_name='contact',
name='message',
field=models.TextField(verbose_name='Mesaj '),
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 6.0 on 2026-01-15 13:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('contact', '0003_alter_contact_message'),
]
operations = [
migrations.AddField(
model_name='contact',
name='ip',
field=models.CharField(default=123, max_length=100, verbose_name='IP Adresi '),
preserve_default=False,
),
]

View File

@@ -0,0 +1,26 @@
# Generated by Django 6.0 on 2026-01-15 13:36
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('contact', '0004_contact_ip'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AlterField(
model_name='contact',
name='ip',
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='IP Adresi '),
),
migrations.AlterField(
model_name='contact',
name='user',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='Kullanıcı'),
),
]

View File

22
contact/models.py Normal file
View File

@@ -0,0 +1,22 @@
from django.db import models
# Create your models here.
class Contact(models.Model):
user = models.ForeignKey('accounts.CustomUser', on_delete=models.SET_NULL, null=True, blank=True, verbose_name="Kullanıcı")
name = models.CharField(max_length=254, verbose_name="Ad Soyad ")
email = models.CharField(max_length=254, verbose_name="Eposta Adresi ")
ip = models.CharField(max_length=100, verbose_name="IP Adresi ", blank=True, null=True)
subject = models.CharField(max_length=254, verbose_name="Konu ")
message = models.TextField(verbose_name="Mesaj ")
created_at = models.DateTimeField(auto_now_add=True, editable=False, verbose_name="Oluşturulma Tarihi")
updated_at = models.DateTimeField(auto_now=True, editable=False, verbose_name="Güncelleme Tarihi")
class Meta:
ordering = ["created_at"]
db_table = 'contacts'
verbose_name_plural = "Contact"
verbose_name = "Contact"
def __str__(self):
return f"Contact: {self.name}"

10
contact/serializers.py Normal file
View File

@@ -0,0 +1,10 @@
from rest_framework import serializers
from contact.models import Contact
class ContactSerializer(serializers.ModelSerializer):
class Meta:
model = Contact
fields = ['id', 'name', 'email', 'subject', 'message', 'created_at']
read_only_fields = ['id', 'created_at']

40
contact/tasks.py Normal file
View File

@@ -0,0 +1,40 @@
from celery import shared_task
from django.core.mail import send_mail
from django.conf import settings
@shared_task
def send_contact_email(name, email, subject, message, ip=None):
"""
Contact formundan gelen mesajı email ile gönderir
"""
email_subject = f"Yeni İletişim Mesajı: {subject}"
email_message = f"""
Yeni bir iletişim mesajı alındı!
Gönderen: {name}
Email: {email}
IP Adresi: {ip or 'Belirtilmemiş'}
Konu: {subject}
Mesaj:
{message}
---
Bu mesaj otomatik olarak gönderilmiştir.
"""
try:
send_mail(
subject=email_subject,
message=email_message,
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=['info@denizogur.com.tr'], # Mesajların gönderileceği email adresi
fail_silently=False,
)
return f"Email başarıyla gönderildi: {email}"
except Exception as e:
return f"Email gönderilemedi: {str(e)}"

3
contact/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

7
contact/urls.py Normal file
View File

@@ -0,0 +1,7 @@
from django.urls import path
from contact.views import ContactCreate
urlpatterns = [
path('contact/create/', ContactCreate.as_view(), name='contact.create'),
]

42
contact/views.py Normal file
View File

@@ -0,0 +1,42 @@
from rest_framework.generics import CreateAPIView
from rest_framework.permissions import AllowAny
from contact.models import Contact
from contact.serializers import ContactSerializer
from contact.tasks import send_contact_email
# Create your views here.
class ContactCreate(CreateAPIView):
queryset = Contact.objects.all()
serializer_class = ContactSerializer
permission_classes = [AllowAny] # Herkes contact gönderebilir
def get_client_ip(self, request):
"""İstemcinin IP adresini al"""
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
return ip
def perform_create(self, serializer):
# IP adresini al
ip_address = self.get_client_ip(self.request)
# Kullanıcı varsa kaydet, yoksa None olarak kaydet
user = self.request.user if self.request.user.is_authenticated else None
# Contact'ı kaydet
contact = serializer.save(user=user, ip=ip_address)
# Celery task ile email gönder (arka planda)
send_contact_email.delay(
name=contact.name,
email=contact.email,
subject=contact.subject,
message=contact.message,
ip=ip_address
)