コード例 #1
0
def process_index_title_change_in_user_history(indx, **kwargs):
    print "Cascading User History from {} to {}".format(kwargs['old'], kwargs['new'])

    # ensure that the regex library we're using here is the same regex library being used in `Ref.regex`
    from text import re as reg_reg
    patterns = [pattern.replace(reg_reg.escape(indx.title), reg_reg.escape(kwargs["old"]))
                for pattern in Ref(indx.title).regex(as_list=True)]
    queries = [{'ref': {'$regex': pattern}} for pattern in patterns]
    objs = UserHistorySet({"$or": queries})
    for o in objs:
        o.ref = o.ref.replace(kwargs["old"], kwargs["new"], 1)
        try:
            o.save()
        except InputError:
            logger.warning(u"Failed to convert user history from: {} to {}".format(kwargs['old'], kwargs['new']))
コード例 #2
0
ファイル: link.py プロジェクト: Sefaria/Sefaria-Project
def process_index_title_change_in_links(indx, **kwargs):
    print "Cascading Links {} to {}".format(kwargs['old'], kwargs['new'])

    # ensure that the regex library we're using here is the same regex library being used in `Ref.regex`
    from text import re as reg_reg
    patterns = [pattern.replace(reg_reg.escape(indx.title), reg_reg.escape(kwargs["old"]))
                for pattern in text.Ref(indx.title).regex(as_list=True)]
    queries = [{'refs': {'$regex': pattern}} for pattern in patterns]
    links = LinkSet({"$or": queries})
    for l in links:
        l.refs = [r.replace(kwargs["old"], kwargs["new"], 1) if re.search(u'|'.join(patterns), r) else r for r in l.refs]
        try:
            l.save()
        except InputError: #todo: this belongs in a better place - perhaps in abstract
            logger.warning("Deleting link that failed to save: {} - {}".format(l.refs[0], l.refs[1]))
            l.delete()
コード例 #3
0
def process_index_title_change_in_links(indx, **kwargs):
    print "Cascading Links {} to {}".format(kwargs['old'], kwargs['new'])

    # ensure that the regex library we're using here is the same regex library being used in `Ref.regex`
    from text import re as reg_reg
    patterns = [pattern.replace(reg_reg.escape(indx.title), reg_reg.escape(kwargs["old"]))
                for pattern in text.Ref(indx.title).regex(as_list=True)]
    queries = [{'refs': {'$regex': pattern}} for pattern in patterns]
    links = LinkSet({"$or": queries})
    for l in links:
        l.refs = [r.replace(kwargs["old"], kwargs["new"], 1) if re.search(u'|'.join(patterns), r) else r for r in l.refs]
        l.expandedRefs0 = [r.replace(kwargs["old"], kwargs["new"], 1) if re.search(u'|'.join(patterns), r) else r for r in l.expandedRefs0]
        l.expandedRefs1 = [r.replace(kwargs["old"], kwargs["new"], 1) if re.search(u'|'.join(patterns), r) else r for r in l.expandedRefs1]
        try:
            l._skip_lang_check = True
            l._skip_expanded_refs_set = True
            l.save()
        except InputError: #todo: this belongs in a better place - perhaps in abstract
            logger.warning(u"Deleting link that failed to save: {} - {}".format(l.refs[0], l.refs[1]))
            l.delete()