def transfer_users(self): for se_u in se.User.objects.all().iterator(): #if se_u.id == -1:#skip the Community user # continue u = askbot.User() u_type = se_u.user_type.name if u_type == 'Administrator': u.set_admin_status() elif u_type == 'Moderator': u.set_status('m') elif u_type not in ('Unregistered', 'Registered'): raise Exception('unknown user type %s' % u_type) if se_u.password_id is not None: pw = se.Password.objects.get(id=se_u.password_id) u.password = '******' % (pw.salt, pw.password) else: u.set_unusable_password() #if user is not registered, no association record created #we do not allow posting by users who are not authenticated #probably they'll just have to "recover" their account by email if u_type != 'Unregistered': try: assert (se_u.open_id) #everybody must have open_id u_openid = askbot_openid.UserAssociation() u_openid.openid_url = se_u.open_id u.save() u_openid.user = u u_openid.last_used_timestamp = se_u.last_login_date u_openid.save() except AssertionError: print u'User %s (id=%d) does not have openid' % \ (unidecode(se_u.display_name), se_u.id) sys.stdout.flush() except IntegrityError: print "Warning: have duplicate openid: %s" % se_u.open_id sys.stdout.flush() if se_u.open_id is None and se_u.email is None: print 'Warning: SE user %d is not recoverable (no email or openid)' sys.stdout.flush() u.reputation = 1 #se_u.reputation, it's actually re-computed u.last_seen = se_u.last_access_date u.email = X.get_email(se_u.email) u.location = X.blankable(se_u.location) u.date_of_birth = se_u.birthday #dattime -> date u.website = X.blankable(se_u.website_url) u.about = X.blankable(se_u.about_me) if se_u.last_login_date is None: u.last_login = se_u.creation_date else: u.last_login = se_u.last_login_date u.date_joined = se_u.creation_date u.is_active = True #todo: this may not be the case u.username = X.get_screen_name(se_u) u.real_name = X.blankable(se_u.real_name) (gold, silver, bronze) = X.parse_badge_summary(se_u.badge_summary) u.gold = gold u.silver = silver u.bronze = bronze #todo: we don't have these fields #views - number of profile views? #has_replies #has_message #opt_in_recruit #last_login_ip #open_id_alt - ?? #preferences_raw - not clear how to use #display_name_cleaned - lowercased, srtipped name #timed_penalty_date #phone #don't know how to handle these - there was no usage example #password_id #guid #ignored #last_email_date - this translates directly to EmailFeedSetting.reported_at #save the data try: other = askbot.User.objects.get(username=u.username) print 'alert - have a second user with name %s' % u.username sys.sdtout.flush() except askbot.User.DoesNotExist: pass u.save() form = EditUserEmailFeedsForm() form.reset() if se_u.opt_in_email == True: #set up daily subscription on "own" items form.initial['individually_selected'] = 'd' form.initial['asked_by_me'] = 'd' form.initial['answered_by_me'] = 'd' # form.save(user=u, save_unbound=True) USER[se_u.id] = u
def transfer_users(self): for se_u in se.User.objects.all().iterator(): #if se_u.id == -1:#skip the Community user # continue u = askbot.User() u_type = se_u.user_type.name if u_type == 'Administrator': u.set_admin_status() elif u_type == 'Moderator': u.set_status('m') elif u_type not in ('Unregistered', 'Registered'): raise Exception('unknown user type %s' % u_type) if se_u.password_id is not None: pw = se.Password.objects.get(id = se_u.password_id) u.password = '******' % (pw.salt, pw.password) else: u.set_unusable_password() #if user is not registered, no association record created #we do not allow posting by users who are not authenticated #probably they'll just have to "recover" their account by email if u_type != 'Unregistered': try: assert(se_u.open_id)#everybody must have open_id u_openid = askbot_openid.UserAssociation() u_openid.openid_url = se_u.open_id u.save() u_openid.user = u u_openid.last_used_timestamp = se_u.last_login_date u_openid.save() except AssertionError: print u'User %s (id=%d) does not have openid' % \ (unidecode(se_u.display_name), se_u.id) sys.stdout.flush() except IntegrityError: print "Warning: have duplicate openid: %s" % se_u.open_id sys.stdout.flush() if se_u.open_id is None and se_u.email is None: print 'Warning: SE user %d is not recoverable (no email or openid)' sys.stdout.flush() u.reputation = 1#se_u.reputation, it's actually re-computed u.last_seen = se_u.last_access_date u.email = X.get_email(se_u.email) u.location = X.blankable(se_u.location) u.date_of_birth = se_u.birthday #dattime -> date u.website = X.blankable(se_u.website_url) u.about = X.blankable(se_u.about_me) if se_u.last_login_date is None: u.last_login = se_u.creation_date else: u.last_login = se_u.last_login_date u.date_joined = se_u.creation_date u.is_active = True #todo: this may not be the case u.username = X.get_screen_name(se_u) u.real_name = X.blankable(se_u.real_name) (gold,silver,bronze) = X.parse_badge_summary(se_u.badge_summary) u.gold = gold u.silver = silver u.bronze = bronze #todo: we don't have these fields #views - number of profile views? #has_replies #has_message #opt_in_recruit #last_login_ip #open_id_alt - ?? #preferences_raw - not clear how to use #display_name_cleaned - lowercased, srtipped name #timed_penalty_date #phone #don't know how to handle these - there was no usage example #password_id #guid #ignored #last_email_date - this translates directly to EmailFeedSetting.reported_at #save the data try: other = askbot.User.objects.get(username = u.username) print 'alert - have a second user with name %s' % u.username sys.sdtout.flush() except askbot.User.DoesNotExist: pass u.save() form = EditUserEmailFeedsForm() form.reset() if se_u.opt_in_email == True:#set up daily subscription on "own" items form.initial['individually_selected'] = 'd' form.initial['asked_by_me'] = 'd' form.initial['problemed_by_me'] = 'd' # form.save(user=u, save_unbound=True) USER[se_u.id] = u