當前位置: 首頁>>代碼示例>>Python>>正文


Python Target.to_dict方法代碼示例

本文整理匯總了Python中crits.targets.target.Target.to_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python Target.to_dict方法的具體用法?Python Target.to_dict怎麽用?Python Target.to_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在crits.targets.target.Target的用法示例。


在下文中一共展示了Target.to_dict方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_target_details

# 需要導入模塊: from crits.targets.target import Target [as 別名]
# 或者: from crits.targets.target.Target import to_dict [as 別名]
def get_target_details(email_address, analyst):
    """
    Generate the data to render the Target details template.

    :param email_address: The email address of the target.
    :type email_address: str
    :param analyst: The user requesting this information.
    :type analyst: str
    :returns: template (str), arguments (dict)
    """

    template = None
    if not email_address:
        template = "error.html"
        args = {'error': "Must provide an email address."}
        return template, args

    # check for exact match first
    target = Target.objects(email_address=email_address).first()

    if not target: # if no exact match, look for case-insensitive match
        target = Target.objects(email_address__iexact=email_address).first()
    if not target:
        target = Target()
        target.email_address = email_address.strip().lower()
        form = TargetInfoForm(initial={'email_address': email_address})
    email_list = target.find_emails(analyst)
    form = TargetInfoForm(initial=target.to_dict())

    if form.fields.get(form_consts.Common.BUCKET_LIST_VARIABLE_NAME) != None:
        form.fields.pop(form_consts.Common.BUCKET_LIST_VARIABLE_NAME)

    if form.fields.get(form_consts.Common.TICKET_VARIABLE_NAME) != None:
        form.fields.pop(form_consts.Common.TICKET_VARIABLE_NAME)

    subscription = {
        'type': 'Target',
        'id': target.id,
        'subscribed': is_user_subscribed("%s" % analyst,
                                            'Target',
                                            target.id)
    }

    #objects
    objects = target.sort_objects()

    #relationships
    relationships = target.sort_relationships("%s" % analyst,
                                                meta=True)

    # relationship
    relationship = {
            'type': 'Target',
            'value': target.id
    }

    #comments
    if target.id:
        comments = {'comments': target.get_comments(),
                    'url_key': email_address}
    else:
        comments = {'comments': [],
                    'url_key': email_address}

    #screenshots
    screenshots = target.get_screenshots(analyst)

    # favorites
    favorite = is_user_favorite("%s" % analyst, 'Target', target.id)

    # analysis results
    service_results = target.get_analysis_results()

    args = {'objects': objects,
            'relationships': relationships,
            'relationship': relationship,
            'comments': comments,
            'favorite': favorite,
            'subscription': subscription,
            'screenshots': screenshots,
            'email_list': email_list,
            'target_detail': target,
            'service_results': service_results,
            'form': form}

    return template, args
開發者ID:ckane,項目名稱:crits,代碼行數:88,代碼來源:handlers.py

示例2: get_target_details

# 需要導入模塊: from crits.targets.target import Target [as 別名]
# 或者: from crits.targets.target.Target import to_dict [as 別名]
def get_target_details(email_address, analyst):
    """
    Generate the data to render the Target details template.

    :param email_address: The email address of the target.
    :type email_address: str
    :param analyst: The user requesting this information.
    :type analyst: str
    :returns: template (str), arguments (dict)
    """

    template = None
    if not email_address:
        template = "error.html"
        args = {"error": "Must provide an email address."}
        return template, args
    target = Target.objects(email_address=email_address).first()
    if not target:
        target = Target()
        target.email_address = email_address
        form = TargetInfoForm(initial={"email_address": email_address})
    email_list = target.find_emails(analyst)
    # initial_data = target.to_dict()
    # initial_data['bucket_list'] = target.get_bucket_list_string();
    form = TargetInfoForm(initial=target.to_dict())

    if form.fields.get(form_consts.Common.BUCKET_LIST_VARIABLE_NAME) != None:
        form.fields.pop(form_consts.Common.BUCKET_LIST_VARIABLE_NAME)

    if form.fields.get(form_consts.Common.TICKET_VARIABLE_NAME) != None:
        form.fields.pop(form_consts.Common.TICKET_VARIABLE_NAME)

    subscription = {
        "type": "Target",
        "id": target.id,
        "subscribed": is_user_subscribed("%s" % analyst, "Target", target.id),
    }

    # objects
    objects = target.sort_objects()

    # relationships
    relationships = target.sort_relationships("%s" % analyst, meta=True)

    # relationship
    relationship = {"type": "Target", "value": target.id}

    # comments
    if target.id:
        comments = {"comments": target.get_comments(), "url_key": email_address}
    else:
        comments = {"comments": [], "url_key": email_address}

    # screenshots
    screenshots = target.get_screenshots(analyst)

    # favorites
    favorite = is_user_favorite("%s" % analyst, "Target", target.id)

    args = {
        "objects": objects,
        "relationships": relationships,
        "relationship": relationship,
        "comments": comments,
        "favorite": favorite,
        "subscription": subscription,
        "screenshots": screenshots,
        "email_list": email_list,
        "target_detail": target,
        "form": form,
    }

    return template, args
開發者ID:brentonchang,項目名稱:crits-1,代碼行數:75,代碼來源:handlers.py


注:本文中的crits.targets.target.Target.to_dict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。