Skip to content
Merged
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
28 changes: 28 additions & 0 deletions managers/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,34 @@
from django_select2.forms import Select2MultipleWidget

from common.constants import CORRECT_DATE_FORMAT
from employees.models import TaskActivityType
from managers.models import Project
from users.models import CustomUser


class ActivityWidget(forms.ModelMultipleChoiceField):
widget = Select2MultipleWidget()

def __init__(self, **kwargs: Any) -> None:
super().__init__(
queryset=TaskActivityType.objects.all(),
required=False,
initial=TaskActivityType.objects.filter(is_default=True),
**kwargs
)


class ProjectAdminForm(forms.ModelForm):
activities = ActivityWidget()

def __init__(self, *args: Any, **kwargs: Any) -> None:
user_pk = kwargs.pop("user_pk", None)
super().__init__(*args, **kwargs)

managers_to_choose = CustomUser.objects.active().exclude(user_type=CustomUser.UserType.EMPLOYEE.name)
if self.instance.pk:
self.fields["managers"].queryset = managers_to_choose
self.initial["activities"] = list(TaskActivityType.objects.filter(projects=self.instance.pk))
else:
self.fields["managers"].queryset = managers_to_choose.exclude(pk=user_pk)
self.fields["managers"].required = False
Expand All @@ -32,13 +48,25 @@ class Meta:
"members": Select2MultipleWidget(),
}

def save(self, commit: bool = True) -> Project:
project = super().save()
project.project_activities.set(self.cleaned_data["activities"])
return project


class ProjectManagerForm(forms.ModelForm):
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
self.fields["members"].queryset = CustomUser.objects.active()

activities = ActivityWidget()

class Meta:
model = Project
exclude = ("managers",)
widgets = ProjectAdminForm.Meta.widgets

def save(self, commit: bool = True) -> Project:
project = super().save()
project.project_activities.set(self.cleaned_data["activities"])
return project
Binary file added managers/static/managers/images/ico-11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 70 additions & 1 deletion managers/static/managers/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@

.row.images > a > i {
color: #2C77BC;
;
}

.box-wrapper {
Expand Down Expand Up @@ -125,3 +124,73 @@
width: calc(99% - 120px);
border-color: #2c77bc;
}

#modal-dialog-create-project-form {
background: white;
padding: 2.5% 2.5% 1%;
-webkit-box-shadow: 0 0 10px grey;
-moz-box-shadow: 0 0 10px grey;
box-shadow: 0 0 10px grey;
min-width: 200px;
max-width: 600px;
width: 95%;
margin: auto;
}

#create-project-form > .form-group > .form-group > input {
width: 10em;
}

.form-group > label {
font-weight: 400; !important;
font-size: 130%;
}

.row.panel-title {
margin-bottom: 6%;
}

.select2.select2-container.select2-container--default {
display: unset;
width: 50%;
}

span.selection {
min-width: 100px;
width: 70%;
}
.project-name-div, .activities-div {
width: 80%;
margin-left: 10%;
margin-right: 10%;
margin-bottom: 5%;
}

.project-buttons > button {
margin-top: 20px;
margin-left: 20px;
margin-right: 20px;
width: 15rem;
}

.delete-project-confimation {
display: none;
}

#div_id_name > div > input {
text-align: center;
width: 70%;
margin: auto;
}

.input-group.date {
width: 70%;
max-width: max-content;
margin: auto;
}

@media only screen and (max-width: 400px) {
.bootstrap-datetimepicker-widget {
left: -90px !important;
}
}
11 changes: 11 additions & 0 deletions managers/templates/managers/partials/delete-project-modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load i18n %}

<div class="delete-project-confimation">
<div id="dialog" title="{% trans 'Are you sure' %}?">
<p>{% trans 'Do you want to delete' %}</p>
<p><b>{{ object.name }}</b> {% trans 'project' %}?</p>
<form action="{% url 'custom-project-delete' pk=object.pk %}" method="POST" id="form">
{% csrf_token %}
</form>
</div>
</div>
49 changes: 49 additions & 0 deletions managers/templates/managers/partials/project_create_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% load i18n %}
{% load crispy_forms_tags %}

