Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Added start time and an end time in Meetup. #523

Open
wants to merge 4 commits into
base: develop
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
2 changes: 1 addition & 1 deletion systers_portal/common/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_login_logout(self):
# Log in the user
self.client.login(username=u.username, password=u.password)
# Check response code for logout
response = self.client.get(reverse('logout'))
response = self.client.get(reverse('account_logout'))
self.assertEqual(response.status_code, 302)
# Log out the user
self.client.logout()
50 changes: 25 additions & 25 deletions systers_portal/meetup/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class RequestMeetupForm(ModelFormWithHelper):
""" Form to create a new Meetup Request. """
class Meta:
model = RequestMeetup
fields = ('title', 'slug', 'date', 'time', 'venue', 'description')
fields = ('title', 'slug', 'date', 'start_time', 'end_time', 'venue', 'description')
widgets = {'date': forms.DateInput(attrs={'type': 'text', 'class': 'datepicker'}),
'time': forms.TimeInput(attrs={'type': 'text', 'class': 'timepicker'})}
'start_time': forms.TimeInput(attrs={'type': 'text', 'class': 'timepicker'}),
'end_time': forms.TimeInput(attrs={'type': 'text', 'class': 'timepicker'})}
helper_class = SubmitCancelFormHelper
helper_cancel_href = "{% url 'about_meetup_location' meetup_location.slug %}"

Expand Down Expand Up @@ -70,16 +71,14 @@ def clean_date(self):
code="date_in_past")
return date

def clean_time(self):
"""Check that if the date is the current date, the time is not the current time. If so,
raise an error."""
time = self.cleaned_data.get('time')
date = self.cleaned_data.get('date')
if time:
if date == timezone.now().date() and time < timezone.now().time():
raise forms.ValidationError("Time should not be a time that has already passed.",
code="time_in_past")
return time
def clean_end_time(self):
"""Check that if start time is less than end time."""
start_time = self.cleaned_data.get('start_time')
end_time = self.cleaned_data.get('end_time')

if end_time < start_time:
raise forms.ValidationError("End time should not be less than Start Time.")
return end_time


