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

Migrated Events app to CBV #364

Merged
Merged
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
Migrated Events app to CBV
Migrated function based views in Events app to class based views
  • Loading branch information
amruthasangeeth committed Aug 18, 2016
commit f4bf510c5d0523087839757660508781ab87a4b4
73 changes: 36 additions & 37 deletions vms/event/forms.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
from django import forms
from django.db import models
from django.forms import ModelForm

from event.models import Event


class EventForm(ModelForm):
class Meta:
model = Event
fields = [
'name',
'start_date',
'end_date',
'country',
'state',
'city',
'address',
'venue'
]

def clean(self):

start_date = self.cleaned_data.get('start_date')
end_date = self.cleaned_data.get('end_date')

if start_date and end_date:
if start_date > end_date:
msg = u"Start date must be before the end date"
self._errors['start_date'] = self.error_class([msg])

return self.cleaned_data


class EventDateForm(forms.Form):
start_date = forms.DateField(required=True)
end_date = forms.DateField(required=True)
from django import forms
from django.db import models
from django.forms import ModelForm

from event.models import Event


class EventForm(ModelForm):
class Meta:
model = Event
fields = [
'name',
'start_date',
'end_date',
'country',
'state',
'city',
'address',
'venue'
]

def clean(self):
start_date = self.cleaned_data.get('start_date')
end_date = self.cleaned_data.get('end_date')

if start_date and end_date:
if start_date > end_date:
msg = u"Start date must be before the end date"
self._errors['start_date'] = self.error_class([msg])

return self.cleaned_data


class EventDateForm(forms.Form):
start_date = forms.DateField(required=True)
end_date = forms.DateField(required=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

@amruthasangeeth What has been changed in this file? Nothing, right? Did you run pep8?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tapasweni-pathak No changes are made in this file.

135 changes: 68 additions & 67 deletions vms/event/models.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,68 @@
from django.core.validators import RegexValidator
from django.db import models


class Event(models.Model):
name = models.CharField(
max_length=75,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(0-9)|(\s)|(\.)|(,)|(\-)|(!)|(\')]+$',
),
],
)
start_date = models.DateField()
end_date = models.DateField()

address = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(0-9)|(\s)|(\-)|(\')]+$',
),
],
blank=True,
null=True,
)
city = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(\s)|(\-)|(\')]+$',
),
],
blank=True,
null=True,
)
state = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(\s)|(\-)]+$',
),
],
blank=True,
null=True,
)
country = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(\s)|(\-)|(\')]+$',
),
],
blank=True,
null=True,
)

venue = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(\s)|(\-)|(\')]+$',
),
],
blank=True,
null=True,
)
from django.core.validators import RegexValidator
from django.db import models


class Event(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(
max_length=75,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(0-9)|(\s)|(\.)|(,)|(\-)|(!)|(\')]+$',
),
],
)
start_date = models.DateField()
end_date = models.DateField()

address = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(0-9)|(\s)|(\-)|(\')]+$',
),
],
blank=True,
null=True,
)
city = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(\s)|(\-)|(\')]+$',
),
],
blank=True,
null=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

@amruthasangeeth Are there any changes in this model?
I can spot only the autoincrement one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smarshy Only the id is the new one.

Copy link
Contributor

Choose a reason for hiding this comment

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

@amruthasangeeth Complete file is coming as diff, it is really difficult to review. Can you please undo the unnecessary changes (cleanups, spacing)?

)
state = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(\s)|(\-)]+$',
),
],
blank=True,
null=True,
)
country = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(\s)|(\-)|(\')]+$',
),
],
blank=True,
null=True,
)

venue = models.CharField(
max_length=30,
validators=[
RegexValidator(
r'^[(A-Z)|(a-z)|(\s)|(\-)|(\')]+$',
),
],
blank=True,
null=True,
)
2 changes: 1 addition & 1 deletion vms/event/templates/event/delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block setting_content %}
<div class="spacer"></div>
<form class="form-horizontal" action="{% url 'event:delete' event_id %}" method="post">
<form class="form-horizontal" action="" method="post">
Copy link
Contributor

Choose a reason for hiding this comment

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

@amruthasangeeth Where are we redirecting to delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tapasweni-pathak DeleteView works just like that.

Copy link
Contributor

@tapaswenipathak tapaswenipathak Aug 18, 2016

Choose a reason for hiding this comment

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

@amruthasangeeth Then do we need this form tag ?

{% csrf_token %}
<div class="panel panel-danger">
<div class="panel-heading">
Expand Down
Loading