Ejemplo n.º 1
0
def attach(request):
    file_id = request.POST['file_id']
    attach_file_name = Feed.get_attach_file_name(file_id)
    attach_file_path = Feed.get_attach_file_path(file_id)
    # response作成
    with open(attach_file_path, 'rb') as fp:
        response = HttpResponse(fp.read(),
                                content_type='application/octet-stream')
        response['Content-Disposition'] = 'attachment; filename=%s' % (
            attach_file_name)
    return response
Ejemplo n.º 2
0
def attach(request):
    file_id = request.POST['file_id']
    attach_file_name = Feed.get_attach_file_name(file_id)
    attach_file_path = Feed.get_attach_file_path(file_id).encode('utf-8')
    # response作成
    with open(attach_file_path, 'rb') as fp:
        response = HttpResponse(fp.read(),
                                content_type='application/octet-stream')
        dl_file_name = urllib.parse.quote(attach_file_name)
        response[
            'Content-Disposition'] = "attachment; filename='{}'; filename*=UTF-8''{}".format(
                dl_file_name, dl_file_name)
    return response
Ejemplo n.º 3
0
def call_jira(request):
    try:
        # JIRA が import されていない場合は何もしない
        if imported_jira is None:
            rsp = {}
            return JsonResponse(rsp)
        # feed情報取得
        feed_file_name_id = request.GET['feed_id']
        package_id_arg = request.GET['package_id']
        feed = Feed.get_feeds_from_package_id(request.user, package_id_arg)

        # JIRA instance
        proxies = System.get_request_proxies()
        j = JIRA(server=SNSConfig.get_jira_host(),
                 proxies=proxies,
                 basic_auth=(SNSConfig.get_jira_username(),
                             SNSConfig.get_jira_password()))
        # issues作成
        issue = j.create_issue(project=SNSConfig.get_jira_project(),
                               summary=feed.title,
                               description=feed.post,
                               issuetype={'name': SNSConfig.get_jira_type()})
        # 添付があればそれもつける
        for attach_file in feed.files.all():
            file_path = Feed.get_attach_file_path(attach_file.package_id)
            j.add_attachment(issue=issue,
                             attachment=file_path,
                             filename=str(attach_file.file_name))

        # STIX添付
        stix_package = STIXPackage.from_xml(feed.stix_file_path)
        package_id = stix_package.id_
        stix_file_name = '%s.xml' % (package_id)
        j.add_attachment(issue=issue,
                         attachment=feed.stix_file_path,
                         filename=stix_file_name)

        # CSV添付
        # CSVの中身を取得する
        content = get_csv_content(feed_file_name_id)
        csv_attachment = io.StringIO()
        csv_attachment.write(content)
        csv_file_name = '%s.csv' % (package_id)
        j.add_attachment(issue=issue,
                         attachment=csv_attachment,
                         filename=csv_file_name)

        # PDF添付
        feed_pdf = FeedPDF(feed, stix_package)
        pdf_attachment = io.BytesIO()
        feed_pdf.make_pdf_content(pdf_attachment, feed)
        pdf_file_name = '%s.pdf' % (package_id)
        j.add_attachment(issue=issue,
                         attachment=pdf_attachment,
                         filename=pdf_file_name)

        # isssue番号返却
        url = SNSConfig.get_jira_host(
        ) + '/projects/' + SNSConfig.get_jira_project() + '/issues/' + str(
            issue)
        rsp = {
            'issues': str(issue),
            'url': url,
        }
        return JsonResponse(rsp)
    except Exception as e:
        traceback.print_exc()
        return HttpResponseServerError(str(e))