Example #1
0
def attach_extra_info(queryset, user=None):
    # Userstories prefetching
    UserStory = apps.get_model("userstories", "UserStory")
    us_queryset = UserStory.objects.select_related("milestone", "project",
                                                   "status", "owner",
                                                   "assigned_to",
                                                   "generated_from_issue",
                                                   "generated_from_task")

    us_queryset = userstories_utils.attach_total_points(us_queryset)
    us_queryset = userstories_utils.attach_total_attachments(us_queryset)
    us_queryset = userstories_utils.attach_role_points(us_queryset)
    us_queryset = userstories_utils.attach_epics(us_queryset)

    us_queryset = attach_total_voters_to_queryset(us_queryset)
    us_queryset = attach_watchers_to_queryset(us_queryset)
    us_queryset = attach_total_watchers_to_queryset(us_queryset)
    us_queryset = attach_is_voter_to_queryset(us_queryset, user)
    us_queryset = attach_is_watcher_to_queryset(us_queryset, user)

    queryset = queryset.prefetch_related(
        Prefetch("user_stories", queryset=us_queryset))

    queryset = attach_total_points(queryset)
    queryset = attach_closed_points(queryset)

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)

    return queryset
Example #2
0
def attach_extra_info(queryset, user=None):
    # Userstories prefetching
    UserStory = apps.get_model("userstories", "UserStory")
    us_queryset = UserStory.objects.select_related("milestone",
                                                   "project",
                                                   "status",
                                                   "owner",
                                                   "assigned_to",
                                                   "generated_from_issue")

    us_queryset = userstories_utils.attach_total_points(us_queryset)
    us_queryset = userstories_utils.attach_role_points(us_queryset)
    us_queryset = attach_total_voters_to_queryset(us_queryset)
    us_queryset = attach_watchers_to_queryset(us_queryset)
    us_queryset = attach_total_watchers_to_queryset(us_queryset)
    us_queryset = attach_is_voter_to_queryset(us_queryset, user)
    us_queryset = attach_is_watcher_to_queryset(us_queryset, user)

    queryset = queryset.prefetch_related(Prefetch("user_stories", queryset=us_queryset))
    queryset = attach_total_points(queryset)
    queryset = attach_closed_points(queryset)

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    return queryset
Example #3
0
def promote_to_us(source_obj):
    model_class = source_obj.__class__
    queryset = model_class.objects.filter(pk=source_obj.id)
    queryset = queryset.prefetch_related("attachments")
    queryset = queryset.select_related("owner", "assigned_to", "project")
    queryset = attach_watchers_to_queryset(queryset)

    us_refs = []
    for obj in queryset:
        us = UserStory.objects.create(
            generated_from_issue_id=obj.id
            if model_class.__name__ == "Issue" else None,
            generated_from_task_id=obj.id
            if model_class.__name__ == "Task" else None,
            project=obj.project,
            owner=obj.owner,
            subject=obj.subject,
            description=obj.description,
            tags=obj.tags,
            milestone=obj.milestone,
        )

        content_type = apps.get_model("contenttypes",
                                      "ContentType").objects.get_for_model(us)

        _import_assigned(obj, us)
        _import_comments(obj, us)
        _import_attachments(obj, us, content_type)
        _import_watchers(obj, us, content_type)

        us_refs.append(us.ref)

    return us_refs
Example #4
0
def attach_extra_info(queryset,
                      user=None,
                      include_attachments=False,
                      include_tasks=False,
                      epic_id=None):
    queryset = attach_total_points(queryset)
    queryset = attach_role_points(queryset)
    queryset = attach_epics(queryset)

    if include_attachments:
        queryset = attach_basic_attachments(queryset)
        queryset = queryset.extra(select={"include_attachments": "True"})

    if include_tasks:
        queryset = attach_tasks(queryset)
        queryset = queryset.extra(select={"include_tasks": "True"})

    if epic_id is not None:
        queryset = attach_epic_order(queryset, epic_id)
        queryset = queryset.extra(select={"include_epic_order": "True"})

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    queryset = attach_total_comments_to_queryset(queryset)
    return queryset
Example #5
0
    def attach_watchers_attrs_to_queryset(self, queryset):
        qs = attach_watchers_to_queryset(queryset)
        qs = attach_total_watchers_to_queryset(queryset)
        if self.request.user.is_authenticated():
            qs = attach_is_watcher_to_queryset(qs, self.request.user)

        return qs
Example #6
0
def attach_extra_info(queryset, user=None, include_attachments=False, include_tasks=False, epic_id=None):
    queryset = attach_total_points(queryset)
    queryset = attach_role_points(queryset)
    queryset = attach_epics(queryset)

    if include_attachments:
        queryset = attach_basic_attachments(queryset)
        queryset = queryset.extra(select={"include_attachments": "True"})

    if include_tasks:
        queryset = attach_tasks(queryset)
        queryset = queryset.extra(select={"include_tasks": "True"})

    if epic_id is not None:
        queryset = attach_epic_order(queryset, epic_id)
        queryset = queryset.extra(select={"include_epic_order": "True"})

    queryset = attach_total_attachments(queryset)
    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    queryset = attach_total_comments_to_queryset(queryset)
    return queryset
