当前位置: 首页>>代码示例>>Python>>正文


Python Rosetta.dump_translated方法代码示例

本文整理汇总了Python中globaleaks.utils.structures.Rosetta.dump_translated方法的典型用法代码示例。如果您正苦于以下问题:Python Rosetta.dump_translated方法的具体用法?Python Rosetta.dump_translated怎么用?Python Rosetta.dump_translated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在globaleaks.utils.structures.Rosetta的用法示例。


在下文中一共展示了Rosetta.dump_translated方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: anon_serialize_ahmia

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def anon_serialize_ahmia(store, language=GLSetting.memory_copy.default_language):
    """
    Request reaches only if ahmia is enabled
    """
    node = store.find(models.Node).one()

    mo = Rosetta()
    mo.acquire_storm_object(node)

    ahmia_description = {
        "title": node.name,
        "description": mo.dump_translated('description', language),

        # TODO support tags/keyword in Node.
        "keywords": "%s (GlobaLeaks instance)" % node.name,
        "relation": node.public_site,

        # TODO ask Ahmia to support a list of languages
        "language": node.default_language,

        # TODO say to the admin that its email will be public
        "contactInformation": u'',
        "type": "GlobaLeaks"
    }

    return ahmia_description
开发者ID:globaleaks,项目名称:GLBackend-outdated,代码行数:28,代码来源:node.py

示例2: receiver_serialize_receiver

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def receiver_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):
    receiver_dict = {
        "id": receiver.id,
        "name": receiver.name,
        "update_date": datetime_to_ISO8601(receiver.last_update),
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "receiver_level": receiver.receiver_level,
        "can_delete_submission": receiver.can_delete_submission,
        "username": receiver.user.username,
        "gpg_key_info": receiver.gpg_key_info,
        "gpg_key_fingerprint": receiver.gpg_key_fingerprint,
        "gpg_key_remove": False,
        "gpg_key_armor": receiver.gpg_key_armor,
        "gpg_key_status": receiver.gpg_key_status,
        "gpg_enable_notification": receiver.gpg_enable_notification,
        "tags": receiver.tags,
        "tip_notification" : receiver.tip_notification,
        "file_notification" : receiver.file_notification,
        "comment_notification" : receiver.comment_notification,
        "message_notification" : receiver.message_notification,
        "mail_address": receiver.mail_address,
                    # list is needed because .values returns a generator
        "contexts": list(receiver.contexts.values(Context.id)),
        "password": u'',
        "old_password": u'',
    }

    mo = Rosetta()
    mo.acquire_storm_object(receiver)
    receiver_dict["description"] = mo.dump_translated('description', language)

    for context in receiver.contexts:
        receiver_dict['contexts'].append(context.id)

    return receiver_dict
开发者ID:Acidburn0zzz,项目名称:GLBackend,代码行数:37,代码来源:receiver.py

示例3: receiver_serialize_internal_tip

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def receiver_serialize_internal_tip(internaltip, language=GLSetting.memory_copy.default_language):

    itip_dict = {
        'context_id': internaltip.context.id,
        'creation_date' : datetime_to_ISO8601(internaltip.creation_date),
        'expiration_date' : datetime_to_ISO8601(internaltip.expiration_date),
        'download_limit' : internaltip.download_limit,
        'access_limit' : internaltip.access_limit,
        'mark' : internaltip.mark,
        'pertinence' : internaltip.pertinence_counter,
        'escalation_threshold' : internaltip.escalation_threshold,
        'fields' : internaltip.wb_fields,

        # these two fields are at the moment unsent by the client, but kept
        # maintained in unitTest. (tickets in wishlist)
        'is_pertinent' : False,
        'global_delete' : False,
        # this field "inform" the receiver of the new expiration date that can
        # be set, only if PUT with extend = True is updated
        'potential_expiration_date' : \
            datetime_to_ISO8601(utc_future_date(seconds=internaltip.context.tip_timetolive)),
        'extend' : False,
        'enable_private_messages': internaltip.context.enable_private_messages
    }

    # context_name and context_description are localized field
    mo = Rosetta()
    mo.acquire_storm_object(internaltip.context)
    for attr in ['name', 'description' ]:
        key = "context_%s" % attr
        itip_dict[key] = mo.dump_translated(attr, language)

    return itip_dict
开发者ID:globaleaks,项目名称:GLBackend-outdated,代码行数:35,代码来源:rtip.py

