Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] - Added model and form to add exhibitors #9135

Open
wants to merge 1 commit into
base: dev-v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions users/forms.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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']
24 changes: 24 additions & 0 deletions users/migrations/0004_exhibitor.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
18 changes: 18 additions & 0 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
37 changes: 37 additions & 0 deletions users/tests.py
Original file line number Diff line number Diff line change
@@ -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())