Skip to content
This repository was archived by the owner on Jul 7, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions ACM_General/events/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

# 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):
"""
This class is used for combining the Event Class model with a form
(ModelForm).
"""

class Meta:
model = Event
exclude = ('id', 'creator', 'date_created')
Expand All @@ -23,5 +24,6 @@ class Meta:
'date_expire': DateTimeInput(attrs={'id': 'calendar'}),
'title': Textarea(attrs={'rows': 3}),
'description': Textarea(attrs={'rows': 3}),
'link': TextInput(),
'link': TextInput(),
'tags': CheckboxSelectMultiple(),
}
47 changes: 47 additions & 0 deletions ACM_General/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,46 @@ def get_path_for_flier(instance, filename):
)


class Tag(models.Model):
"""
Class used for adding classification tags on events.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid using Class here and rephrase this docstring.

"""

#: The name of the tag that is displayed on the event creation form; represented
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not exclusively be what it will be used for. It will be used anytime that we display the Tag. Rephrase to make more generic.

#: as a CharField.
display_name = models.CharField(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have unique=True, we don't want two tags have the same display name

verbose_name=_('Event Tag'),
help_text=_('Different categories for the event.'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This help text is not really descriptive as to what it does. Should be something along the lines of The name of the Tag that will be displayed to users

max_length=256,
)

#: Unique id of the tag; represented as an IntegerField.
id = models.IntegerField(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was thinking for this id was another CharField which has an unchanging name that the creator of this Tag creates. This makes things look better from the API perspective when requesting event data.

verbose_name=_('ID'),
help_text=_('Unique ID of the tag.'),
primary_key=True,
)

#: If the tag should be diplayed on the event creation form; represented as a
#: BooleanField.
display = models.BooleanField(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I necessarily agree with the name of this being display. The concept behind this was that if this field is true, the user can no longer add this tag to the event nor can it be seen on events that have already used this tag. This first part of this can be solved with https://stackoverflow.com/questions/3010489/how-do-i-filter-values-in-a-django-form-using-modelform#3013509 and a custom function on this model which is something like is_enabled(). I believe the name should be something like is_disabled. What do you think?

verbose_name=_('Display'),
help_text=_('Whether or not the tag is to be displayed on the event creation form.'),
default = True,
)


def __str__(self):
"""
Changes what is displayed for each tag on the event creation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that you necessarily need to put this description on this function. The __str__ attribute is a Python standard attribute which returns this object whenever str() is called on it. Moreover, these descriptions should avoid addressing django-specific projects and be specific to the function or return itself.

form (without this it shows 'Tag object (id)').

:return: String containing the name of the tag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be :returns:. Also, The text should probably be "The display name of the tag". You don't need to mention the type because it is stated in the statement below.

Copy link
Author

@dmgardiner25 dmgardiner25 Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other two functions just say :return: as well so I'll go ahead and change those too.

:rtype: string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No period, should be str.

"""
return self.display_name


class Event(models.Model):
"""
Class used to define what is needed when creating new events.
Expand Down Expand Up @@ -154,6 +194,13 @@ 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=_('Different categories for classifying the event.'),
)

@property
def is_active(self):
"""
Expand Down
6 changes: 4 additions & 2 deletions ACM_General/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down