Example #7
0
    def attach_watchers_attrs_to_queryset(self, queryset):
        qs = attach_watchers_to_queryset(queryset)
        qs = attach_total_watchers_to_queryset(queryset)
        if self.request.user.is_authenticated():
            qs = attach_is_watcher_to_queryset(qs, self.request.user)

        return qs
Example #8
0
def epics_to_csv(project, queryset):
    csv_data = io.StringIO()
    fieldnames = ["id", "ref", "subject", "description", "owner", "owner_full_name",
                  "assigned_to", "assigned_to_full_name", "status", "epics_order",
                  "client_requirement", "team_requirement", "attachments", "tags",
                  "watchers", "voters", "created_date", "modified_date",
                  "related_user_stories"]

    custom_attrs = project.epiccustomattributes.all()
    for custom_attr in custom_attrs:
        fieldnames.append(custom_attr.name)

    queryset = queryset.prefetch_related("attachments",
                                         "custom_attributes_values",
                                         "user_stories__project")
    queryset = queryset.select_related("owner",
                                       "assigned_to",
                                       "status",
                                       "project")

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)

    writer = csv.DictWriter(csv_data, fieldnames=fieldnames)
    writer.writeheader()
    for epic in queryset:
        epic_data = {
            "id": epic.id,
            "ref": epic.ref,
            "subject": epic.subject,
            "description": epic.description,
            "owner": epic.owner.username if epic.owner else None,
            "owner_full_name": epic.owner.get_full_name() if epic.owner else None,
            "assigned_to": epic.assigned_to.username if epic.assigned_to else None,
            "assigned_to_full_name": epic.assigned_to.get_full_name() if epic.assigned_to else None,
            "status": epic.status.name if epic.status else None,
            "epics_order": epic.epics_order,
            "client_requirement": epic.client_requirement,
            "team_requirement": epic.team_requirement,
            "attachments": epic.attachments.count(),
            "tags": ",".join(epic.tags or []),
            "watchers": epic.watchers,
            "voters": epic.total_voters,
            "created_date": epic.created_date,
            "modified_date": epic.modified_date,
            "related_user_stories": ",".join([
                "{}#{}".format(us.project.slug, us.ref) for us in epic.user_stories.all()
            ]),
        }

        for custom_attr in custom_attrs:
            if not hasattr(epic, "custom_attributes_values"):
                continue
            value = epic.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
            epic_data[custom_attr.name] = value

        writer.writerow(epic_data)

    return csv_data
Example #9
0
def tasks_to_csv(project, queryset):
    csv_data = io.StringIO()
    fieldnames = ["ref", "subject", "description", "user_story", "sprint", "sprint_estimated_start",
                  "sprint_estimated_finish", "owner", "owner_full_name", "assigned_to",
                  "assigned_to_full_name", "status", "is_iocaine", "is_closed", "us_order",
                  "taskboard_order", "attachments", "external_reference", "tags", "watchers", "voters",
                  "created_date", "modified_date", "finished_date"]

    custom_attrs = project.taskcustomattributes.all()
    for custom_attr in custom_attrs:
        fieldnames.append(custom_attr.name)

    queryset = queryset.prefetch_related("attachments",
                                         "custom_attributes_values")
    queryset = queryset.select_related("milestone",
                                       "owner",
                                       "assigned_to",
                                       "status",
                                       "project")

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)

    writer = csv.DictWriter(csv_data, fieldnames=fieldnames)
    writer.writeheader()
    for task in queryset:
        task_data = {
            "ref": task.ref,
            "subject": task.subject,
            "description": task.description,
            "user_story": task.user_story.ref if task.user_story else None,
            "sprint": task.milestone.name if task.milestone else None,
            "sprint_estimated_start": task.milestone.estimated_start if task.milestone else None,
            "sprint_estimated_finish": task.milestone.estimated_finish if task.milestone else None,
            "owner": task.owner.username if task.owner else None,
            "owner_full_name": task.owner.get_full_name() if task.owner else None,
            "assigned_to": task.assigned_to.username if task.assigned_to else None,
            "assigned_to_full_name": task.assigned_to.get_full_name() if task.assigned_to else None,
            "status": task.status.name if task.status else None,
            "is_iocaine": task.is_iocaine,
            "is_closed": task.status is not None and task.status.is_closed,
            "us_order": task.us_order,
            "taskboard_order": task.taskboard_order,
            "attachments": task.attachments.count(),
            "external_reference": task.external_reference,
            "tags": ",".join(task.tags or []),
            "watchers": task.watchers,
            "voters": task.total_voters,
            "created_date": task.created_date,
            "modified_date": task.modified_date,
            "finished_date": task.finished_date,
        }
        for custom_attr in custom_attrs:
            value = task.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
            task_data[custom_attr.name] = value

        writer.writerow(task_data)

    return csv_data