示例4: anon_serialize_receiver

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def anon_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):
    """
    @param receiver: a valid Storm object
    @return: a dict describing the receivers available in the node
        (e.g. checks if almost one context is associated, or, in
         node where GPG encryption is enforced, that a valid key is registered)
    """
    mo = Rosetta()
    mo.acquire_storm_object(receiver)

    receiver_dict = {
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "update_date": datetime_to_ISO8601(receiver.last_update),
        "name": receiver.name,
        "description": mo.dump_translated('description', language),
        "id": receiver.id,
        "receiver_level": receiver.receiver_level,
        "tags": receiver.tags,
        "presentation_order": receiver.presentation_order,
        "gpg_key_status": receiver.gpg_key_status,
                    # list is needed because .values returns a generator
        "contexts": list(receiver.contexts.values(models.Context.id))
    }

    if not len(receiver_dict['contexts']):
        return None

    return receiver_dict
开发者ID:globaleaks,项目名称:GLBackend-outdated,代码行数:30,代码来源:node.py

示例5: receiver_serialize_receiver

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def receiver_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):
    receiver_dict = {
        "receiver_gus": receiver.id,
        "name": receiver.name,
        "update_date": pretty_date_time(receiver.last_update),
        "creation_date": pretty_date_time(receiver.creation_date),
        "receiver_level": receiver.receiver_level,
        "can_delete_submission": receiver.can_delete_submission,
        "username": receiver.user.username,
        "gpg_key_info": receiver.gpg_key_info,
        "gpg_key_fingerprint": receiver.gpg_key_fingerprint,
        "gpg_key_remove": False,
        "gpg_key_armor": receiver.gpg_key_armor,
        "gpg_key_status": receiver.gpg_key_status,
        "gpg_enable_notification": receiver.gpg_enable_notification,
        "gpg_enable_files": receiver.gpg_enable_files,
        "tags": receiver.tags,
        "tip_notification" : receiver.tip_notification,
        "file_notification" : receiver.file_notification,
        "comment_notification" : receiver.comment_notification,
        "notification_fields": dict(receiver.notification_fields),
        "failed_login": receiver.user.failed_login_count,
        "contexts": []
    }

    mo = Rosetta()
    mo.acquire_storm_object(receiver)
    receiver_dict["description"] = mo.dump_translated('description', language)

    for context in receiver.contexts:
        receiver_dict['contexts'].append(context.id)

    return receiver_dict
开发者ID:rowanthorpe,项目名称:GLBackend,代码行数:35,代码来源:receiver.py

示例6: anon_serialize_receiver

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def anon_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):
    """
    @param receiver: a valid Storm object
    @return: a dict describing the receivers available in the node
        (e.g. checks if almost one context is associated, or, in
         node where GPG encryption is enforced, that a valid key is registered)
    """
    receiver_dict = {
        "contexts": [],
    }

    for context in receiver.contexts:
        receiver_dict['contexts'].append(unicode(context.id))

    if not len(receiver_dict['contexts']):
        return None

    receiver_dict.update({
        "can_delete_submission": receiver.can_delete_submission,
        "creation_date": pretty_date_time(receiver.creation_date),
        "update_date": pretty_date_time(receiver.last_update),
        "name": unicode(receiver.name),
        "receiver_gus": unicode(receiver.id),
        "receiver_level": int(receiver.receiver_level),
        "tags": receiver.tags,
    })

    mo = Rosetta()
    mo.acquire_storm_object(receiver)
    receiver_dict['description'] = mo.dump_translated('description', language)

    return receiver_dict
开发者ID:rowanthorpe,项目名称:GLBackend,代码行数:34,代码来源:node.py