<div class="project-form">
<div class="row form-row">
<div class="col-xs-12 project-name-div">
{{ form.name|as_crispy_field }}
</div>
</div>
<div class="row form-row">
<div class="col-lg-6 mb-0 form-group">
{{ form.start_date|as_crispy_field }}
</div>
<div class="col-lg-6 mb-0 form-group">
{{ form.stop_date|as_crispy_field }}
</div>
</div>
<div class="row form-row">
<div class="col-md-6 mb-0 form-group">
{{ form.suspended|as_crispy_field }}
</div>
<div class="col-md-6 mb-0 form-group">
{{ form.is_notification_enabled|as_crispy_field }}
</div>
</div>
<div class="row form-row">
{% if user.is_admin %}
<div class="col-lg-6 form-group">
{{ form.managers|as_crispy_field }}
</div>
{% endif %}
<div class="{% if user.is_admin %}col-lg-6{% else %}col-12{% endif %} form-group">
{{ form.members|as_crispy_field }}
</div>
</div>
<div class="row form-row">
<div class="col-xs-12 activities-div">
{{ form.activities|as_crispy_field }}
</div>
</div>
<div class="row form-group project-buttons">
<button type="submit" class="btn btn-success">{{ button_text }}</button>
{% if user.is_admin and object %}
<button type="button" id="opener" class="btn btn btn-danger">
<span class="glyphicon glyphicon-remove"></span> {% trans 'Delete' %}
</button>
{% endif %}
</div>
</div>
60 changes: 26 additions & 34 deletions managers/templates/managers/project_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

{% load i18n %}
{% load static %}
{% load crispy_forms_tags %}

{% block extra_head %}
<link
Expand All @@ -14,48 +13,41 @@
<link
rel="stylesheet"
type="text/css"
href="{% static "employees/style.css" %}"
integrity="{% staticinline "employees/style.css" encode="sri" %}"
href="{% static "managers/style.css" %}"
integrity="{% staticinline "managers/style.css" encode="sri" %}"
crossorigin="anonymous"
/>
{{ form.media.css }}
{% endblock %}

{% block content %}
<h2>
<small>
<a href="{{ back_url }}">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
</small>
{{ title }}
</h2>
<div class="modal-dialog" id="modal-dialog-create-project-form">
<div class="row panel-title">
<div class="col-xs-12">
<h2>
<small>
<a href="{{ back_url }}">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
</small>
<img src="{% static 'managers/images/ico-11.png' %}"/>
{{ title }}
</h2>
</div>
</div>
<form id="create-project-form" action="." method="post">
{% csrf_token %}
{% include 'managers/partials/project_create_form.html' %}
</form>
</div>

<div class="modal-dialog" style="margin-bottom:0">
<form action="." method="post">
{% csrf_token %}
{{ form|crispy }}
<button type="submit" class="btn btn-default">{{ button_text }}</button>
</form>
</div>

{% if request.user.is_admin and object %}
<br/>
<button type="button" id="opener" class="btn btn btn-danger">
<span class="glyphicon glyphicon-remove"></span> Delete
</button>

<div id="dialog" style="display: none" title="{% trans 'Are you sure' %}?" align="center">
{% trans 'Do you want to delete' %} <br/>
<b>{{object.name}}</b> {% trans 'project' %}?
<form style="display: hidden" action="{% url 'custom-project-delete' pk=object.pk %}" method="POST" id="form">
{% csrf_token %}
</form>
</div>
{% endif %}
{% if request.user.is_admin and object %}
{% include 'managers/partials/delete-project-modal.html' %}
{% endif %}
{% endblock %}

{% block extra_script %}
{{ form.media }}
{{ form.media.js }}
{% if request.user.is_admin and object %}
<script
src="https://code.jquery.com/jquery-3.3.1.js"
Expand Down
2 changes: 1 addition & 1 deletion managers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_context_data(self, **kwargs: Any) -> dict:
@method_decorator(login_required, name="dispatch")
@method_decorator(check_permissions(allowed_user_types=[CustomUser.UserType.ADMIN.name]), name="dispatch")
class ProjectCreateView(CreateView):
extra_context = {"button_text": _("Create"), "title": _("Create new project")}
extra_context = {"button_text": _("Create"), "title": _("New project")}
form_class = ProjectAdminForm
model = Project
template_name = "managers/project_form.html"
Expand Down