Coverage for apps/report/bulk_import/support_pariticipation_detail.py : 95%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from dateutil.parser import parse as date_parse
3from report.models import SupportPariticipationDetail
4from report.utils import convert_to_int
6from .common import get_or_create_project
9def increment(obj, keys, value=1):
10 _dict = obj
11 for key in keys[:-1]:
12 if _dict.get(key) is None:
13 _dict[key] = {}
14 _dict = _dict[key]
15 _dict[keys[-1]] = _dict.get(keys[-1], 0) + value
18def extract(csv_data, _):
19 import_data = {}
21 # Collect Data
22 for row in csv_data:
23 pj_translation = row['Textbox255']
24 pj_number = convert_to_int(pj_translation.split('-')[0].split(':')[1])
25 p_type = row['ParticipationType']
26 comment = row['ParticipationComments']
27 p_date = date_parse(row['ParticipationDate']).date()
29 increment(
30 import_data,
31 (pj_number, p_type, comment, p_date)
32 )
34 # Save Data to DB
35 for pj_number, language_data in import_data.items():
36 project = get_or_create_project(pj_number)
37 for p_type, comment, p_date, count in [
38 (p_type, comment, p_date, count)
39 for p_type, p_type_data in language_data.items()
40 for comment, comment_data in p_type_data.items()
41 for p_date, count in comment_data.items()
42 ]:
43 if count == 0: 43 ↛ 44line 43 didn't jump to line 44, because the condition on line 43 was never true
44 continue
45 sppd, _ = SupportPariticipationDetail.objects.get_or_create(
46 project=project,
47 date=p_date,
48 type=p_type,
49 comment=comment,
50 )
51 sppd.count = count
52 sppd.save()