def create_defaults_for(session, user, only_for=None, detail_values=None):
detail_values = detail_values or {}<EOL>if not user.openid.endswith('<STR_LIT>'):<EOL><INDENT>log.warn("<STR_LIT>")<EOL>return<EOL><DEDENT>nick = user.openid.split('<STR_LIT:.>')[<NUM_LIT:0>]<EOL>valid_paths = fmn.lib.load_rules(root='<STR_LIT>')<EOL>def rule_maker(path, **kw):<EOL><INDENT>"""<STR_LIT>"""<EOL>return fmn.lib.models.Rule.create_from_code_path(<EOL>session, valid_paths, path, **kw)<EOL><DEDENT>def contexts():<EOL><INDENT>names = ['<STR_LIT:email>', '<STR_LIT>', '<STR_LIT>']<EOL>if only_for:<EOL><INDENT>names = [only_for.name]<EOL><DEDENT>for name in names:<EOL><INDENT>context = fmn.lib.models.Context.get(session, name)<EOL>if context:<EOL><INDENT>yield context<EOL><DEDENT>else:<EOL><INDENT>log.warn("<STR_LIT>" % name)<EOL><DEDENT><DEDENT><DEDENT>for context in contexts():<EOL><INDENT>pref = fmn.lib.models.Preference.load(session, user, context)<EOL>if not pref:<EOL><INDENT>value = detail_values.get(context.name)<EOL>pref = fmn.lib.models.Preference.create(<EOL>session, user, context, detail_value=value)<EOL><DEDENT>filt = fmn.lib.models.Filter.create(<EOL>session, "<STR_LIT>")<EOL>filt.add_rule(session, valid_paths,<EOL>"<STR_LIT>", fasnick=nick)<EOL>filt.add_rule(session, valid_paths,<EOL>"<STR_LIT>",<EOL>fasnick=nick,<EOL>negated=True)<EOL>filt.add_rule(session, valid_paths,<EOL>"<STR_LIT>",<EOL>instance="<STR_LIT>",<EOL>negated=True)<EOL>for code_path in exclusion_packages + exclusion_mutual:<EOL><INDENT>filt.add_rule(<EOL>session, valid_paths, "<STR_LIT>" % code_path, negated=True)<EOL><DEDENT>pref.add_filter(session, filt, notify=True)<EOL>filt = fmn.lib.models.Filter.create(<EOL>session, "<STR_LIT>")<EOL>filt.add_rule(session, valid_paths,<EOL>"<STR_LIT>", fasnick=nick)<EOL>filt.add_rule(session, valid_paths,<EOL>"<STR_LIT>",<EOL>instance="<STR_LIT>",<EOL>negated=True)<EOL>for code_path in exclusion_username + exclusion_mutual:<EOL><INDENT>filt.add_rule(<EOL>session, valid_paths, "<STR_LIT>" % code_path, negated=True)<EOL><DEDENT>pref.add_filter(session, filt, notify=True)<EOL>filt = fmn.lib.models.Filter.create(<EOL>session, "<STR_LIT>")<EOL>filt.add_rule(session, valid_paths,<EOL>"<STR_LIT>",<EOL>fasnick=nick)<EOL>filt.add_rule(session, valid_paths,<EOL>"<STR_LIT>")<EOL>filt.add_rule(session, valid_paths,<EOL>"<STR_LIT>",<EOL>outcome='<STR_LIT>')<EOL>pref.add_filter(session, filt, notify=True)<EOL><DEDENT>
Create a sizable amount of defaults for a new user.