diff --git a/open_event_api/models.py b/open_event_api/models.py new file mode 100644 index 0000000000..20a746fc24 --- /dev/null +++ b/open_event_api/models.py @@ -0,0 +1,12 @@ +from django.db import models + +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" + 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