Skip to content

Commit

Permalink
#256 excel export now support the extended task properties (from #260)…
Browse files Browse the repository at this point in the history
…. follow to e2e911f
  • Loading branch information
yn-coder committed Apr 21, 2021
1 parent e2e911f commit ee1b6ff
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from django.utils.html import strip_tags
from django.utils.encoding import escape_uri_path
from django.utils import timezone

from account.mixins import LoginRequiredMixin
from django.views.generic import View
from django.views.generic.edit import CreateView, UpdateView
Expand Down Expand Up @@ -495,21 +497,45 @@ def get(self, request, project_id):
# Write data.
fields = ( 'id', 'created_at', 'fullname', 'holder', 'state', 'detailed_state', 'milestone', 'finished_fact_at', 'important', 'kind', 'sub_project' )

#Task._meta.get_fields()
# linked properties titles
prop_fields = None
if project.use_properties:
tpt = Task_Property_Type.objects.all()
prop_fields = {}
for p in tpt:
prop_fields[p.id] = p.name

row_num = 0
col_num = 0
for field in fields:
cell_data = Task._meta.get_field( field ).verbose_name
worksheet.write(row_num, col_num, cell_data)
title = Task._meta.get_field( field ).verbose_name
worksheet.write(row_num, col_num, title)
col_num = col_num + 1
if prop_fields:
for pf in prop_fields:
title = prop_fields[ pf ]
worksheet.write(row_num, col_num, title)
col_num = col_num + 1

row_num = 1
for task in data:
col_num = 0
for field in fields:
cell_data = getattr(task, field )
worksheet.write(row_num, col_num, str( cell_data) )
if cell_data:
worksheet.write(row_num, col_num, str( cell_data) )
col_num = col_num + 1

if prop_fields:
for pf in prop_fields:
try:
a = Task_Property_Amount.objects.get( task=task, property_id = pf )
cell_data = a.amount
if a.amount:
worksheet.write(row_num, col_num, str( cell_data) )
except:
pass
col_num = col_num + 1
row_num = row_num + 1

# Close the workbook before sending the data.
Expand All @@ -519,7 +545,8 @@ def get(self, request, project_id):
output.seek(0)

# Set up the Http response.
filename = project_id + '_' + project.fullname + '.xlsx'
n = timezone.now()
filename = project_id + '_' + project.fullname + '_' + str( n ) + '.xlsx'

response = HttpResponse(
output,
Expand Down

0 comments on commit ee1b6ff

Please sign in to comment.