-
Notifications
You must be signed in to change notification settings - Fork 4
Migrated Events app to CBV #364
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Migrated function based views in Events app to class based views
- Loading branch information
There are no files selected for viewing
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) | ||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amruthasangeeth Are there any changes in this model? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smarshy Only the id is the new one. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amruthasangeeth Where are we redirecting to delete? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tapasweni-pathak DeleteView works just like that. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"> | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.