Skip to content

Commit

Permalink
assigned vacation views
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielf-eb committed Nov 8, 2019
1 parent f3c300b commit 9fb821c
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 1 deletion.
2 changes: 1 addition & 1 deletion templates/vacations_app/admin_vacation_request.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h3>Admin Vacation Request</h3>
<div class="row">
<div class="col-md-6">
<form action="{% url 'vacation-admin-request' %}" method="post" class="form">
<form method="post" class="form">
{% csrf_token %}

{% for hidden_field in form.hidden_fields %}
Expand Down
20 changes: 20 additions & 0 deletions templates/vacations_app/assignedvacations_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'vacations_app/base.html' %}
{% load bootstrap4 %}
{% load widget_tweaks %}

{% block content %}
<h3>Employee Assigned Vacation</h3>
<div class="row">
<div class="col-md-6">
<form method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm">
</form>

</div>
</div>
{% endblock content %}
{% block scripts %}
{{ block.super }}
{{form.media }}
{% endblock scripts %}
55 changes: 55 additions & 0 deletions templates/vacations_app/assignedvacations_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% extends 'vacations_app/base.html' %}
{% load bootstrap4 %}
{% load widget_tweaks %}

{% block content %}
<h3>Employee Assigned Vacation</h3>
<div class="row">
<div class="col-md-6">
<form method="post" class="form">
{% csrf_token %}

{% for hidden_field in form.hidden_fields %}
{{ hidden_field }}
{% endfor %}

{% if form.non_field_errors %}
<div class="alert alert-danger" role="alert">
{% for error in form.non_field_errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}

{% for field in form.visible_fields %}
<div class="form-group">
{{ field.label_tag }}
{% if form.is_bound %}
{% if field.errors %}
{% render_field field class="form-control is-invalid" %}
{% for error in field.errors %}
<div class="help-block">
{{ error }}
</div>
{% endfor %}
{% else %}
{% render_field field class="form-control is-valid" %}
{% endif %}
{% else %}
{% render_field field class="form-control" %}
{% endif %}

{% if field.help_text %}
<small class="form-text text-muted">{{ field.help_text }}</small>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-info">Save</button>
</form>
</div>
</div>
{% endblock content %}
{% block scripts %}
{{ block.super }}
{{form.media }}
{% endblock scripts %}
37 changes: 37 additions & 0 deletions templates/vacations_app/assignedvacations_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends 'vacations_app/base.html' %}
{% load static %}
{% block head %}
{{block.super}}
<link rel="stylesheet" href="{% static 'css/index.css' %}">
{% endblock head %}
{% block content %}

{% if user.is_authenticated %}
<h1>Employees Assigned Vacations</h1>
<table class="table table-hover">
<thead class="thead-dark">
<tr>
<th>Employee</th>
<th>Worked Year</th>
<th>Total Days</th>
<th>Actions</th>
</tr>
</thead>
{% for assigned_vacation in object_list %}
<tbody>
<tr>
<td>{{ assigned_vacation.employee.first_name }} {{ assigned_vacation.employee.last_name }} </td>
<td>{{ assigned_vacation.worked_year }}</td>
<td>{{ assigned_vacation.total_days }}</td>
<td>
<a href="{% url 'assigned-vacations-update' assigned_vacation.id %}" class="btn btn-primary">Update</a>
<a href="{% url 'assigned-vacations-delete' assigned_vacation.id %}" class="btn btn-primary">Delete</a>
</td>
</tr>
</tbody>
{% endfor %}
</table>
<a href="{% url 'assigned-vacations-create' %}" class="btn btn-primary">Create Assigned Vacations</a>
{% else %}
{% endif %}
{% endblock content %}
1 change: 1 addition & 0 deletions templates/vacations_app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ <h1>Employee</h1>
<a href="{% url 'vacation-admin-request' %}" class="btn btn-warning">Admin Request vacation</a>
<a href="{% url 'vacations-list' %}" class="btn btn-info">View vacations requests</a>
<a href="{% url 'holidays-list' %}" class="btn btn-info">View Holidays</a>
<a href="{% url 'assigned-vacations-list' %}" class="btn btn-info">View Employees Assigned Vacations</a>
{% endif %}
{% endif %}
{% endblock content %}
8 changes: 8 additions & 0 deletions vacations_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"""
from django.conf.urls import url
from .views import (
AssignedVacationCreateView,
AssignedVacationDeleteView,
AssignedVacationsList,
AssignedVacationUpdateView,
HolidayCreateView,
HolidayUpdateView,
HolidayDeleteView,
Expand All @@ -34,6 +38,10 @@
url(r'^vacation/admin-request$', AdminVacationRequest.as_view(), name='vacation-admin-request'),
url(r'^vacations$', VacationList.as_view(), name='vacations-list'),
url(r'^vacations/team$', TeamVacationsList.as_view(), name='vacations-team'),
url(r'^assigned_vacations$', AssignedVacationsList.as_view(), name='assigned-vacations-list'),
url(r'^assigned_vacations/create$', AssignedVacationCreateView.as_view(), name='assigned-vacations-create'),
url(r'^assigned_vacations/update/(?P<pk>[0-9]+)/$', AssignedVacationUpdateView.as_view(), name='assigned-vacations-update'),
url(r'^assigned_vacations/delete/(?P<pk>[0-9]+)/$', AssignedVacationDeleteView.as_view(), name='assigned-vacations-delete'),
url(r'^holidays$', HolidayList.as_view(), name='holidays-list'),
url(r'^holidays/create$', HolidayCreateView.as_view(), name='holidays-create'),
url(r'^holidays/update/(?P<pk>[0-9]+)/$', HolidayUpdateView.as_view(), name='holidays-update'),
Expand Down
26 changes: 26 additions & 0 deletions vacations_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CAN_VIEW_TEAM_MEMBERS_VACATIONS,
)
from vacations_app.models import (
AssignedVacations,
Holiday,
Vacation,
validate_from_date,
Expand Down Expand Up @@ -184,3 +185,28 @@ def get_form(self):
widget=DatePickerInput(),
)
return form


class AssignedVacationsList(PermissionRequiredMixin, ListView):
permission_required = CAN_VIEW_OTHER_VACATIONS
model = AssignedVacations


class AssignedVacationCreateView(PermissionRequiredMixin, CreateView):
permission_required = CAN_VIEW_OTHER_VACATIONS
model = AssignedVacations
fields = '__all__'
success_url = reverse_lazy('assigned-vacations-list')


class AssignedVacationUpdateView(PermissionRequiredMixin, UpdateView):
permission_required = CAN_VIEW_OTHER_VACATIONS
model = AssignedVacations
fields = '__all__'
success_url = reverse_lazy('assigned-vacations-list')


class AssignedVacationDeleteView(PermissionRequiredMixin, DeleteView):
permission_required = CAN_VIEW_OTHER_VACATIONS
model = AssignedVacations
success_url = reverse_lazy('assigned-vacations-list')

0 comments on commit 9fb821c

Please sign in to comment.