示例7: anon_serialize_node

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def anon_serialize_node(store, language=GLSetting.memory_copy.default_language):
    node = store.find(models.Node).one()

    # Contexts and Receivers relationship
    associated = store.find(models.ReceiverContext).count()

    custom_homepage = False

    try: 
        custom_homepage = os.path.isfile(os.path.join(GLSetting.static_path, "custom_homepage.html"))
    except:
        pass

    node_dict = {
      'name': node.name,
      'hidden_service': node.hidden_service,
      'public_site': node.public_site,
      'email': node.email,
      'languages_enabled': node.languages_enabled,
      'languages_supported': LANGUAGES_SUPPORTED,
      'default_language' : node.default_language,
      # extended settings info:
      'maximum_namesize': node.maximum_namesize,
      'maximum_textsize': node.maximum_textsize,
      'maximum_filesize': node.maximum_filesize,
      # public serialization use GLSetting memory var, and
      # not the real one, because needs to bypass
      # Tor2Web unsafe deny default settings
      'tor2web_admin': GLSetting.memory_copy.tor2web_admin,
      'tor2web_submission': GLSetting.memory_copy.tor2web_submission,
      'tor2web_receiver': GLSetting.memory_copy.tor2web_receiver,
      'tor2web_unauth': GLSetting.memory_copy.tor2web_unauth,
      'ahmia': node.ahmia,
      'postpone_superpower': node.postpone_superpower,
      'can_delete_submission': node.can_delete_submission,
      'wizard_done': node.wizard_done,
      'anomaly_checks': node.anomaly_checks,
      'allow_unencrypted': node.allow_unencrypted,
      'x_frame_options_mode': node.x_frame_options_mode,
      'x_frame_options_allow_from': node.x_frame_options_allow_from,
      'receipt_regexp': node.receipt_regexp,
      'configured': True if associated else False,
      'password': u"",
      'old_password': u"",
      'custom_homepage': custom_homepage,
      'disable_privacy_badge': node.disable_privacy_badge,
      'disable_security_awareness_badge': node.disable_security_awareness_badge,
      'disable_security_awareness_questions': node.disable_security_awareness_questions
    }

    mo = Rosetta()
    mo.acquire_storm_object(node)
    for attr in mo.get_localized_attrs():
        node_dict[attr] = mo.dump_translated(attr, language)

    return node_dict
开发者ID:globaleaks,项目名称:GLBackend-outdated,代码行数:58,代码来源:node.py

示例8: anon_serialize_context

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def anon_serialize_context(context, language=GLSetting.memory_copy.default_language):
    """
    @param context: a valid Storm object
    @return: a dict describing the contexts available for submission,
        (e.g. checks if almost one receiver is associated)
    """

    mo = Rosetta()
    mo.acquire_storm_object(context)
    fo = Fields(context.localized_fields, context.unique_fields)

    context_dict = {
        "id": context.id,
        "escalation_threshold": 0,
        "file_max_download": context.file_max_download,
        "file_required": context.file_required,
        "selectable_receiver": context.selectable_receiver,
        "tip_max_access": context.tip_max_access,
        "tip_timetolive": context.tip_timetolive,
        "submission_introduction": u'NYI', # unicode(context.submission_introduction), # optlang
        "submission_disclaimer": u'NYI', # unicode(context.submission_disclaimer), # optlang
        "select_all_receivers": context.select_all_receivers,
        "maximum_selectable_receivers": context.maximum_selectable_receivers,
        'require_pgp': context.require_pgp,
        "show_small_cards": context.show_small_cards,
        "show_receivers": context.show_receivers,
        "enable_private_messages": context.enable_private_messages,
        "presentation_order": context.presentation_order,
                     # list is needed because .values returns a generator
        "receivers": list(context.receivers.values(models.Receiver.id)),
        'name': mo.dump_translated('name', language),
        "description": mo.dump_translated('description', language),
        "fields": fo.dump_fields(language)
    }

    if not len(context_dict['receivers']):
        return None

    return context_dict
开发者ID:globaleaks,项目名称:GLBackend-outdated,代码行数:41,代码来源:node.py

示例9: anon_serialize_context

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def anon_serialize_context(context, language=GLSetting.memory_copy.default_language):
    """
    @param context: a valid Storm object
    @return: a dict describing the contexts available for submission,
        (e.g. checks if almost one receiver is associated)
    """
    context_dict = {
        "receivers": []
    }

    for receiver in context.receivers:
        context_dict['receivers'].append(unicode(receiver.id))

    if not len(context_dict['receivers']):
        return None

    context_dict.update({
        "context_gus": unicode(context.id),
        "escalation_threshold": None,
        "file_max_download": int(context.file_max_download),
        "file_required": context.file_required,
        "selectable_receiver": bool(context.selectable_receiver),
        "tip_max_access": int(context.tip_max_access),
        "tip_timetolive": int(context.tip_timetolive),
        "receipt_description": u'NYI', # unicode(context.receipt_description), # optlang
        "submission_introduction": u'NYI', # unicode(context.submission_introduction), # optlang
        "submission_disclaimer": u'NYI', # unicode(context.submission_disclaimer), # optlang
        "select_all_receivers": context.select_all_receivers
    })

    mo = Rosetta()
    mo.acquire_storm_object(context)
    context_dict['name'] = mo.dump_translated('name', language)
    context_dict['description'] = mo.dump_translated('description', language)

    fo = Fields(context.localized_fields, context.unique_fields)
    context_dict['fields'] = fo.dump_fields(language)

    return context_dict