class AddMeetupForm(ModelFormWithHelper):
Expand All @@ -91,9 +90,11 @@ class AddMeetupForm(ModelFormWithHelper):
"""
class Meta:
model = Meetup
fields = ('title', 'slug', 'date', 'time', 'venue', 'description', 'meetup_picture')
fields = ('title', 'slug', 'date', 'start_time', 'end_time', 'venue', 'description',
'meetup_picture')
widgets = {'date': forms.DateInput(attrs={'type': 'text', 'class': 'datepicker'}),
'time': forms.TimeInput(attrs={'type': 'text', 'class': 'timepicker'})}
'start_time': forms.TimeInput(attrs={'type': 'text', 'class': 'timepicker'}),
'end_time': forms.TimeInput(attrs={'type': 'text', 'class': 'timepicker'})}
helper_class = SubmitCancelFormHelper
helper_cancel_href = "{% url 'about_meetup_location' meetup_location.slug %}"

Expand Down Expand Up @@ -121,24 +122,23 @@ def clean_date(self):
raise forms.ValidationError("Date should not be before today's date.")
return date

def clean_time(self):
"""Check that if the date is the current date, the time is not the current time. If so,
raise an error."""
time = self.cleaned_data.get('time')
date = self.cleaned_data.get('date')
if time:
if date == timezone.now().date() and time < timezone.now().time():
raise forms.ValidationError("Time should not be a time that has already passed.")
return time
def clean_end_time(self):
"""Check that if start time is less than end time."""
start_time = self.cleaned_data.get('start_time')
end_time = self.cleaned_data.get('end_time')
if end_time < start_time:
raise forms.ValidationError("End time should not be less than Start Time.")
return end_time


class EditMeetupForm(ModelFormWithHelper):
"""Form to edit Meetup"""
class Meta:
model = Meetup
fields = ('title', 'slug', 'date', 'time', 'description', 'venue')
fields = ('title', 'slug', 'date', 'start_time', 'end_time', 'description', 'venue')
widgets = {'date': forms.DateInput(attrs={'type': 'date', 'class': 'datepicker'}),
'time': forms.TimeInput(attrs={'type': 'time', 'class': 'timepicker'})}
'start_time': forms.TimeInput(attrs={'type': 'time', 'class': 'timepicker'}),
'end_time': forms.TimeInput(attrs={'type': 'time', 'class': 'timepicker'})}
helper_class = SubmitCancelFormHelper
helper_cancel_href = "{% url 'view_meetup' meetup_location.slug meetup.slug %}"

Expand Down
20 changes: 20 additions & 0 deletions systers_portal/meetup/migrations/0003_meetup_start_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-04-16 06:44
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('meetup', '0002_meetup_meetup_picture'),
]

operations = [
migrations.AddField(
model_name='meetup',
name='start_time',
field=models.TimeField(null=True, verbose_name=b'Start Time'),
),
]
33 changes: 33 additions & 0 deletions systers_portal/meetup/migrations/0004_auto_20200512_1414.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-05-12 14:14
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('meetup', '0003_meetup_start_time'),
]

operations = [
migrations.RemoveField(
model_name='meetup',
name='time',
),
migrations.RemoveField(
model_name='requestmeetup',
name='time',
),
migrations.AddField(
model_name='requestmeetup',
name='end_time',
field=models.TimeField(null=True, verbose_name=b'End Time'),
),
migrations.AddField(
model_name='requestmeetup',
name='start_time',
field=models.TimeField(null=True, verbose_name=b'Start Time'),
),
]
5 changes: 3 additions & 2 deletions systers_portal/meetup/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Meetup(models.Model):
slug = models.SlugField(max_length=50, unique=True, verbose_name="Slug")
date = models.DateField(verbose_name="Date")
end_date = models.DateField(verbose_name="End Date", null=True)
time = models.TimeField(verbose_name="Time", blank=True)
start_time = models.TimeField(verbose_name="Start Time", null=True)
end_time = models.TimeField(verbose_name="End Time", null=True)
venue = models.CharField(max_length=512, verbose_name="Venue", blank=True)
description = models.TextField(verbose_name="Description")
Expand All @@ -114,7 +114,8 @@ class RequestMeetup(models.Model):
title = models.CharField(max_length=50, verbose_name="Title",)
slug = models.SlugField(max_length=50, unique=True, verbose_name="Slug")
date = models.DateField(verbose_name="Date")
time = models.TimeField(verbose_name="Time", blank=True)
start_time = models.TimeField(verbose_name="Start Time", null=True)
end_time = models.TimeField(verbose_name="End Time", null=True)
venue = models.CharField(max_length=512, verbose_name="Venue", blank=True)
description = RichTextField(verbose_name="Description")
meetup_location = models.ForeignKey(MeetupLocation, verbose_name="Meetup Location")
Expand Down
79 changes: 44 additions & 35 deletions systers_portal/meetup/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.utils.timezone import timedelta
from cities_light.models import City, Country
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.core import mail

from meetup.forms import (AddMeetupForm, EditMeetupForm, AddMeetupLocationMemberForm,
Expand Down Expand Up @@ -34,7 +33,9 @@ def setUp(self):

self.meetup = Meetup.objects.create(title='Foo Bar Baz', slug='foobarbaz',
date=timezone.now().date(),
time=timezone.now().time(),
start_time=timezone.now().time(),
end_time=(timezone.now() + timedelta(minutes=30)).
time(),
description='This is test Meetup',
meetup_location=self.meetup_location,
created_by=self.systers_user,
Expand Down Expand Up @@ -68,9 +69,10 @@ def test_add_request_meetup_form(self):
self.assertFalse(form.is_valid())

date = (timezone.now() + timedelta(2)).date()
time = timezone.now().time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'time': time,
'description': "It's a test meetup."}
start_time = timezone.now().time()
end_time = (timezone.now() + timedelta(minutes=30)).time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'start_time': start_time,
'end_time': end_time, 'description': "It's a test meetup."}
form = RequestMeetupForm(data=data, created_by=self.user,
meetup_location=self.meetup_location)
self.assertTrue(form.is_valid())
Expand All @@ -84,28 +86,29 @@ def test_add_request_meetup_form(self):
self.assertIn('New Meetup Request', mail.outbox[0].subject)

def test_request_meetup_form_with_past_date(self):
"""Test add Meetup form with a date that has passed."""
"""Test add Request Meetup form with a date that has passed."""
date = (timezone.now() - timedelta(2)).date()
time = timezone.now().time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'time': time,
'description': "It's a test meetup."}
form = AddMeetupForm(data=data, created_by=self.systers_user,
meetup_location=self.meetup_location)
start_time = timezone.now().time()
end_time = (timezone.now() + timedelta(minutes=30)).time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'start_time': start_time,
'end_time': end_time, 'description': "It's a test meetup."}
form = RequestMeetupForm(data=data, created_by=self.systers_user,
meetup_location=self.meetup_location)
self.assertFalse(form.is_valid())
self.assertTrue(form.errors['date'], ["Date should not be before today's date."])

def test_request_meetup_form_with_passed_time(self):
"""Test add Meetup form with a time that has passed."""
def test_request_meetup_form_with_start_time_less_than_end_time(self):
"""Test add Request Meetup form with end time is less than start time"""
date = timezone.now().date()
time = (timezone.now() - timedelta(2)).time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'time': time,
'description': "It's a test meetup."}
form = AddMeetupForm(data=data, created_by=self.systers_user,
meetup_location=self.meetup_location)
start_time = timezone.now().time()
end_time = (timezone.now() - timedelta(minutes=30)).time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'start_time': start_time,
'end_time': end_time, 'description': "It's a test meetup."}
form = RequestMeetupForm(data=data, created_by=self.systers_user,
meetup_location=self.meetup_location)
self.assertFalse(form.is_valid())
self.assertTrue(form.errors['time'],
["Time should not be a time that has already passed."])
self.assertRaises(ValidationError, form.clean_time())
self.assertTrue(form.errors['end_time'],
["End time should not be less than Start Time."])


class AddMeetupFormTestCase(MeetupFormTestCaseBase, TestCase):
Expand All @@ -125,8 +128,10 @@ def test_add_meetup_form(self):
self.assertFalse(form.is_valid())

date = (timezone.now() + timedelta(2)).date()
time = timezone.now().time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'time': time,
start_time = timezone.now().time()
end_time = (timezone.now() + timedelta(minutes=30)).time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date,
'start_time': start_time, 'end_time': end_time,
'description': "It's a test meetup."}
form = AddMeetupForm(data=data, created_by=self.user,
meetup_location=self.meetup_location)
Expand All @@ -145,25 +150,27 @@ def test_add_meetup_form(self):
def test_add_meetup_form_with_past_date(self):
"""Test add Meetup form with a date that has passed."""
date = (timezone.now() - timedelta(2)).date()
time = timezone.now().time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'time': time,
'description': "It's a test meetup."}
start_time = timezone.now().time()
end_time = (timezone.now() + timedelta(minutes=30)).time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'start_time': start_time,
'end_time': end_time, 'description': "It's a test meetup."}
form = AddMeetupForm(data=data, created_by=self.systers_user,
meetup_location=self.meetup_location)
self.assertFalse(form.is_valid())
self.assertTrue(form.errors['date'], ["Date should not be before today's date."])

def test_add_meetup_form_with_passed_time(self):
"""Test add Meetup form with a time that has passed."""
def test_request_meetup_form_with_start_time_less_than_end_time(self):
"""Test add Meetup form with end time is less than start time"""
date = timezone.now().date()
time = (timezone.now() - timedelta(2)).time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'time': time,
'description': "It's a test meetup."}
start_time = timezone.now().time()
end_time = (timezone.now() - timedelta(minutes=30)).time()
data = {'title': 'Foo', 'slug': 'foo', 'date': date, 'start_time': start_time,
'end_time': end_time, 'description': "It's a test meetup."}
form = AddMeetupForm(data=data, created_by=self.systers_user,
meetup_location=self.meetup_location)
self.assertFalse(form.is_valid())
self.assertTrue(form.errors['time'],
["Time should not be a time that has already passed."])
self.assertTrue(form.errors['end_time'],
["End time should not be less than Start Time."])


class EditMeetupFormTestCase(MeetupFormTestCaseBase, TestCase):
Expand All @@ -174,9 +181,11 @@ def test_edit_meetup_form(self):
self.assertFalse(form.is_valid())

date = (timezone.now() + timedelta(2)).date()
time = timezone.now().time()
start_time = timezone.now().time()
end_time = (timezone.now() - timedelta(minutes=30)).time()

data = {'slug': 'foobar', 'title': 'Foo Bar', 'date': date, 'time': time,
data = {'slug': 'foobar', 'title': 'Foo Bar', 'date': date,
'start_time': start_time, 'end_time': end_time,
'description': "It's a test meetup.", 'venue': 'test address'}
form = EditMeetupForm(instance=self.meetup, data=data)
self.assertTrue(form.is_valid())
Expand Down
27 changes: 18 additions & 9 deletions systers_portal/meetup/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.auth.models import User
from django.test import TestCase
from django.utils import timezone
from django.utils.timezone import timedelta
from cities_light.models import City, Country

from meetup.models import (Meetup, MeetupLocation, Rsvp, SupportRequest, RequestMeetupLocation,
Expand Down Expand Up @@ -40,8 +41,10 @@ class MeetupTestCase(MeetupBaseTestCase, TestCase):
def setUp(self):
super(MeetupTestCase, self).setUp()
self.meetup = Meetup.objects.create(title="Test Meetup", slug="baz",
date=timezone.now().date(), time=timezone.now().time(),
venue="FooBar colony",
date=timezone.now().date(), start_time=timezone.now().
time(),
end_time=(timezone.now() + timedelta(minutes=30)).
time(), venue="FooBar colony",
description="This is a testing meetup.",
meetup_location=self.meetup_location,
created_by=self.systers_user)
Expand All @@ -56,8 +59,10 @@ def setUp(self):
super(RequestMeetupTestCase, self).setUp()
self.meetup_request = \
RequestMeetup.objects.create(title="Test Meetup Request", slug="baz",
date=timezone.now().date(), time=timezone.now().time(),
venue="FooBar colony",
date=timezone.now().date(), start_time=timezone.now().
time(),
end_time=(timezone.now() + timedelta(minutes=30)).
time(), venue="FooBar colony",
description="This is a testing meetup request.",
meetup_location=self.meetup_location,
created_by=self.systers_user)
Expand All @@ -68,16 +73,18 @@ def test_str(self):

def test_get_verbose_fields(self):
fields = self.meetup_request.get_verbose_fields()
self.assertEqual(len(fields), 12)
self.assertEqual(len(fields), 13)
self.assertTrue(fields[1], ('Title', 'Test Meetup Request'))


class RsvpTestCase(MeetupBaseTestCase, TestCase):
def setUp(self):
super(RsvpTestCase, self).setUp()
self.meetup = Meetup.objects.create(title="Test Meetup", slug="baz",
date=timezone.now().date(), time=timezone.now().time(),
venue="FooBar colony",
date=timezone.now().date(), start_time=timezone.now().
time(),
end_time=(timezone.now() + timedelta(minutes=30)).
time(), venue="FooBar colony",
description="This is a testing meetup.",
meetup_location=self.meetup_location,
created_by=self.systers_user)
Expand All @@ -91,8 +98,10 @@ class SupportRequestTestCase(MeetupBaseTestCase, TestCase):
def setUp(self):
super(SupportRequestTestCase, self).setUp()
self.meetup = Meetup.objects.create(title="Test Meetup", slug="baz",
date=timezone.now().date(), time=timezone.now().time(),
venue="FooBar colony",
date=timezone.now().date(), start_time=timezone.now().
time(),
end_time=(timezone.now() + timedelta(minutes=30)).
time(), venue="FooBar colony",
description="This is a testing meetup.",
meetup_location=self.meetup_location,
created_by=self.systers_user)
Expand Down
Loading