diff --git a/ACM_General/events/forms.py b/ACM_General/events/forms.py index 312928a..6220e6e 100755 --- a/ACM_General/events/forms.py +++ b/ACM_General/events/forms.py @@ -4,10 +4,10 @@ # Django from django.forms import ModelForm -from django.forms.widgets import DateTimeInput, Textarea, TextInput +from django.forms.widgets import DateTimeInput, Textarea, TextInput, CheckboxSelectMultiple # local Django -from .models import Event +from .models import Event, Tag class EventForm(ModelForm): @@ -15,6 +15,7 @@ class EventForm(ModelForm): This class is used for combining the Event Class model with a form (ModelForm). """ + class Meta: model = Event exclude = ('id', 'creator', 'date_created') @@ -24,4 +25,8 @@ class Meta: 'title': Textarea(attrs={'rows': 3}), 'description': Textarea(attrs={'rows': 3}), 'link': TextInput(), + 'tags': CheckboxSelectMultiple(), } + def __init__(self, *args, **kwargs): + super(EventForm, self).__init__(*args, **kwargs) + self.fields['tags'].queryset = Tag.objects.filter(is_disabled=False) diff --git a/ACM_General/events/migrations/0002_auto_20180330_0722.py b/ACM_General/events/migrations/0002_auto_20180330_0722.py new file mode 100644 index 0000000..dcbf1a7 --- /dev/null +++ b/ACM_General/events/migrations/0002_auto_20180330_0722.py @@ -0,0 +1,26 @@ +# Generated by Django 2.0.3 on 2018-03-30 07:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Tag', + fields=[ + ('display_name', models.CharField(help_text='The name of the tag that will be displayed to users.', max_length=256, unique=True, verbose_name='Event Tag')), + ('id', models.CharField(help_text='Unique ID of the tag.', max_length=256, primary_key=True, serialize=False, verbose_name='ID')), + ('is_disabled', models.BooleanField(default=True, help_text='Whether or not the tag is to be displayed.', verbose_name='Display')), + ], + ), + migrations.AddField( + model_name='event', + name='tags', + field=models.ManyToManyField(help_text='The name of the Tag that will be displayed to users', to='events.Tag', verbose_name='Event Tags'), + ), + ] diff --git a/ACM_General/events/migrations/0003_auto_20180408_0410.py b/ACM_General/events/migrations/0003_auto_20180408_0410.py new file mode 100644 index 0000000..39cdc67 --- /dev/null +++ b/ACM_General/events/migrations/0003_auto_20180408_0410.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.3 on 2018-04-08 04:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0002_auto_20180330_0722'), + ] + + operations = [ + migrations.AlterField( + model_name='event', + name='tags', + field=models.ManyToManyField(blank=True, help_text='The name of the Tag that will be displayed to users', to='events.Tag', verbose_name='Event Tags'), + ), + ] diff --git a/ACM_General/events/models.py b/ACM_General/events/models.py index f99b1f7..c0d6f06 100644 --- a/ACM_General/events/models.py +++ b/ACM_General/events/models.py @@ -47,6 +47,42 @@ def get_path_for_flier(instance, filename): ) +class Tag(models.Model): + """ + Model used for adding tags on events. + """ + + #: The name of the tag that is displayed; represented as a CharField. + display_name = models.CharField( + verbose_name=_('Event Tag'), + help_text=_('The name of the tag that will be displayed to users.'), + unique=True, + max_length=256, + ) + + #: Unique id of the tag; represented as an CharField. + id = models.CharField( + verbose_name=_('ID'), + help_text=_('Unique ID of the tag.'), + primary_key=True, + max_length=256, + ) + + #: If the tag should be diplayed; represented as a BooleanField. + is_disabled = models.BooleanField( + verbose_name=_('Display'), + help_text=_('Whether or not the tag is to be displayed.'), + default = True, + ) + + def __str__(self): + """ + :returns: Display the name of the tag. + :rtype: str + """ + return self.display_name + + class Event(models.Model): """ Class used to define what is needed when creating new events. @@ -154,13 +190,21 @@ class Event(models.Model): blank=True, ) + #: Tags available to attach to events; represented as a ManyToManyField. + tags = models.ManyToManyField( + Tag, + verbose_name=_('Event Tags'), + help_text=_('The name of the Tag that will be displayed to users'), + blank=True, + ) + @property def is_active(self): """ Checking whether or not an event has already expired (gone past the current date). - :return: Bool value representing whether or not the event is + :returns: Bool value representing whether or not the event is considered 'active'. :rtype: bool """ @@ -171,7 +215,7 @@ def clean(self): The clean function is used for making checks on the data posted to the form. - :return: None. + :returns: None. :rtype: None :raises ValidationError: if date_expire or date_hosted are invalid. diff --git a/ACM_General/events/static/events/css/create-event.css b/ACM_General/events/static/events/css/create-event.css index fedd40d..d5513cc 100644 --- a/ACM_General/events/static/events/css/create-event.css +++ b/ACM_General/events/static/events/css/create-event.css @@ -17,6 +17,12 @@ a { color: white; } +ul { + list-style-type: none; + margin: 0; + padding: 0; +} + input, textarea, option { font-size: 15px; } diff --git a/ACM_General/events/views.py b/ACM_General/events/views.py index abf3767..093da07 100755 --- a/ACM_General/events/views.py +++ b/ACM_General/events/views.py @@ -48,8 +48,9 @@ def create_event(request): - If the user is submitting a GET request, it will send them to the blank create event page. - If the user is submitting a POST request: - - If the form is valid, it will save the event to the database and - redirect the user to the homepage. + - If the form is valid, it will save the event as well as the + ManyToMany relation to the database and redirect the user to the + homepage. - If the form is invalid, the user will be redirected back to the same create event page with same information that they filled out, but also with information that now explains the errors that @@ -74,6 +75,7 @@ def create_event(request): event = form.save(commit=False) event.creator = request.user event.save() + form.save_m2m() return HttpResponseRedirect("/") return render(request, 'events/create-event.html', {'form': form})