开发者ID:rowanthorpe,项目名称:GLBackend,代码行数:41,代码来源:node.py

示例10: wb_serialize_tip

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def wb_serialize_tip(internaltip, language=GLSetting.memory_copy.default_language):
    itip_dict = {
        'context_id': internaltip.context.id,
        'creation_date' : datetime_to_ISO8601(internaltip.creation_date),
        'last_activity' : datetime_to_ISO8601(internaltip.creation_date),
        'expiration_date' : datetime_to_ISO8601(internaltip.expiration_date),
        'download_limit' : internaltip.download_limit,
        'access_limit' : internaltip.access_limit,
        'mark' : internaltip.mark,
        'pertinence' : internaltip.pertinence_counter,
        'escalation_threshold' : internaltip.escalation_threshold,
        'fields' : internaltip.wb_fields,
    }

    # context_name and context_description are localized field
    mo = Rosetta()
    mo.acquire_storm_object(internaltip.context)
    for attr in ['name', 'description' ]:
        key = "context_%s" % attr
        itip_dict[key] = mo.dump_translated(attr, language)

    return itip_dict
开发者ID:Acidburn0zzz,项目名称:GLBackend,代码行数:24,代码来源:wbtip.py

示例11: get_receiver_list_receiver

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def get_receiver_list_receiver(store, user_id, tip_id, language=GLSetting.memory_copy.default_language):

    rtip = access_tip(store, user_id, tip_id)

    receiver_list = []
    for rtip in rtip.internaltip.receivertips:

        receiver_desc = {
            "gpg_key_status": rtip.receiver.gpg_key_status,
            "can_delete_submission": rtip.receiver.can_delete_submission,
            "name": unicode(rtip.receiver.name),
            "receiver_id": unicode(rtip.receiver.id),
            "receiver_level": int(rtip.receiver.receiver_level),
            "tags": rtip.receiver.tags,
            "access_counter": rtip.access_counter,
        }

        mo = Rosetta()
        mo.acquire_storm_object(rtip.receiver)
        receiver_desc["description"] = mo.dump_translated("description", language)

        receiver_list.append(receiver_desc)

    return receiver_list
开发者ID:globaleaks,项目名称:GLBackend-outdated,代码行数:26,代码来源:rtip.py

示例12: anon_serialize_node

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def anon_serialize_node(store, language=GLSetting.memory_copy.default_language):
    node = store.find(models.Node).one()

    # Contexts and Receivers relationship
    associated = store.find(models.ReceiverContext).count()
    
    node_dict = {
      'name': unicode(node.name),
      'hidden_service': unicode(node.hidden_service),
      'public_site': unicode(node.public_site),
      'email': unicode(node.email),
      'languages_enabled': node.languages_enabled,
      'languages_supported': LANGUAGES_SUPPORTED,
      'default_language' : node.default_language,
      'configured': True if associated else False,
      # extended settings info:
      'maximum_namesize': node.maximum_namesize,
      'maximum_textsize': node.maximum_textsize,
      'maximum_filesize': node.maximum_filesize,
      # public serialization use GLSetting memory var, and
      # not the real one, because needs to bypass
      # Tor2Web unsafe deny default settings
      'tor2web_admin': GLSetting.memory_copy.tor2web_admin,
      'tor2web_submission': GLSetting.memory_copy.tor2web_submission,
      'tor2web_tip': GLSetting.memory_copy.tor2web_tip,
      'tor2web_receiver': GLSetting.memory_copy.tor2web_receiver,
      'tor2web_unauth': GLSetting.memory_copy.tor2web_unauth,
      'postpone_superpower': node.postpone_superpower,
    }

    mo = Rosetta()
    mo.acquire_storm_object(node)
    for attr in mo.get_localized_attrs():
        node_dict[attr] = mo.dump_translated(attr, language)

    return node_dict
开发者ID:rowanthorpe,项目名称:GLBackend,代码行数:38,代码来源:node.py

