Skip to content
9 changes: 7 additions & 2 deletions department/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.contrib import admin
from department.models import Department
from department import models as dept_models


# Register your models here.

@admin.register(Department)
@admin.register(dept_models.Department)
class DepartmentAdmin(admin.ModelAdmin):
list_display = ('department',)


@admin.register(dept_models.Notice)
class DepartmentAdmin(admin.ModelAdmin):
list_display = ('topic',)
8 changes: 8 additions & 0 deletions department/froms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django import forms
from .models import Notice


class NoticeForm(forms.ModelForm):
class Meta:
model = Notice
fields = '__all__'
8 changes: 8 additions & 0 deletions department/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ class Department(models.Model):

def __str__(self):
return self.department


class Notice(models.Model):
topic = models.CharField(max_length=100, default="Emergency Notice")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

does nullable works?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

BROTHER Have you done this job in laravel?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No we have not done this in laravel.

message = models.TextField()

def __str__(self):
return self.topic
59 changes: 59 additions & 0 deletions department/templates/department/notice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{% extends 'leave_manager/layout.html' %}
{% load static %}

{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2 mx-auto">
<div class="card">
<div class="header">
<h4 class="title">Send New Notice</h4>
</div>
<form method="POST" class="register-form" id="register-form" enctype ="multipart/form-data">
{% csrf_token %}
{% load addcss %}
<div class="content">
{% for field in form %}
{{field.errors}}
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>{{field.label_tag}}</label>
{{field|addcss:"form-control"}}
</div>
</div>
</div>
{% endfor %}
<div class="row">
<div class="col-md-12">
<div class="form-group form-button">
<button type="submit" name="signup" id="signup" class="btn btn-fill btn-info pull-right">Submit</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock content %}

{% block welcome_message %}
{% if message %}
<script type="text/javascript">
$(document).ready(function () {
$.notify({
icon: 'pe-7s-info',
message: "{{ message }}"

}, {
type: type[4],
timer: 4
});

});
</script>
{% endif %}
{% endblock welcome_message %}

37 changes: 37 additions & 0 deletions department/templates/department/noticeboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends 'leave_manager/layout.html' %}
{% load static %}

{% block content %}
<div class="container-fluid">
<div class="row">
<div class="{% if leave_issuer %} col-md-10 {% else %} col-md-12 {% endif %}">
{% if notices %}
{% for notice in notices %}
<div class="card" style="width: 100%;padding:5px">
<div class="card-body">
<h4 style="text-align:center;margin-botton:3px;">{{ notice.topic }}
{% if leave_issuer %}
<form action="{% url 'notice-delete' notice.id %}" method="post">
{% csrf_token %}
<button class="btn btn-danger btn-flat margin btn-sm" style="float:right;position:relative;top:-54px; margin-right:20px;" type="submit">
<i class="fa fa-trash" aria-hidden="true"></i>
</button>
</form>
{% endif %}
</h4>
<hr style="width:100%">
<p class="card-text" style="text-align:center;">{{ notice.message }}</p>
</div>
</div>
{% endfor %}
{% else %}
<tr>
<td colspan=4>
<h5>No Notice</h5>
</td>
</tr>
{% endif %}
</div>
</div>
</div>
{% endblock content %}
8 changes: 8 additions & 0 deletions department/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from department import views as dept_views

urlpatterns = [
path('', dept_views.create_notice, name='notice'),
path("delete/<int:id>", dept_views.delete_notice, name="notice-delete"),
path('view',dept_views.get_notice,name='notice-board'),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

view? say notice

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

then it would be /notice/notice

]
55 changes: 55 additions & 0 deletions department/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,58 @@
from django.shortcuts import render
from .models import Notice
from .froms import NoticeForm
from leave_manager.common.routes import get_formatted_routes, get_routes, is_leave_issuer
from django.urls import reverse
from django.http import HttpResponseRedirect
from mobile_api.common.fcm import fcm
from leave_manager.common import check_leave_admin

# Create your views here.

def create_notice(request):
if not request.user.is_authenticated:
return HttpResponseRedirect(reverse('user-login'))
if not is_leave_issuer(request.user):
return HttpResponseRedirect(reverse('leave_manager_dashboard'))

context = {}
routes = get_formatted_routes(get_routes(request.user), active_page = "notice")
context.update({'routes':routes})

if request.method == "POST":
form = NoticeForm(request.POST)
if form.is_valid():
notice = form.save(commit=True)
fcm(None,notice,"notice")
return HttpResponseRedirect(reverse('notice-board'))
else:
form = NoticeForm()
context.update({'form':form})
return render(request, 'department/notice.html', context=context)
else:
form = NoticeForm()
context.update({'form':form})

return render(request, 'department/notice.html', context=context)



def get_notice(request):
if not request.user.is_authenticated:
return HttpResponseRedirect(reverse('user-login'))
context = {}
routes = get_formatted_routes(get_routes(request.user), active_page = "notice board")
context.update({'routes':routes})
notice = Notice.objects.all()
context.update({'notices':notice})
if check_leave_admin.is_leave_issuer(request.user):
context.update({'leave_issuer':1})
return render(request, 'department/noticeboard.html', context=context)


