Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates events page. #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion events/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from .models import Event, EventParticipant
from .models import Event, EventParticipant, requestEvent

admin.site.register(Event)
admin.site.register(EventParticipant)
admin.site.register(requestEvent)
7 changes: 6 additions & 1 deletion events/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.forms import ModelForm
from .models import EventParticipant
from .models import EventParticipant, requestEvent


class ParticipantForm(ModelForm):
class Meta:
model = EventParticipant
fields = ['title', 'student_name',
'email_id', 'mobile_number', 'roll_no', 'branch']

class requestEventForm(ModelForm):
Copy link
Member

Choose a reason for hiding this comment

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

Issues here :

  • You're not following PEP8 conventions here.
  • According to PEP8 there should be 2 blank lines after a class.
  • Whenever you create class, it should be in caps. eg. class RequestEventForm(ModelForm)
  • Also try to include docstrings in your class/methods.

class Meta:
model = requestEvent
fields = ['title', 'description', 'your_name','roll_no' ,'contact']
10 changes: 10 additions & 0 deletions events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ class EventParticipant(TimeStampedModel):

def __str__(self):
return self.student_name

class requestEvent(models.Model):
Copy link
Member

Choose a reason for hiding this comment

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

  • Here also, In classes, you should follow CamelCase notation.
  • Try to add docstrings to explain what the class/method is doing.
  • You can also add docstrings for existing classes/methods.

title = models.CharField(max_length=50, blank=False)
description = models.TextField(blank=False)
your_name = models.CharField(max_length=50, blank=False)
roll_no = models.CharField(max_length=15, blank=False)
contact = models.CharField(max_length=10, blank=False)

def __str__(self):
return self.title
3 changes: 2 additions & 1 deletion events/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.urls import path
from .views import events, register
from .views import events, register, requestEvent

urlpatterns = [
path('', events, name='tech_events'),
path('register/', register, name='register'),
path('requestEvent/', requestEvent, name='requestEvent'),
]
25 changes: 21 additions & 4 deletions events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
from django.contrib import messages
from django.shortcuts import render, redirect
from django.views.generic import ListView
from .models import Event, EventParticipant
from .forms import ParticipantForm
from .models import Event, EventParticipant, requestEvent
from .forms import ParticipantForm, requestEventForm
import csv


def events(request):
events = Event.objects.all
return render(request, 'events.html', {'events': events})
events = Event.objects.all()
#numberOfEvents = len(events)
#if (numberOfEvents) == 0:
# events = 0
Copy link
Member

Choose a reason for hiding this comment

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

Why did you left commented code here. You should remove the unused code.

return render(request, 'events.html', {'events': events })


def register(request):
Expand Down Expand Up @@ -45,3 +48,17 @@ def export_to_csv(request):
error = "Please Enter a Valid Token"
return render(request, 'download.html', {'error': error})
return render(request, 'download.html')

def requestEvent(request):
if request.method == 'POST':
form = requestEventForm(request.POST)
if form.is_valid():
form.save()
your_name = form.cleaned_data.get('your_name')
title = form.cleaned_data.get('title')
messages.success(
request, f'Thank you { your_name } for requesting to organise { title }, you will be contacted shortly!')
return redirect('homepage')
else:
form = requestEventForm()
return render(request, 'event_register.html', {'form': form})
Copy link
Member

Choose a reason for hiding this comment

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

While creating methods, you should not write like this.
Use this notation, def request_event(request):

17 changes: 14 additions & 3 deletions templates/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@
<br>
<div class="container">
<br>
{% if events|length == 0 %}
<div class="card text-center">
<div class="card-body bg">
<h4 class="card-title">No Ongoing Events </h4>
<p class="card-text">Please review after sometime, to see latest ongoing Events!<br>THANK YOU!</p>
</div>
</div>

{% endif %}
{% for event in events%}
<div class="card text-center">
<div class="card-body bg">
<h4 class="card-title">{{ event.title }}</h4>
<p class="card-text">{{ event.description | linebreaksbr }}</p>
<a href="{% url 'register' %}" class="btn btn-primary">Register</a>
<a href="{% url 'register' %}" class="btn btn-primary">Register for this Event</a>
</div>
</div>
<br>
{% endfor %}
{% endfor %}
<br>
<center><a href="{% url 'requestEvent' %}" class="btn btn-primary">Request for any Event in your mind!</a></center>
</div>
{% comment %} </div> {% endcomment %}
{% endblock content %}
{% endblock content %}