示例13: get_receiver_tip_list

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def get_receiver_tip_list(store, receiver_id, language=GLSetting.memory_copy.default_language):

    rtiplist = store.find(ReceiverTip, ReceiverTip.receiver_id == receiver_id)
    rtiplist.order_by(Desc(ReceiverTip.creation_date))

    node = store.find(Node).one()

    rtip_summary_list = []

    for rtip in rtiplist:

        postpone_superpower = (node.postpone_superpower or
                               rtip.internaltip.context.postpone_superpower or
                               rtip.receiver.postpone_superpower)

        can_delete_submission = (node.can_delete_submission or
                                 rtip.internaltip.context.can_delete_submission or
                                 rtip.receiver.can_delete_submission)

        rfiles_n = store.find(ReceiverFile,
            (ReceiverFile.internaltip_id == rtip.internaltip.id,
             ReceiverFile.receiver_id == receiver_id)).count()

        your_messages = store.find(Message,
                                   Message.receivertip_id == rtip.id,
                                   Message.type == u'receiver').count()

        unread_messages = store.find(Message,
                                     Message.receivertip_id == rtip.id,
                                     Message.type == u'whistleblower',
                                     Message.visualized == False).count()

        read_messages = store.find(Message,
                                   Message.receivertip_id == rtip.id,
                                   Message.type == u'whistleblower',
                                   Message.visualized == True).count()

        single_tip_sum = dict({
            'id' : rtip.id,
            'expressed_pertinence': rtip.expressed_pertinence,
            'creation_date' : datetime_to_ISO8601(rtip.creation_date),
            'last_access' : datetime_to_ISO8601(rtip.last_access),
            'expiration_date' : datetime_to_ISO8601(rtip.internaltip.expiration_date),
            'access_counter': rtip.access_counter,
            'files_number': rfiles_n,
            'comments_number': rtip.internaltip.comments.count(),
            'unread_messages' : unread_messages,
            'read_messages' : read_messages,
            'your_messages' : your_messages,
            'postpone_superpower': postpone_superpower,
            'can_delete_submission': can_delete_submission,
        })

        mo = Rosetta()
        mo.acquire_storm_object(rtip.internaltip.context)
        single_tip_sum["context_name"] = mo.dump_translated('name', language)

        preview_data = []

        fo = Fields(rtip.internaltip.context.localized_fields, rtip.internaltip.context.unique_fields)
        for preview_key, preview_label in fo.get_preview_keys(language).iteritems():

            # preview in a format angular.js likes
            try:
                entry = dict({'label' : preview_label,
                              'text': rtip.internaltip.wb_fields[preview_key] })

            except KeyError as xxx:
                log.err("Legacy error: suppressed 'preview_keys' %s" % xxx.message )
                continue

            preview_data.append(entry)

        single_tip_sum.update({ 'preview' : preview_data })
        rtip_summary_list.append(single_tip_sum)

    return rtip_summary_list
开发者ID:Acidburn0zzz,项目名称:GLBackend,代码行数:79,代码来源:receiver.py

示例14: collect_tip_overview

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def collect_tip_overview(store, language=GLSetting.memory_copy.default_language):

    tip_description_list = []
    all_itips = store.find(models.InternalTip)
    all_itips.order_by(Desc(models.InternalTip.creation_date))

    for itip in all_itips:
        tip_description = {
            "id": itip.id,
            "creation_date": pretty_date_time(itip.creation_date),
            "creation_lifetime": pretty_date_time(itip.creation_date),
            "expiration_date": pretty_date_time(itip.expiration_date),
            "context_id": itip.context_id,
            "pertinence_counter": itip.pertinence_counter,
            "status": itip.mark,
            "receivertips": [],
            "internalfiles": [],
            "comments": [],
        }

        mo = Rosetta()
        mo.acquire_storm_object(itip.context)
        tip_description['context_name'] = mo.dump_translated('name', language)

        # strip uncompleted submission, until GLClient open new submission
        # also if no data has been supply
        if itip.mark == models.InternalTip._marker[0]:
            continue

        for rtip in itip.receivertips:
            tip_description['receivertips'].append({
                'access_counter': rtip.access_counter,
                'notification_date': pretty_date_time(rtip.notification_date),
                # 'creation_date': pretty_date_time(rtip.creation_date),
                'status': rtip.mark,
                'receiver_id': rtip.receiver.id,
                'receiver_username': rtip.receiver.user.username,
                'receiver_name': rtip.receiver.name,
                # last_access censored willingly
            })

        for ifile in itip.internalfiles:
            tip_description['internalfiles'].append({
                'name': ifile.name,
                'size': ifile.size,
                'status': ifile.mark,
                'content_type': ifile.content_type
            })

        for comment in itip.comments:
            tip_description['comments'].append({
                'type': comment.type,
                'lifetime': pretty_date_time(comment.creation_date),
            })

        # whistleblower tip has not a reference from itip, then:
        wbtip = store.find(models.WhistleblowerTip,
            models.WhistleblowerTip.internaltip_id == itip.id).one()

        if wbtip is not None:
            tip_description.update({
                'wb_access_counter': wbtip.access_counter,
                'wb_last_access': pretty_date_time(wbtip.last_access)
            })
        else:
            tip_description.update({
                'wb_access_counter': u'Deleted', 'wb_last_access': u'Never'
            })

        tip_description_list.append(tip_description)

    return tip_description_list
