Skip to content

Commit

Permalink
Merge pull request #334 from PROCOLLAB-github/loadout_leaders_vacanci…
Browse files Browse the repository at this point in the history
…es_email

loadout of leader emails and vacancies
  • Loading branch information
sh1nkey authored Mar 18, 2024
2 parents 9d6a25e + 57ed691 commit 9d56999
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
15 changes: 15 additions & 0 deletions templates/vacancies/vacancies_change_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "admin/change_list.html" %}
{% load i18n %}

{% block object-tools-items %}
{{ block.super }}
<a href="#" class="addlink" previewlistener="true" onclick="get_emails_vacancies()">
Emal лидеров у проектов с вакансиями
</a>

<script>
function get_emails_vacancies() {
window.open("{% url 'admin:vacancy_leaders_email' %}", '_blank').focus();
}
</script>
{% endblock %}
48 changes: 47 additions & 1 deletion vacancy/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import tablib
from django.contrib import admin
from django.http import HttpResponse
from django.urls import path

from vacancy.models import Vacancy, VacancyResponse

Expand All @@ -7,7 +10,6 @@
class VacancyAdmin(admin.ModelAdmin):
list_display = [
"role",
"required_skills",
"description",
"project",
"is_active",
Expand All @@ -16,6 +18,50 @@ class VacancyAdmin(admin.ModelAdmin):
]
list_display_links = ["role"]

change_list_template = "vacancies/vacancies_change_list.html"

def get_urls(self):
default_urls = super(VacancyAdmin, self).get_urls()
custom_urls = [
path(
"email-vacancies/",
self.admin_site.admin_view(self.email_leaders_vacancies),
name="vacancy_leaders_email",
)
]
return custom_urls + default_urls

def email_leaders_vacancies(self, request):
data = list(
Vacancy.objects.select_related("project", "project__leader").values_list(
"project__leader__email", "datetime_created", "project__id", "role"
)
)
return self.excel_email_leaders_vacancies(data)

def excel_email_leaders_vacancies(self, data: list):
response_data = tablib.Dataset(
headers=["email", "дата", "ссылка на проект", "название вакансии"]
)

for row in data:
row_to_add = [
row[0],
row[1].strftime("%d-%m-%Y %S:%M:%H %Z"),
f"https://app.procollab.ru/office/projects/{row[2]}",
row[3],
]
response_data.append(row_to_add)

binary_data = response_data.export("xlsx")
file_name = "email_of_leaders_with_users"
response = HttpResponse(
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
headers={"Content-Disposition": f'attachment; filename="{file_name}.xlsx"'},
)
response.write(binary_data)
return response


@admin.register(VacancyResponse)
class VacancyResponseAdmin(admin.ModelAdmin):
Expand Down

0 comments on commit 9d56999

Please sign in to comment.