Exemplo n.º 1
0
def main():
    args = parse_args()
    load_config(args.conf_file)

    if args.instance is None:
        instance = None
    else:
        instance = valid_instance(args.instance)
    invited_badge = valid_userbadge(args.badge.decode("utf-8"), instance)
    creator = User.find(u"admin")

    if args.action == u"invite":
        template = valid_template(args.template)
        csv_data = valid_csv(args.csv_file)
        for user_info in csv_data:
            user_info[u"user_badges"].add(invited_badge)

        ret = user_import(csv_data, args.subject, template, creator, instance)
        print_invite_result(ret)
    elif args.action == u"reinvite":
        template = valid_template(args.template)

        users = invited_users(invited_badge, activated=False)
        csv_data = [
            {u"email": u.email, u"user_name": u.user_name, u"display_name": u.display_name, u"user_badges": set()}
            for u in users
        ]

        ret = user_import(csv_data, args.subject, template, creator, instance, reinvite=True)
        print_invite_result(ret, reinvite=True)
    elif args.action == u"revoke":
        users = invited_users(invited_badge, activated=False)
        if len(users) != 0:
            for user in users:
                revoke(user)
        else:
            print (u"No users to revoke")
    elif args.action == u"uninvite":
        if len(args.users) != 0:
            for name in args.users:
                user = User.find(name)
                uninvite(user, invited_badge, revoke=args.revoke)
        else:
            print (u"No users to uninvite")

    meta.Session.commit()
Exemplo n.º 2
0
    def user_import(self, format="html"):

        if request.method == "POST":
            try:
                self.form_result = UserImportForm().to_python(request.params, state=get_user_import_state())
                data = user_import(
                    self.form_result["users_csv"],
                    self.form_result["email_subject"],
                    self.form_result["email_template"],
                    c.user,
                    c.instance,
                )
                return render("/admin/userimport_success.html", data, overlay=format == u"overlay")
            except formencode.Invalid as i:
                return self.user_import_form(errors=i.unpack_errors())
        else:
            return self.user_import_form(format=format)