def delete_notice(request,id):
if not request.user.is_authenticated:
return HttpResponseRedirect(reverse('user-login'))
notice = Notice.objects.filter(id=id)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use get rather than filter. with try catch. What if id = 5000000 is given?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

notice.delete()
return HttpResponseRedirect(reverse('notice-board'))
36 changes: 36 additions & 0 deletions leave_manager/common/leave_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from leave_manager.models import Leave, Holiday, CompensationLeave
from leave_manager.common.send_email_notification import send_email_notification
from leave_manager.common.user_image import get_image_url
from mobile_api.common.fcm import fcm
from lms_user import models as lms_user_models


def apply_leave(**kwargs):
Expand Down Expand Up @@ -40,6 +42,13 @@ def apply_leave(**kwargs):
reverse_lazy('leave_manager_leave_requests')))
}
if send_email_notification(update_details=update_details):
try:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DoesNotExist Again same @AwaleRohin

user =lms_user_models.LmsUser.objects.get(user=request.user)
leave_issuer = lms_user_models.LmsUser.objects.get(user=leave_details['issuer'])
leave_issuer_fcm = leave_issuer.fcm_token
fcm(leave_issuer_fcm,user,"leave_apply")
except Exception as e:
print(e)
return True
else:
leave.delete()
Expand Down Expand Up @@ -257,6 +266,11 @@ def approve_leave_request(request, leave_id):
user.save()
leave.save()
if send_email_notification(update_details=update_details):
try:
leave_issuer_fcm = user.fcm_token
fcm(leave_issuer_fcm,request.user.get_full_name(),"approve_leave")
except Exception as e:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return False on Exception hainara? @AwaleRohin

print(e)
return True
else:
return False
Expand Down Expand Up @@ -288,6 +302,11 @@ def reject_leave_request(request, leave_id):
leave.save()

if send_email_notification(update_details=update_details):
try:
leave_issuer_fcm = user.fcm_token
fcm(leave_issuer_fcm,request.user.get_full_name(),"reject_leave")
except Exception as e:
print(e)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return what on exception

Copy link
Copy Markdown
Collaborator Author

@AwaleRohin AwaleRohin Jul 24, 2019

Choose a reason for hiding this comment

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

nothing because if there is fcm token then notification will be sent otherwise do nothing and continue with process

return True
else:
return False
Expand Down Expand Up @@ -372,6 +391,13 @@ def apply_CompensationLeave(**kwargs):
reverse_lazy('leave_manager_leave_requests')))
}
if send_email_notification(update_details=update_details):
try:
user =lms_user_models.LmsUser.objects.get(user=request.user)
leave_issuer = lms_user_models.LmsUser.objects.get(user=leave_details['issuer'])
leave_issuer_fcm = leave_issuer.fcm_token
fcm(leave_issuer_fcm,user,"compensation_apply")
except Exception as e:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DoesNotExist

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

print(e)
return True
else:
leave.delete()
Expand Down Expand Up @@ -434,6 +460,11 @@ def reject_compensationLeave_request(request, leave_id):
leave.save()

if send_email_notification(update_details=update_details):
try:
leave_issuer_fcm = user.fcm_token
fcm(leave_issuer_fcm,request.user.get_full_name(),"reject_compensation")
except Exception as e:
print(e)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return what on Exception? @AwaleRohin

Copy link
Copy Markdown
Collaborator Author

@AwaleRohin AwaleRohin Jul 24, 2019

Choose a reason for hiding this comment

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

nothing because if there is fcm token then notification will be sent otherwise do nothing and continue with process

return True
else:
return False
Expand Down Expand Up @@ -478,6 +509,11 @@ def approve_compensationLeave_request(request, leave_id):
user.save()
leave.save()
if send_email_notification(update_details=update_details):
try:
leave_issuer_fcm = user.fcm_token
fcm(leave_issuer_fcm,request.user.get_full_name(),"approve_compensation")
except Exception as e:
print(e)
return True
else:
return False
Expand Down
17 changes: 16 additions & 1 deletion leave_manager/common/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,22 @@
'password': True,
'icon': 'pe-7s-pin'
},

{
'title': 'notice',
'url': reverse_lazy('notice'),
'admin': True,
'active': False,
'password': False,
'icon': 'pe-7s-note2'
},
{
'title': 'notice board',
'url': reverse_lazy('notice-board'),
'admin': False,
'active': False,
'password': False,
'icon': 'pe-7s-note2'
},
]

non_admin_navigation_routes = [route for route in all_navigation_routes if not route['admin'] and not route['password']]
Expand Down
4 changes: 4 additions & 0 deletions leave_manager/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime, timedelta
from lms_user.models import LmsUser
from leave_manager.common import check_leave_admin
from department.models import Notice

def get_birthday_notification(request):
have_birthday = {}
Expand All @@ -22,4 +23,7 @@ def get_birthday_notification(request):

if counter > 0:
have_birthday.update({'upcoming_birthday':counter})

notice = Notice.objects.all()
have_birthday.update({'notice':len(notice)})
return have_birthday
Loading