Example #10
0
def epics_to_csv(project, queryset):
    csv_data = io.StringIO()
    fieldnames = ["id", "ref", "subject", "description", "owner", "owner_full_name",
                  "assigned_to", "assigned_to_full_name", "status", "epics_order",
                  "client_requirement", "team_requirement", "attachments", "tags",
                  "watchers", "voters", "created_date", "modified_date",
                  "related_user_stories"]

    custom_attrs = project.epiccustomattributes.all()
    for custom_attr in custom_attrs:
        fieldnames.append(custom_attr.name)

    queryset = queryset.prefetch_related("attachments",
                                         "custom_attributes_values",
                                         "user_stories__project")
    queryset = queryset.select_related("owner",
                                       "assigned_to",
                                       "status",
                                       "project")

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)

    writer = csv.DictWriter(csv_data, fieldnames=fieldnames)
    writer.writeheader()
    for epic in queryset:
        epic_data = {
            "id": epic.id,
            "ref": epic.ref,
            "subject": epic.subject,
            "description": epic.description,
            "owner": epic.owner.username if epic.owner else None,
            "owner_full_name": epic.owner.get_full_name() if epic.owner else None,
            "assigned_to": epic.assigned_to.username if epic.assigned_to else None,
            "assigned_to_full_name": epic.assigned_to.get_full_name() if epic.assigned_to else None,
            "status": epic.status.name if epic.status else None,
            "epics_order": epic.epics_order,
            "client_requirement": epic.client_requirement,
            "team_requirement": epic.team_requirement,
            "attachments": epic.attachments.count(),
            "tags": ",".join(epic.tags or []),
            "watchers": epic.watchers,
            "voters": epic.total_voters,
            "created_date": epic.created_date,
            "modified_date": epic.modified_date,
            "related_user_stories": ",".join([
                "{}#{}".format(us.project.slug, us.ref) for us in epic.user_stories.all()
            ]),
        }

        for custom_attr in custom_attrs:
            if not hasattr(epic, "custom_attributes_values"):
                continue
            value = epic.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
            epic_data[custom_attr.name] = value

        writer.writerow(epic_data)

    return csv_data
Example #11
0
def tasks_to_csv(project, queryset):
    csv_data = io.StringIO()
    fieldnames = ["ref", "subject", "description", "user_story", "sprint", "sprint_estimated_start",
                  "sprint_estimated_finish", "owner", "owner_full_name", "assigned_to",
                  "assigned_to_full_name", "status", "is_iocaine", "is_closed", "us_order",
                  "taskboard_order", "attachments", "external_reference", "tags", "watchers", "voters",
                  "created_date", "modified_date", "finished_date"]

    custom_attrs = project.taskcustomattributes.all()
    for custom_attr in custom_attrs:
        fieldnames.append(custom_attr.name)

    queryset = queryset.prefetch_related("attachments",
                                         "custom_attributes_values")
    queryset = queryset.select_related("milestone",
                                       "owner",
                                       "assigned_to",
                                       "status",
                                       "project")

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)

    writer = csv.DictWriter(csv_data, fieldnames=fieldnames)
    writer.writeheader()
    for task in queryset:
        task_data = {
            "ref": task.ref,
            "subject": task.subject,
            "description": task.description,
            "user_story": task.user_story.ref if task.user_story else None,
            "sprint": task.milestone.name if task.milestone else None,
            "sprint_estimated_start": task.milestone.estimated_start if task.milestone else None,
            "sprint_estimated_finish": task.milestone.estimated_finish if task.milestone else None,
            "owner": task.owner.username if task.owner else None,
            "owner_full_name": task.owner.get_full_name() if task.owner else None,
            "assigned_to": task.assigned_to.username if task.assigned_to else None,
            "assigned_to_full_name": task.assigned_to.get_full_name() if task.assigned_to else None,
            "status": task.status.name if task.status else None,
            "is_iocaine": task.is_iocaine,
            "is_closed": task.status is not None and task.status.is_closed,
            "us_order": task.us_order,
            "taskboard_order": task.taskboard_order,
            "attachments": task.attachments.count(),
            "external_reference": task.external_reference,
            "tags": ",".join(task.tags or []),
            "watchers": task.watchers,
            "voters": task.total_voters,
            "created_date": task.created_date,
            "modified_date": task.modified_date,
            "finished_date": task.finished_date,
        }
        for custom_attr in custom_attrs:
            value = task.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
            task_data[custom_attr.name] = value

        writer.writerow(task_data)

    return csv_data
Example #12
0
def attach_extra_info(queryset, user=None):
    queryset = attach_generated_user_stories(queryset)
    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    return queryset
Example #13
0
def attach_extra_info(queryset, user=None):
    queryset = attach_generated_user_stories(queryset)
    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    return queryset
