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

Notice archive #28

Open
wants to merge 1 commit into
base: master
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
227 changes: 227 additions & 0 deletions bandhuapp/templates/notice_archive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
{% extends 'accounts_base.html' %}

{% load static %}

{% block title %} Notice Archive {% endblock %}

{% block content %}
<!-- Don't put this in { style block } -->
<!-- Do not import bandhu.css -->
<style>
.ribbon-new {
background: #ff9800;
height: 30px;
width: 30px;
position: absolute;
text-align: center;
font: 400 13px sans-serif;
color: #fff;
line-height: 27px;
border: 0;
right: 16px;
margin-top: 5px;
animation: colorRotate 2s ease infinite;
}
.ribbon-new:after {
content: "";
position: absolute;
bottom: -20px;
left: 0;
height: 0;
width: 30px;
border: solid 15px #ff9800;
border-bottom-color: transparent;
}

.ribbon-new:hover {
background: #ff9800;
}

.ribbon-new:hover:after {
border-color: #ff9800;
border-bottom-color: transparent;
}

.row {
margin: 0px;
}

.section-title {
color: #0d0d0d;
font-size: 2.25em;
font-weight: 900;
line-height: 54px;
text-transform: uppercase;
margin-bottom: 45px;
position: relative;
-webkit-text-stroke: 0.3px;;
margin-right: auto;
margin-left: auto;
}
</style>

<script>
// alert("hello");
function sortNotice(){
var val = document.getElementById('sort').value;
$.ajax({
type:"POST",
url: "/get_active_notice/",
data:{
sort_type: val,
csrfmiddlewaretoken: '{{ csrf_token }}'
},
success: function(data) {
var notice = JSON.parse(data);
console.log(notice);
$("#notice-list").empty();
for(var i=0; i<notice.length; i++) {
var mynotice =
`<div class="col col-md-4 col-md-offset-2" style="padding: 15px;">
<div class="card bg-light mb-3 h-100" style="border: 0; box-shadow: 1px 2px 3px 0 #cccccc;">
<div class="card-body">
<h5 class="card-title"> <b> ${notice[i].fields.title} </b> </h5>
<h6 class="card-subtitle mb-2 text-muted" style="font-size: smaller;">
</h6>`;
if(notice[i].fields.start_date) {
mynotice += `${notice[i].fields.start_date}`; // Date Format Error
}

if(notice[i].fields.end_date) {
mynotice += `- ${notice[i].fields.end_date}`; // Date Format Error
}
mynotice += `<p class="card-text"> ${notice[i].fields.description.substring(0, 180)} <br>
<a href="#" data-target="#notice-modal${i}" data-toggle="modal" style="font-size: smaller">Read More</a>
</p>
</div>
<div class="card-footer text-muted text-right">
<a href="${notice[i].fields.link}" style="padding: 8px; text-decoration: none; font-size: 20px;">
<i class="fa fa-link"></i>
</a>`;
if (notice[i].fields.notice_file != ''){
mynotice += `<a href="${notice[i].fields.notice_file}" style="padding: 8px; text-decoration: none; font-size: 20px;">
<i class="fa fa-paperclip"></i>
</a>`;
}
mynotice += `</div>
</div>
</div>`;
$("#notice-list").append(mynotice);
}
}
});
}
</script>


<div class="notice-container" style="margin-top: 100px;">
<!-- Search Bar -->
<div class="row">
<h3 class="section-title">Notice Archive</h3>
</div>
<div class="row">
<div class="col col-md-3">
<div class="form-group">
<label for="Sort">Sort By</label>
<select name="Sort" id="sort" class="form-control" onchange="sortNotice();">
<option value="0" selected>None</option>
<option value="1">Active</option>
<option value="2">Date Created (Ascending) </option>
</select>
</div>
</div>
</div>
<div class="row">
<!-- Notices -->
<div class="col">
<div class="row" id="notice-list">
{% for notice in notices %}
<div class="col col-md-4 col-md-offset-2" style="padding: 15px;">
<div class="card bg-light mb-3 h-100" style="border: 0; box-shadow: 1px 2px 3px 0 #cccccc;">
<div class="card-body">
<h5 class="card-title"> <b> {{notice.title}} </b> </h5>
<h6 class="card-subtitle mb-2 text-muted" style="font-size: smaller;">
{% if notice.start_date %}
{{notice.start_date}}
{% endif %}
{% if notice.end_date %}
- {{notice.end_date}}
{% endif %}
</h6>
<p class="card-text"> {{notice.description|truncatechars:180}} <br>
<a href="#" data-target="#notice-modal{{forloop.counter0}}" data-toggle="modal" style="font-size: smaller">Read More</a>
</p>

{% if notice.end_date %}
<!-- If it is an event. So, keep "New" until event is over -->
{% if notice.end_date|date:"Y-m-d" >= curr_date|date:"Y-m-d" %}
<div class="ribbon-new" style="top: -5px; right: 10px;">New</div>
{% endif %}

