-
Notifications
You must be signed in to change notification settings - Fork 14
Notice #3
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
base: mobile_api
Are you sure you want to change the base?
Notice #3
Changes from 5 commits
7f5ac45
c4f69b6
f354b51
2ef4e00
ea5f06a
158074c
cd0b31e
76d1845
680d3ff
cd105fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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',) |
| 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__' |
| 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 %} | ||
|
|
| 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 %} |
| 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'), | ||
|
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. view? say notice
Collaborator
Author
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. then it would be /notice/notice |
||
| ] | ||
| 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) | ||
|
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. use get rather than filter. with try catch. What if id = 5000000 is given?
Collaborator
Author
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. done |
||
| notice.delete() | ||
| return HttpResponseRedirect(reverse('notice-board')) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
|
@@ -40,6 +42,13 @@ def apply_leave(**kwargs): | |
| reverse_lazy('leave_manager_leave_requests'))) | ||
| } | ||
| if send_email_notification(update_details=update_details): | ||
| try: | ||
|
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. 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() | ||
|
|
@@ -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: | ||
|
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. return False on Exception hainara? @AwaleRohin |
||
| print(e) | ||
| return True | ||
| else: | ||
| return False | ||
|
|
@@ -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) | ||
|
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. return what on exception
Collaborator
Author
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. nothing because if there is fcm token then notification will be sent otherwise do nothing and continue with process |
||
| return True | ||
| else: | ||
| return False | ||
|
|
@@ -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: | ||
|
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. DoesNotExist
Collaborator
Author
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. Done |
||
| print(e) | ||
| return True | ||
| else: | ||
| leave.delete() | ||
|
|
@@ -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) | ||
|
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. return what on Exception? @AwaleRohin
Collaborator
Author
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. nothing because if there is fcm token then notification will be sent otherwise do nothing and continue with process |
||
| return True | ||
| else: | ||
| return False | ||
|
|
@@ -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 | ||
|
|
||
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.
does nullable works?
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.
BROTHER Have you done this job in laravel?
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.
No we have not done this in laravel.