Example #14
0
def issues_to_csv(project, queryset):
    csv_data = io.StringIO()
    fieldnames = ["ref", "subject", "description", "sprint", "sprint_estimated_start",
                  "sprint_estimated_finish", "owner", "owner_full_name", "assigned_to",
                  "assigned_to_full_name", "status", "severity", "priority", "type",
                  "is_closed", "attachments", "external_reference", "tags", "watchers",
                  "voters", "created_date", "modified_date", "finished_date"]

    custom_attrs = project.issuecustomattributes.all()
    for custom_attr in custom_attrs:
        fieldnames.append(custom_attr.name)

    queryset = queryset.prefetch_related("attachments",
                                         "generated_user_stories",
                                         "custom_attributes_values")
    queryset = queryset.select_related("owner",
                                       "assigned_to",
                                       "status",
                                       "project")
    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)

    writer = csv.DictWriter(csv_data, fieldnames=fieldnames)
    writer.writeheader()
    for issue in queryset:
        issue_data = {
            "ref": issue.ref,
            "subject": issue.subject,
            "description": issue.description,
            "sprint": issue.milestone.name if issue.milestone else None,
            "sprint_estimated_start": issue.milestone.estimated_start if issue.milestone else None,
            "sprint_estimated_finish": issue.milestone.estimated_finish if issue.milestone else None,
            "owner": issue.owner.username if issue.owner else None,
            "owner_full_name": issue.owner.get_full_name() if issue.owner else None,
            "assigned_to": issue.assigned_to.username if issue.assigned_to else None,
            "assigned_to_full_name": issue.assigned_to.get_full_name() if issue.assigned_to else None,
            "status": issue.status.name if issue.status else None,
            "severity": issue.severity.name,
            "priority": issue.priority.name,
            "type": issue.type.name,
            "is_closed": issue.is_closed,
            "attachments": issue.attachments.count(),
            "external_reference": issue.external_reference,
            "tags": ",".join(issue.tags or []),
            "watchers": issue.watchers,
            "voters": issue.total_voters,
            "created_date": issue.created_date,
            "modified_date": issue.modified_date,
            "finished_date": issue.finished_date,
        }

        for custom_attr in custom_attrs:
            value = issue.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
            issue_data[custom_attr.name] = value

        writer.writerow(issue_data)

    return csv_data
Example #15
0
def issues_to_csv(project, queryset):
    csv_data = io.StringIO()
    fieldnames = ["ref", "subject", "description", "sprint", "sprint_estimated_start",
                  "sprint_estimated_finish", "owner", "owner_full_name", "assigned_to",
                  "assigned_to_full_name", "status", "severity", "priority", "type",
                  "is_closed", "attachments", "external_reference", "tags", "watchers",
                  "voters", "created_date", "modified_date", "finished_date"]

    custom_attrs = project.issuecustomattributes.all()
    for custom_attr in custom_attrs:
        fieldnames.append(custom_attr.name)

    queryset = queryset.prefetch_related("attachments",
                                         "generated_user_stories",
                                         "custom_attributes_values")
    queryset = queryset.select_related("owner",
                                       "assigned_to",
                                       "status",
                                       "project")
    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)

    writer = csv.DictWriter(csv_data, fieldnames=fieldnames)
    writer.writeheader()
    for issue in queryset:
        issue_data = {
            "ref": issue.ref,
            "subject": issue.subject,
            "description": issue.description,
            "sprint": issue.milestone.name if issue.milestone else None,
            "sprint_estimated_start": issue.milestone.estimated_start if issue.milestone else None,
            "sprint_estimated_finish": issue.milestone.estimated_finish if issue.milestone else None,
            "owner": issue.owner.username if issue.owner else None,
            "owner_full_name": issue.owner.get_full_name() if issue.owner else None,
            "assigned_to": issue.assigned_to.username if issue.assigned_to else None,
            "assigned_to_full_name": issue.assigned_to.get_full_name() if issue.assigned_to else None,
            "status": issue.status.name if issue.status else None,
            "severity": issue.severity.name,
            "priority": issue.priority.name,
            "type": issue.type.name,
            "is_closed": issue.is_closed,
            "attachments": issue.attachments.count(),
            "external_reference": issue.external_reference,
            "tags": ",".join(issue.tags or []),
            "watchers": issue.watchers,
            "voters": issue.total_voters,
            "created_date": issue.created_date,
            "modified_date": issue.modified_date,
            "finished_date": issue.finished_date,
        }

        for custom_attr in custom_attrs:
            value = issue.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
            issue_data[custom_attr.name] = value

        writer.writerow(issue_data)

    return csv_data
Example #16
0
def attach_extra_info(queryset, user=None, include_attachments=False):
    if include_attachments:
        queryset = attach_basic_attachments(queryset)
        queryset = queryset.extra(select={"include_attachments": "True"})

    queryset = attach_generated_user_stories(queryset)
    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    return queryset
Example #17
0
def attach_extra_info(queryset, user=None, include_attachments=False):
    if include_attachments:
        queryset = attach_basic_attachments(queryset)
        queryset = queryset.extra(select={"include_attachments": "True"})

    queryset = attach_user_stories_counts_to_queryset(queryset)
    queryset = attach_child_epics_counts_to_queryset(queryset)
    queryset = attach_epic_progress_to_queryset(queryset)
    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    return queryset