{% elif notice.start_date %}
{% if notice.start_date|date:"Y-m-d" > notice.date_created|date:"Y-m-d" and notice.start_date|date:"Y-m-d" >= curr_date|date:"Y-m-d" %}
<!-- If it is a one day event, keep "New" until event is over -->
<div class="ribbon-new" style="top: -5px; right: 10px;">New</div>
{% elif notice.start_date|date:"Y-m-d" == notice.date_created|date:"Y-m-d" and notice.start_date|date:"Y-m-d" >= seven_day_delta|date:"Y-m-d" %}
<!-- If it is a notifiation, keep "New" for 7 days -->
<div class="ribbon-new" style="top: -5px; right: 10px;">New</div>
{% endif %}

{% else %}
<!-- If no date is mentioned, keep "New" for 7 days -->
{% if notice.date_created|date:"Y-m-d" >= seven_day_delta|date:"Y-m-d" %}
<div class="ribbon-new" style="top: -5px; right: 10px;">New</div>
{% endif %}
{% endif %}
</div>
<div class="card-footer text-muted text-right">
{% if notice.link %}
<a href="{{notice.link}}" style="padding: 8px; text-decoration: none; font-size: 20px;">
<i class="fa fa-link"></i>
</a>
{% endif %}
{% if notice.notice_file %}
<a href="{{notice.notice_file}}" style="padding: 8px; text-decoration: none; font-size: 20px;">
<i class="fa fa-paperclip"></i>
</a>
{% endif %}
</div>
</div>
</div>

{% endfor %}
</div>
</div>
</div>
</div>

<!-- Modal Section -->
{% for notice in notices %}
<div class="modal fade bd-example-modal-md" tabindex="-1" id="notice-modal{{forloop.counter0}}" role="dialog"
aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title bld" id="exampleModalLongTitle"> <b> {{notice.title}} </b></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<h6 class="card-subtitle mb-2 text-muted" style="font-size: smaller;">
{% if notice.start_date %}
{{notice.start_date}}
{% endif %}
{% if notice.end_date %}
- {{notice.end_date}}
{% endif %}
</h6>
{{ notice.description }}
</div>
</div>
</div>
</div>

{% endfor %}

{% endblock %}
3 changes: 3 additions & 0 deletions bandhuapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
path('photos/add_image/', views.add_image, name='add_image'),
path('photos/approve_image/', views.approve_image, name='approve_image'),
path('user_profile_data/', views.extract_user_data, name="extract_user_data"),
path('notice_archive/', views.notice_archive, name="notice_archive"),
path('get_active_notice/', views.get_active_notice, name="get_active_notice"),
path('get_notice_asc/', views.get_notice_asc, name="get_notice_asc"),
]
44 changes: 41 additions & 3 deletions bandhuapp/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta

from django.core import serializers
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import logout
Expand All @@ -25,7 +25,7 @@
from .models import (
Profile, Photo, Initiatives, AboutUs,
Mission, Volunteer, Gallery, Contact,
HomePage,
HomePage, RecentActivity,
)
from .templatetags import permissions as temp_perms # Template permissions

Expand Down Expand Up @@ -237,4 +237,42 @@ def extract_user_data(request):
sheet.cell(row=row, column=12).value = profile.user.is_admin

excel.save(file_path)
return HttpResponseRedirect(settings.MEDIA_URL + '/sheets/user_profile_data.xlsx')
return HttpResponseRedirect(settings.MEDIA_URL + '/sheets/user_profile_data.xlsx')

def notice_archive(request):
notices = RecentActivity.objects.all()
context = {
'notices' : notices,
'curr_date': datetime.now().date(),
'seven_day_delta': datetime.now().date() - timedelta(days=7),
}
return render(request, 'notice_archive.html', context)

def get_notice_asc(request):
if request.method == "GET" and request.is_ajax():
notices = RecentActivity.objects.all().order_by('date_created')
data = serializers.serialize('json', notices)
return JsonResponse(data, safe=False, status=200)

def get_active_notice(request):
if request.method == "POST":
sort_type = request.POST.get('sort_type')
notices = RecentActivity.objects.all()
print(sort_type)
# curr_date = datetime.now()
# seven_day_delta = datetime.now().date() - timedelta(days=7)
# active_notice = []
# for notice in notices:
# if notice.end_date :
# if notice.end_date >= curr_date:
# active_notice.append(notice)
# elif notice.start_date.date:
# if notice.start_date > notice.date_created and notice.start_date >= curr_date:
# active_notice.append(notice)
# elif notice.start_date == notice.date_created and notice.start_date.date >= seven_day_delta:
# active_notice.append(notice)
# else:
# if notice.date_created.date >= seven_day_delta:
# active_notice.append(notice)
data = serializers.serialize('json', notices)
return JsonResponse(data, safe=False, status = 200)