From 5359b42f3b30daa2b37c11727335ff4223f88233 Mon Sep 17 00:00:00 2001 From: Aaditya_singh <68394997+Aaditya-Singh78@users.noreply.github.com> Date: Sun, 31 Mar 2024 01:07:08 +0530 Subject: [PATCH 1/3] feat - model and form to add exhibitors --- users/forms.py | 14 +++++++++-- users/migrations/0004_exhibitor.py | 24 +++++++++++++++++++ users/models.py | 18 +++++++++++++++ users/tests.py | 37 ++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 users/migrations/0004_exhibitor.py diff --git a/users/forms.py b/users/forms.py index 46b08906ad..111cceab0b 100644 --- a/users/forms.py +++ b/users/forms.py @@ -1,6 +1,6 @@ from django.contrib.auth.forms import UserChangeForm, UserCreationForm - -from .models import CustomUser +from django.forms import ModelForm +from .models import CustomUser, Exhibitor class CustomUserCreationForm(UserCreationForm): @@ -13,3 +13,13 @@ class CustomUserChangeForm(UserChangeForm): class Meta: model = CustomUser fields = UserChangeForm.Meta.fields + +class ExhibitorCreationForm(ModelForm): + class Meta: + model = Exhibitor + fields = ['description', 'website'] + +class ExhibitorChangeForm(ModelForm): + class Meta: + model = Exhibitor + fields = ['description', 'website'] \ No newline at end of file diff --git a/users/migrations/0004_exhibitor.py b/users/migrations/0004_exhibitor.py new file mode 100644 index 0000000000..060ed717e9 --- /dev/null +++ b/users/migrations/0004_exhibitor.py @@ -0,0 +1,24 @@ +# Generated by Django 5.0 on 2024-03-30 19:30 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0003_customuser_avatar_url_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='Exhibitor', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('description', models.TextField(blank=True, null=True)), + ('website', models.URLField()), + ('username', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='exhibitors', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/users/models.py b/users/models.py index 34f23de308..c6af211c57 100644 --- a/users/models.py +++ b/users/models.py @@ -46,3 +46,21 @@ class CustomUser(AbstractUser): company = models.CharField(null=True, blank=True, max_length=200) rocket_chat_token = models.CharField(null=True, blank=True, max_length=200) + +class Exhibitor(models.Model): + username = models.OneToOneField(CustomUser, on_delete =models.CASCADE, related_name = 'exhibitors', null=False, blank = False) + description = models.TextField(null = True, blank = True) + website = models.URLField(null=False, blank = False) + + def verify(self): + return self.username.is_verified + + def update_exhibtor(self,description=None, website = None): + if description is not None: + self.description = description + if website is not None: + self.website = website + self.save() + + def __str__(self) -> str: + return self.username.username or "Exhibtors" diff --git a/users/tests.py b/users/tests.py index e55d689097..13c3007c42 100644 --- a/users/tests.py +++ b/users/tests.py @@ -1,3 +1,40 @@ from django.test import TestCase # noqa: F401 # Create your tests here. +from .models import Exhibitor, CustomUser +from .forms import ExhibitorCreationForm, ExhibitorChangeForm + +class ExhibitorTestCase(TestCase): + def setUp(self): + self.user = CustomUser.objects.create(username="test_user") + self.exhibitor = Exhibitor.objects.create( + username=self.user, + description="Test Description", + website="http://example.com" + ) + + def test_exhibitor_creation(self): + self.assertEqual(self.exhibitor.username, self.user) + self.assertEqual(self.exhibitor.description, "Test Description") + self.assertEqual(self.exhibitor.website, "http://example.com") + +class ExhibitorFormTestCase(TestCase): + def test_valid_creation_form(self): + form_data = {'username': 'test_user', 'description': 'Test Description', 'website': 'http://example.com'} + form = ExhibitorCreationForm(data=form_data) + self.assertTrue(form.is_valid()) + + def test_invalid_creation_form(self): + form_data = {'username': 'test_user', 'description': '', 'website': 'invalid-url'} + form = ExhibitorCreationForm(data=form_data) + self.assertFalse(form.is_valid()) + + def test_valid_change_form(self): + form_data = {'description': 'New Description', 'website': 'http://new-example.com'} + form = ExhibitorChangeForm(data=form_data) + self.assertTrue(form.is_valid()) + + def test_invalid_change_form(self): + form_data = {'description': '', 'website': 'invalid-url'} + form = ExhibitorChangeForm(data=form_data) + self.assertFalse(form.is_valid()) \ No newline at end of file From fd33a7199800eabaa6546514b0f8d0dfbfa4d754 Mon Sep 17 00:00:00 2001 From: Aaditya_singh <68394997+Aaditya-Singh78@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:39:51 +0530 Subject: [PATCH 2/3] added mail support feature --- open_event_api/models.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 open_event_api/models.py diff --git a/open_event_api/models.py b/open_event_api/models.py new file mode 100644 index 0000000000..3381973727 --- /dev/null +++ b/open_event_api/models.py @@ -0,0 +1,14 @@ +from django.db import models +# imported fields from #9123 where event tickets & discount codes are created. +from events.models import Event +from tickets.models import Ticket + +class MailingList(models.Model): + email = models.EmailField(unique=True, blank=False, null=False) + subscribed_at = models.DateTimeField(auto_now_add=True) + + def __str__(self): + if self.email: + return self.email + else: + return "No email specified" From 614c80e5ae344a75b7023a29ded3f34cb8173fa7 Mon Sep 17 00:00:00 2001 From: Aaditya_singh <68394997+Aaditya-Singh78@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:42:29 +0530 Subject: [PATCH 3/3] fixed imports for mailingList --- open_event_api/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/open_event_api/models.py b/open_event_api/models.py index 3381973727..20a746fc24 100644 --- a/open_event_api/models.py +++ b/open_event_api/models.py @@ -1,7 +1,4 @@ from django.db import models -# imported fields from #9123 where event tickets & discount codes are created. -from events.models import Event -from tickets.models import Ticket class MailingList(models.Model): email = models.EmailField(unique=True, blank=False, null=False) @@ -12,3 +9,4 @@ def __str__(self): return self.email else: return "No email specified" +