Skip to content
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
Binary file modified blood/blog/__pycache__/views.cpython-36.pyc
Binary file not shown.
29 changes: 22 additions & 7 deletions blood/blog/static/blog/donors-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var criterion_map = {
"Blood Group": 2,
"Mobile number": 3,
"Eligible by(days)": 4,
"Everything": 5
"event": 5,
"Everything": 6,
};

var column_names=[
Expand All @@ -13,7 +14,8 @@ var column_names=[
"Blood Group",
"Mobile number",
"Eligible by(days)",
"Everything"
"event",
"Everything",
];

function editTable(){
Expand Down Expand Up @@ -81,8 +83,16 @@ function showForm(button){
}


function changeFilter(index) {
document.getElementById("criterion").innerHTML = column_names[index];
function changeFilter(index, eventId) {
if(index != -1){
document.getElementById("criterion").innerHTML = column_names[index];
}
if(eventId!=-1){
document.getElementById("eventId").innerHTML = eventId;
}
if(index == -1){
myFunction();
}
}

function myFunction() {
Expand All @@ -92,6 +102,7 @@ function myFunction() {
var table = document.getElementById("myTable");
var tr = table.getElementsByTagName("tr");
var criterion = document.getElementById("criterion").innerHTML;
var eventId = document.getElementById("eventId");

// Loop through all table rows, and hide those who don't match the search query
for (var i = 1; i < tr.length; i++) {
Expand All @@ -100,7 +111,7 @@ function myFunction() {
var j = criterion_map[criterion];
if(criterion ==="Everything"){
//enable display if atleast one of the fields match the query
for(var j =0; j<td.length-1; j++){
for(var j =0; j<td.length-2; j++){
if(td[j])
if(td[j].innerHTML.toUpperCase().indexOf(filter)>-1)
tr[i].style.display = "";
Expand All @@ -117,9 +128,13 @@ function myFunction() {
if(td[j].innerHTML.toUpperCase().indexOf(filter)>-1)
tr[i].style.display = "";
}
if(filter=="")

if(td[td.length-1].innerHTML != eventId.innerHTML){
tr[i].style.display = "none";
}
if(filter=="" && eventId.innerHTML==0 )
tr[i].style.display = "";
}
//after the fiter call form, but tell it not to change the state of the

editTable();
}
3 changes: 3 additions & 0 deletions blood/blog/static/blog/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,6 @@ nav{
padding: 10px;
}

#eventFilter{
border-radius: 0 .25rem .25rem 0;
}
35 changes: 28 additions & 7 deletions blood/blog/templates/blog/donors.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,45 @@ <h4 class="alert-heading">This page is for admin only</h4>
<div class="input-group-prepend">
<button id='criterion' class="btn btn-outline-info dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Everything</button>
<div class="dropdown-menu">
<div class="dropdown-item" onclick="changeFilter(0)">
<div class="dropdown-item" onclick="changeFilter(0, -1)">
Name</div>
<div class="dropdown-item" onclick="changeFilter(1)">
<div class="dropdown-item" onclick="changeFilter(1, -1)">
Email</div>
<div class="dropdown-item" onclick="changeFilter(2)">
<div class="dropdown-item" onclick="changeFilter(2, -1)">
Blood Group</div>
<div class="dropdown-item" onclick="changeFilter(3)">
<div class="dropdown-item" onclick="changeFilter(3, -1)">
Mobile number</div>
<div class="dropdown-item" onclick="changeFilter(4)">
<div class="dropdown-item" onclick="changeFilter(4, -1)">
Eligible by(days)</div>
<div role="separator" class="dropdown-divider"></div>
<div class="dropdown-item" onclick="changeFilter(5)">
<div class="dropdown-item" onclick="changeFilter(5, -1)">
Everything</div>
</div>
</div>
<input id="myInput" onkeyup="myFunction()" type="text"
class="form-control" aria-label="Text input with dropdown button"
placeholder="Search">
</div>

<div class="dropdown">
<button id="eventFilter" class="btn btn-outline-info dropdown-toggle"
type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Filter by event
</button>
<span id="eventId" style="display: none;">0</span>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<div class="dropdown-item" href="#" onclick="changeFilter(-1,0)">
Clear event filter
</div>
<div role="separator" class="dropdown-divider"></div>
{% for post in posts %}
<div class="dropdown-item" href="#" onclick="changeFilter(-1, {{ post.id }} )">
{{post.title}}
</div>
{% endfor %}
</div>
</div>
</div>

<table id="myTable" class="table table-striped table-borderless">
<tbody>
<tr>
Expand All @@ -60,6 +79,7 @@ <h4 class="alert-heading">This page is for admin only</h4>
<th scope="row">Blood Group</th>
<th scope="row">Mobile number</th>
<th scope="row">Last donated (Days ago)</th>
<th scope="row">Current Event</th>
</tr>
{% for donor in people %}
<tr>
Expand All @@ -68,6 +88,7 @@ <h4 class="alert-heading">This page is for admin only</h4>
<td>{{ donor.0.profile.blood_group }}</td>
<td>{{ donor.0.profile.mobile_number}}</td>
<td>{{ donor.1 }}</td>
<td>{{ donor.0.profile.current_event_id }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
15 changes: 10 additions & 5 deletions blood/blog/templates/blog/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,36 @@
}
</style>
<div id="home-mid">
{% if isEle %}
{% if user.is_authenticated and not isEle and not user.is_staff %}
<div class="alert alert-danger" role="alert">
We thank you for your recent registration for one of our blood donation camps. We advise you to wait for atleast {{ daysLeft }} days until your next donation.
</div>
{% endif %}
{% if user.is_staff %}
<div class="alert alert-info" role="alert">
Welcome admin, {{ user.username }}
</div>
{% endif %}
<h1>Upcoming Camps</h1>
<br>
{% for post in posts %}
<article class="media content-section">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ post.author }}</a>
<small class="text-muted">{{ post.date_posted }}</small>
<small class="mr-1">Date and time:</small>
<small class="text-muted">{{ post.event_date }}</small>
</div>
<h2><a class="article-title" href="{% url 'post-detail' post.id %}">{{ post.title }}</a></h2>
<p class="article-content"><strong>Venue: </strong>{{ post.venue }}</p>
<div class="form-group">
<form method="POST">
<form method="POST" onsubmit="return confirm('Are you sure you want to enroll?');">
{% csrf_token %}
<fieldset class="form-group" style="display:none;">
<legend class="border-bottom mb-4">Enroll</legend>
{{ form|crispy }}
<span>{{ post.id }}</span>
</fieldset>
{% if isELe %}
{% if isEle %}
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Enroll</button>
</div>
Expand Down
14 changes: 12 additions & 2 deletions blood/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from datetime import *
from django.core.mail import send_mail
from django.conf import settings
def cleanUser(user):
if user.profile.current_event_id>0 and Eli(user)>0:
user.profile.current_event_id = 0

def home(request):
if request.user.is_authenticated:
Expand All @@ -23,8 +26,10 @@ def home(request):
post = Post.objects.get(id = form.instance.event)
temp = post.event_date.date()
request.user.profile.last_donated = temp
request.user.profile.current_event_id = form.instance.event
request.user.profile.save()
form.save()
return redirect('blog-home')
else:
# we come here first and.....
form = EnrollForm()
Expand All @@ -37,7 +42,7 @@ def home(request):
'form': form,
'isEle': isEle>=112,
'daysLeft': 112-isEle
}
}
return render(request, 'blog/home.html', context)
else:
context = {
Expand Down Expand Up @@ -70,6 +75,9 @@ def Eli(x):
return (datetime.now().date() - x.profile.last_donated).days

def donors(request):
users = User.objects.all()
for user in users:
cleanUser(user)
form = EmergencyEmailForm()
if request.method == 'POST':
form = EmergencyEmailForm(request.POST)
Expand All @@ -87,10 +95,12 @@ def donors(request):
success_mssg = ""
people = User.objects.all()
people = list(map(lambda x:[x,Eli(x)], people))
posts = Post.objects.all().order_by("-event_date")[:3]
context = {
'people' : people,
'form' : form,
'message' : success_mssg
'message' : success_mssg,
'posts' : posts,
}
return render(request, 'blog/donors.html', context)

Expand Down
Binary file modified blood/blood/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file modified blood/blood/__pycache__/urls.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion blood/blood/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_SSL = True
EMAIL_HOST_SSL = False
EMAIL_HOST_USER = 'casualdeepak@gmail.com'
EMAIL_HOST_PASSWORD = 'tczwijngqqeasnwp'
9 changes: 5 additions & 4 deletions blood/blood/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
#Including another URLconf
# 1. Import the include() function: from django.urls import include, path
# 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))

from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include
from users import views as user_views
from django.contrib.auth import views as auth_views

urlpatterns = [
path('admin/', admin.site.urls),
path('register/', user_views.register, name='register'),
path('login/', auth_views.LoginView.as_view(template_name = 'users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name = 'users/logout.html'), name='logout'),
path('profile/', user_views.profile, name='profile'),
Expand All @@ -29,6 +28,8 @@
path('password-reset/done', auth_views.PasswordResetDoneView.as_view(template_name = 'users/password_reset_done.html'), name='password_reset_done'),
path('password-reset-confirm/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name = 'users/password_reset_confirm.html'), name='password_reset_confirm'),
path('password-reset-complete/', auth_views.PasswordResetCompleteView.as_view(template_name = 'users/password_reset_complete.html'), name='password_reset_complete'),


url(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
user_views.activate, name='activate'),
path('register/', user_views.register, name='register'),

]
Binary file modified blood/db.sqlite3
Binary file not shown.
Binary file modified blood/users/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file added blood/users/__pycache__/tokens.cpython-36.pyc
Binary file not shown.
Binary file modified blood/users/__pycache__/views.cpython-36.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions blood/users/migrations/0002_profile_current_event_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.2 on 2018-11-27 19:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='profile',
name='current_event_id',
field=models.IntegerField(default=0),
),
]
Binary file not shown.
1 change: 1 addition & 0 deletions blood/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Profile(models.Model):
date_of_birth = models.DateField(default = timezone.now)
gender = models.CharField(max_length = 10, default = Male, choices = gender_choice)
is_registered = models.BooleanField(default = False)
current_event_id = models.IntegerField(default = 0)


def __str__(self):
Expand Down
5 changes: 5 additions & 0 deletions blood/users/templates/users/acc_active_email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% autoescape off %}
Hi {{ user.username }},
Please click on the link to confirm your registration,
http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
{% endautoescape %}
8 changes: 5 additions & 3 deletions blood/users/templates/users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
align-items: center;
}

#profile-info {
margin-right: 100px;
}

#profile-info th{
font-size: 1.1em;
Expand All @@ -34,6 +31,11 @@
align-items: baseline;
}

#profile-info {
width: 400px;
margin-right: 100px;
}

#register-mid{
padding-top: 0;
max-width: 700px;
Expand Down
10 changes: 9 additions & 1 deletion blood/users/tokens.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
from django.auth.contrib.tokens import
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils import six
class TokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (
six.text_type(user.pk) + six.text_type(timestamp) +
six.text_type(user.is_active)
)
account_activation_token = TokenGenerator()
Loading