Example #18
0
def attach_extra_info(queryset, user=None, include_attachments=False, include_tasks=False):
    queryset = attach_total_points(queryset)
    queryset = attach_role_points(queryset)

    if include_attachments:
        queryset = attach_basic_attachments(queryset)
        queryset = queryset.extra(select={"include_attachments": "True"})

    if include_tasks:
        queryset = attach_tasks(queryset)
        queryset = queryset.extra(select={"include_tasks": "True"})

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    return queryset
Example #19
0
def attach_extra_info(queryset, user=None, include_attachments=False, include_tasks=False):
    queryset = attach_total_points(queryset)
    queryset = attach_role_points(queryset)

    if include_attachments:
        queryset = attach_basic_attachments(queryset)
        queryset = queryset.extra(select={"include_attachments": "True"})

    if include_tasks:
        queryset = attach_tasks(queryset)
        queryset = queryset.extra(select={"include_tasks": "True"})

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_voter_to_queryset(queryset, user)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    return queryset
Example #20
0
def promote_to_us(source_obj):
    model_class = source_obj.__class__
    queryset = model_class.objects.filter(pk=source_obj.id)
    queryset = queryset.prefetch_related("attachments")
    queryset = queryset.select_related("owner", "assigned_to", "project")
    queryset = attach_watchers_to_queryset(queryset)

    us_refs = []
    for obj in queryset:
        us = UserStory.objects.create(
            generated_from_issue_id=obj.id
            if isinstance(source_obj, Issue) else None,
            from_task_ref=_("Task #%(ref)s") %
            {"ref": obj.ref} if isinstance(source_obj, Task) else None,
            project=obj.project,
            owner=obj.owner,
            subject=obj.subject,
            description=obj.description,
            tags=obj.tags,
            milestone=obj.milestone,
        )

        content_type = apps.get_model("contenttypes",
                                      "ContentType").objects.get_for_model(us)

        # add data only for task conversion
        if isinstance(source_obj, Task):
            us.due_date = obj.due_date
            us.due_date_reason = obj.due_date_reason
            us.is_blocked = obj.is_blocked
            us.blocked_note = obj.blocked_note
            us.save()

            _import_votes(obj, us)

        _import_assigned(obj, us)
        _import_comments(obj, us)
        _import_attachments(obj, us, content_type)
        _import_watchers(obj, us, content_type)

        us_refs.append(us.ref)

    return us_refs
Example #21
0
def userstories_to_csv(project, queryset):
    csv_data = io.StringIO()
    fieldnames = [
        "id", "ref", "subject", "description", "sprint_id", "sprint",
        "sprint_estimated_start", "sprint_estimated_finish", "owner",
        "owner_full_name", "assigned_to", "assigned_to_full_name",
        "assigned_users", "assigned_users_full_name", "status", "is_closed"
    ]

    roles = project.roles.filter(computable=True).order_by('slug')
    for role in roles:
        fieldnames.append("{}-points".format(role.slug))

    fieldnames.append("total-points")

    fieldnames += [
        "backlog_order", "sprint_order", "kanban_order", "created_date",
        "modified_date", "finish_date", "client_requirement",
        "team_requirement", "attachments", "generated_from_issue",
        "generated_from_task", "external_reference", "tasks", "tags",
        "watchers", "voters", "due_date", "due_date_reason"
    ]

    custom_attrs = project.userstorycustomattributes.all()
    for custom_attr in custom_attrs:
        fieldnames.append(custom_attr.name)

    queryset = queryset.prefetch_related("role_points", "role_points__points",
                                         "role_points__role", "tasks",
                                         "attachments",
                                         "custom_attributes_values")
    queryset = queryset.select_related("milestone", "project", "status",
                                       "owner", "assigned_to",
                                       "generated_from_issue",
                                       "generated_from_task")

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)

    writer = csv.DictWriter(csv_data, fieldnames=fieldnames)
    writer.writeheader()
    for us in queryset:
        row = {
            "id":
            us.id,
            "ref":
            us.ref,
            "subject":
            us.subject,
            "description":
            us.description,
            "sprint_id":
            us.milestone.id if us.milestone else None,
            "sprint":
            us.milestone.name if us.milestone else None,
            "sprint_estimated_start":
            us.milestone.estimated_start if us.milestone else None,
            "sprint_estimated_finish":
            us.milestone.estimated_finish if us.milestone else None,
            "owner":
            us.owner.username if us.owner else None,
            "owner_full_name":
            us.owner.get_full_name() if us.owner else None,
            "assigned_to":
            us.assigned_to.username if us.assigned_to else None,
            "assigned_to_full_name":
            us.assigned_to.get_full_name() if us.assigned_to else None,
            "assigned_users":
            ",".join([
                assigned_user.username
                for assigned_user in us.assigned_users.all()
            ]),
            "assigned_users_full_name":
            ",".join([
                assigned_user.get_full_name()
                for assigned_user in us.assigned_users.all()
            ]),
            "status":
            us.status.name if us.status else None,
            "is_closed":
            us.is_closed,
            "backlog_order":
            us.backlog_order,
            "sprint_order":
            us.sprint_order,
            "kanban_order":
            us.kanban_order,
            "created_date":
            us.created_date,
            "modified_date":
            us.modified_date,
            "finish_date":
            us.finish_date,
            "client_requirement":
            us.client_requirement,
            "team_requirement":
            us.team_requirement,
            "attachments":
            us.attachments.count(),
            "generated_from_issue":
            us.generated_from_issue.ref if us.generated_from_issue else None,
            "generated_from_task":
            us.generated_from_task.ref if us.generated_from_task else None,
            "external_reference":
            us.external_reference,
            "tasks":
            ",".join([str(task.ref) for task in us.tasks.all()]),
            "tags":
            ",".join(us.tags or []),
            "watchers":
            us.watchers,
            "voters":
            us.total_voters,
            "due_date":
            us.due_date,
            "due_date_reason":
            us.due_date_reason,
        }

        us_role_points_by_role_id = {
            us_rp.role.id: us_rp.points.value
            for us_rp in us.role_points.all()
        }
        for role in roles:
            row["{}-points".format(role.slug)] = \
                us_role_points_by_role_id.get(role.id, 0)

        row['total-points'] = us.get_total_points()

        for custom_attr in custom_attrs:
            value = us.custom_attributes_values.attributes_values.get(
                str(custom_attr.id), None)
            row[custom_attr.name] = value

        writer.writerow(row)

    return csv_data