开发者ID:rowanthorpe,项目名称:GLBackend,代码行数:74,代码来源:overview.py

示例15: get_receiver_list_wb

# 需要导入模块: from globaleaks.utils.structures import Rosetta [as 别名]
# 或者: from globaleaks.utils.structures.Rosetta import dump_translated [as 别名]
def get_receiver_list_wb(store, wb_tip_id, language=GLSetting.memory_copy.default_language):
    """
    @return:
        This function contain the serialization of the receiver, this function is
        used only by /wbtip/receivers API

        The returned struct contain information on read/unread messages
    """

    wb_tip = store.find(WhistleblowerTip,
                        WhistleblowerTip.id == unicode(wb_tip_id)).one()

    if not wb_tip:
        raise errors.TipReceiptNotFound

    # This part of code is used only in the short time between the first
    # WB access and the delivery schedule. In this moment
    # wb_tip.internaltips.receivertips is EMPTY, therefore we force
    # the Receivers values below
    if not wb_tip.internaltip.receivertips.count():
        receiver_list = []

        log.debug("Early access from the WB to the Tip (creation_date: %s UTC),"\
                  " Receiver not yet present: fallback on receiver list" %
                  datetime_to_pretty_str(wb_tip.creation_date))

        for receiver in wb_tip.internaltip.receivers:

            # This is the reduced version of Receiver serialization
            receiver_desc = {
                "name": receiver.name,
                "id": receiver.id,
                "gpg_key_status": receiver.gpg_key_status,
                "tags": receiver.tags,
                "access_counter" : 0,
                "unread_messages" : 0,
                "read_messages" : 0,
                "your_messages" : 0,
                "creation_date" : datetime_to_ISO8601(datetime_now()),
                # XXX ReceiverTip last activity ?
            }

            mo = Rosetta()
            mo.acquire_storm_object(receiver)
            receiver_desc["description"] = mo.dump_translated("description", language)
            receiver_list.append(receiver_desc)

        return receiver_list
    else:
        receiver_list = []
        for rtip in wb_tip.internaltip.receivertips:


            your_messages = store.find(Message,
                                       Message.receivertip_id == rtip.id,
                                       Message.type == u'whistleblower').count()

            unread_messages = store.find(Message,
                                         Message.receivertip_id == rtip.id,
                                         Message.type == u'receiver',
                                         Message.visualized == False).count()

            read_messages = store.find(Message,
                                       Message.receivertip_id == rtip.id,
                                       Message.type == u'receiver',
                                       Message.visualized == True).count()

            # if you change something here, check also 20 lines before!
            receiver_desc = {
                "name": rtip.receiver.name,
                "id": rtip.receiver.id,
                "tags": rtip.receiver.tags,
                "access_counter" : rtip.access_counter,
                "unread_messages" : unread_messages,
                "read_messages" : read_messages,
                "your_messages" : your_messages,
                "creation_date" : datetime_to_ISO8601(datetime_now()),
                # XXX ReceiverTip last activity ?
            }

            mo = Rosetta()
            mo.acquire_storm_object(rtip.receiver)
            receiver_desc["description"] = mo.dump_translated("description", language)

            receiver_list.append(receiver_desc)

        return receiver_list
开发者ID:globaleaks,项目名称:GLBackend-outdated,代码行数:89,代码来源:wbtip.py


注:本文中的globaleaks.utils.structures.Rosetta.dump_translated方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。