Example #22
0
    def attach_watchers_attrs_to_queryset(self, queryset):
        qs = attach_watchers_to_queryset(queryset)
        if self.request.user.is_authenticated():
            qs = attach_is_watched_to_queryset(self.request.user, qs)

        return qs
Example #23
0
def attach_extra_info(queryset, user=None, include_attachments=False):
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    return queryset
Example #24
0
def issues_to_csv(project, queryset, type, status):
    csv_data = io.StringIO()
    

    queryset = queryset.prefetch_related("attachments",
                                         "generated_user_stories",
                                         "custom_attributes_values")
    queryset = queryset.select_related("owner",
                                       "assigned_to",
                                       "status",
                                       "project",
                                       "type")
    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)

    if type == 'Issue':
        fieldnames = ["Sr.No", "Project Name", "Chainage From (In Km)", "Chainage To (In Km)", "Direction", "Description of Issue",
                              "Photograph During Inspection", "Asset Type", "Performance Parameter (Type of Issue)",
                              "Issue Raised On (Date)", "Issue Raised By (Name of Concessionaire)", "description",
                              "Issue Raised To (Assignee Name Max Upto 3 Persons)"]

    if type == 'Issue' and status:
        fieldnames = ["Sr.No", "Project Name", "Chainage From (In Km)", "Chainage To (In Km)", "Direction", "Description of Issue",
                          "Photograph During Inspection", "Asset Type", "Performance Parameter (Type of Issue)",
                          "Issue Raised On (Date)", "Issue Raised By (Name of Concessionaire)",
                          "Issue Raised To (Assignee Name Max Upto 3 Persons)" , "Timeline",
                          "Target Date", "Status",
                          "Issue Closed On Date", "Complianced", "Issue Closed By",
                          "Photograph Post Compliance", "Remark", "Current Status","Description Of Compliance" ]
    if type == 'Investigation':
        fieldnames = ["Sr.No", "Project Name", "Chainage From (In Km)", "Chainage To (In Km)", "Direction", "Description of Issue",
                          "Photograph During Inspection", "Asset Type", "Performance Parameter(Type of Issue)",
                          "Issue Raised On", "Name of Test", "Testing Method", "Standard References for testing",
                          "Test Carried Out Date", "Testing Carried Out By(Name)", "Remark", "Outcome Report"]
        

    if type == 'Accident':
        fieldnames = ["Sr.No", "Description","No of Accidents previous month","No of Peoples affected previous month","No of Accidents during this month",
                        "No of Peoples affected during this month", "No of Accidents upto this month", "No of Peoples affected upto this month"]

    custom_attrs = project.issuecustomattributes.all()
        
    for custom_attr in custom_attrs:
        fieldnames.append(custom_attr.name)
    
    writer = csv.DictWriter(csv_data, fieldnames=fieldnames)
    writer.writeheader()

    animals_killed_count = 0
    
    for issue in queryset:
        if issue:
            qqq = issue.watchers
            watchers = []
            new_watcher_list =  ""
            watcher_username =""
            if issue.assigned_to:
                watcher_username = '******'+issue.assigned_to.full_name
            for i in qqq:
                sql = User.objects.get(id=int(i))
                watchers.append(sql.full_name)
            for j in range(len(watchers)):
                watcher_username = str(j+2)+'. '+watchers[j] +','+ watcher_username
            
            split = watcher_username.split(',')

            for i in range(len(split)):
                new_watcher_list = split[i] +'\n'+ new_watcher_list 

            if issue.type.name == type:
                if issue.attachments:
                    file_name = "" 
                    files = []
                    file = issue.attachments.filter(project__id=issue.project.id).values_list('attached_file')
                    for i in file:
                        files.extend(i)
                    #     for j in len(file):
                    #         files.append(file[j])
                    for j in files:
                        file_name = os.path.join(settings.MEDIA_URL,str(j)) +'\n' + file_name
                else:
                    file_name=""
                Raised_date = datetime.strftime(issue.created_date.date(),"%d-%m-%Y")

                issue_data = {
                    "Sr.No" : issue.ref,
                    "Project Name" : issue.project.name,
                    "Chainage From (In Km)" : issue.chainage_from,
                    "Chainage To (In Km)" : issue.chainage_to,
                    "Direction" : issue.chainage_side,
                    "Description of Issue" : issue.description,
                    "Photograph During Inspection" : file_name if issue.attachments else None,
                    "Asset Type" : issue.issue_category,
                    "Performance Parameter (Type of Issue)" : issue.issue_subcategory,
                    "Issue Raised On (Date)" : Raised_date,
                    "Issue Raised By (Name of Concessionaire)" : issue.owner.full_name if issue.owner else None,
                    "Issue Raised To (Assignee Name Max Upto 3 Persons)" : new_watcher_list,
                }
                
        if issue.type.name==type and status:
            qqqq = issue.watchers
            watchers = []
            new_watcher_list =  ""
            watcher_username =""
            if issue.assigned_to:
                watcher_username = '******'+issue.assigned_to.full_name
            for i in qqq:
                sql = User.objects.get(id=int(i))
                watchers.append(sql.full_name)
            for j in range(len(watchers)):
                watcher_username = str(j+2)+'. '+watchers[j] +','+ watcher_username
            
            split = watcher_username.split(',')

            for i in range(len(split)):
                new_watcher_list = split[i] +'\n'+ new_watcher_list 
            a = issue.created_date.date()
            b = datetime.strptime(issue.target_date,"%d/%m/%Y").date()
            timeline = b-a
            target_date = datetime.strftime(b,"%d-%m-%Y")
            if issue.attachments:
                file_name = "" 
                files = []
                file = issue.attachments.filter(project_id=issue.project.id).values_list('attached_file')
                for i in file:
                    files.extend(i)
                #     for j in len(file):
                #         files.append(file[j])
                for j in files:
                    file_name = os.path.join(settings.MEDIA_URL,str(j)) +'\n' + file_name
            else:
                file_name=""
            status_name = []
            status_names =  project.issues.filter(status__id__in=status)
            new_status_name =[]
            for name in status_names:
                
                if str(name.status) == 'Closed':
                    new_status_name.append('Open')
                    # new_status_name += 'Open'
                     
                elif str(name.status) == 'Maintenance Closed':
                    # new_status_name += 'Closed'
                    new_status_name.append('Closed')
                    
                elif str(name.status) == 'Maintenance Pending':
                    # new_status_name += 'Pending'
                    new_status_name.append('Pending')
            if new_status_name:
                new =""
                for i in new_status_name:
                    new = i
            issue_data = {
            "Sr.No" : issue.ref,
            "Project Name" : issue.project.name,
            "Chainage From (In Km)" : issue.chainage_from,
            "Chainage To (In Km)" : issue.chainage_to,
            "Direction" : issue.chainage_side,
            "Description of Issue" : issue.description,
            "Photograph During Inspection" : file_name,
            "Asset Type" : issue.issue_category,
            "Performance Parameter (Type of Issue)" : issue.issue_subcategory,
            "Issue Raised On (Date)" : issue.created_date.date(),
            "Issue Raised By (Name of Concessionaire)" : issue.owner.full_name if issue.owner else None,
            "Issue Raised To (Assignee Name Max Upto 3 Persons)" : new_watcher_list,
            "Timeline" : timeline,
            "Target Date" : target_date,
            "Status" :new if issue.status else None,
            "Issue Closed On Date" : issue.finished_date if status_name=='Closed' else None,
            "Complianced" : 'Yes' if issue.compliance_is_update==True else 'No',
            "Issue Closed By" : issue.assigned_to.full_name if issue.assigned_to else None,
            "Description Of Compliance": issue.compliance_description,
            "Photograph Post Compliance" : issue.attachments.name,
            "Remark":"",
            "Current Status" : new if issue.status else None,
        }

          
        if issue.type.name == 'Investigation':
            issue_data = {
                "Sr.No" : issue.ref,
                "Project Name" :   issue.project.name,
                "Chainage From (In Km)" : issue.investigation_chainage_from,
                "Chainage To (In Km)" : issue.investigation_chainage_to,
                "Direction" : issue.investigation_chainage_side,
                "Description of Issue" : issue.investigation_description,
                "Asset Type" : issue.asset_name,
                "Performance Parameter(Type of Issue)" : issue.test_name,
                "Name of Test" : "",
                "Testing Method" : "",
                "Standard References for testing" : "",
                "Test Carried Out Date" :"",
                "Testing Carried Out By(Name)" :issue.assigned_to.username if issue.assigned_to else None,
                "Outcome Report" : "",
                "Remark" :"",
            }


            

        if issue.type.name == 'Accident':
            last_day_of_prev_month = date.today().replace(day=1) - timedelta(days=1)
            first_date_of_previos_month = date.today().replace(day=1) - timedelta(days=last_day_of_prev_month.day)
            first_date = date.today().replace(day=1)
            current_date = date.today()
            previous_month = first_date_of_previos_month
            Previous_last_date = last_day_of_prev_month
            animals_killed_last_month = project.issues.filter(created_date__date__range=[previous_month,Previous_last_date],type__name='Accident').values_list('animals_killed', flat=True)
            
            animal_list_last_month = list(animals_killed_last_month)
            new_list_last = []
            
            if animals_killed_last_month:
                for i in animals_killed_last_month:
                    if i:
                        new_list_last.append(int(i))


            animals_killed_cuurent_month = project.issues.filter(created_date__date__range=[first_date,current_date],type__name='Accident').values_list('animals_killed', flat=True)
            animal_list_current_month = list(animals_killed_cuurent_month)
            new_list_current = []
            if animals_killed_cuurent_month:
                for i in animal_list_current_month:
                    if i:
                        new_list_current.append(int(i))


            animals_killed_upto_month = project.issues.filter(type__name='Accident').values_list('animals_killed', flat=True)

            animal_list_upto_month = list(animals_killed_upto_month)
            new_list_upto = []
            if animals_killed_upto_month:
                for i in animal_list_upto_month:
                    if i:
                        new_list_upto.append(int(i))
            
            issue_data = {
                "Sr.No" : issue.ref,
                "Description" : issue.accident_classification,
                "No of Accidents previous month":project.issues.filter(type__name='Accident',created_date__date__range=[previous_month,Previous_last_date]).count(),
                "No of Peoples affected previous month": sum(new_list_last),
                "No of Accidents during this month":project.issues.filter(type__name='Accident',created_date__date__range=[first_date,current_date]).count(),
                "No of Peoples affected during this month": sum(new_list_current),
                "No of Accidents upto this month":project.issues.filter(type__name='Accident').count(),
                "No of Peoples affected upto this month": sum(new_list_upto),

            }
        for custom_attr in custom_attrs:
            value = issue.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
            issue_data[custom_attr.name] = value

        writer.writerow(issue_data) 

    return csv_data
Example #25
0
    def attach_watchers_attrs_to_queryset(self, queryset):
        qs = attach_watchers_to_queryset(queryset)
        if self.request.user.is_authenticated():
            qs = attach_is_watched_to_queryset(self.request.user, qs)

        return qs
Example #26
0
def userstories_to_csv(project, queryset):
    csv_data = io.StringIO()
    fieldnames = ["ref", "subject", "description", "sprint", "sprint_estimated_start",
                  "sprint_estimated_finish", "owner", "owner_full_name", "assigned_to",
                  "assigned_to_full_name", "status", "is_closed"]

    roles = project.roles.filter(computable=True).order_by('slug')
    for role in roles:
        fieldnames.append("{}-points".format(role.slug))

    fieldnames.append("total-points")

    fieldnames += ["backlog_order", "sprint_order", "kanban_order",
                   "created_date", "modified_date", "finish_date",
                   "client_requirement", "team_requirement", "attachments",
                   "generated_from_issue", "external_reference", "tasks",
                   "tags", "watchers", "voters"]

    custom_attrs = project.userstorycustomattributes.all()
    for custom_attr in custom_attrs:
        fieldnames.append(custom_attr.name)

    queryset = queryset.prefetch_related("role_points",
                                         "role_points__points",
                                         "role_points__role",
                                         "tasks",
                                         "attachments",
                                         "custom_attributes_values")
    queryset = queryset.select_related("milestone",
                                       "project",
                                       "status",
                                       "owner",
                                       "assigned_to",
                                       "generated_from_issue")

    queryset = attach_total_voters_to_queryset(queryset)
    queryset = attach_watchers_to_queryset(queryset)

    writer = csv.DictWriter(csv_data, fieldnames=fieldnames)
    writer.writeheader()
    for us in queryset:
        row = {
            "ref": us.ref,
            "subject": us.subject,
            "description": us.description,
            "sprint": us.milestone.name if us.milestone else None,
            "sprint_estimated_start": us.milestone.estimated_start if us.milestone else None,
            "sprint_estimated_finish": us.milestone.estimated_finish if us.milestone else None,
            "owner": us.owner.username if us.owner else None,
            "owner_full_name": us.owner.get_full_name() if us.owner else None,
            "assigned_to": us.assigned_to.username if us.assigned_to else None,
            "assigned_to_full_name": us.assigned_to.get_full_name() if us.assigned_to else None,
            "status": us.status.name if us.status else None,
            "is_closed": us.is_closed,
            "backlog_order": us.backlog_order,
            "sprint_order": us.sprint_order,
            "kanban_order": us.kanban_order,
            "created_date": us.created_date,
            "modified_date": us.modified_date,
            "finish_date": us.finish_date,
            "client_requirement": us.client_requirement,
            "team_requirement": us.team_requirement,
            "attachments": us.attachments.count(),
            "generated_from_issue": us.generated_from_issue.ref if us.generated_from_issue else None,
            "external_reference": us.external_reference,
            "tasks": ",".join([str(task.ref) for task in us.tasks.all()]),
            "tags": ",".join(us.tags or []),
            "watchers": us.watchers,
            "voters": us.total_voters,
        }

        us_role_points_by_role_id = {us_rp.role.id: us_rp.points.value for us_rp in us.role_points.all()}
        for role in roles:
            row["{}-points".format(role.slug)] = us_role_points_by_role_id.get(role.id, 0)

        row['total-points'] = us.get_total_points()

        for custom_attr in custom_attrs:
            value = us.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
            row[custom_attr.name] = value

        writer.writerow(row)

    return csv_data
Example #27
0
def attach_extra_info(queryset, user=None, include_attachments=False):
    queryset = attach_watchers_to_queryset(queryset)
    queryset = attach_total_watchers_to_queryset(queryset)
    queryset = attach_is_watcher_to_queryset(queryset, user)
    return queryset