Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb
- from django.shortcuts import render
- from django.views.generic import TemplateView
- from django.contrib.auth.models import User
- # Create your views here.
- from account.models import Account, Point
- class AccountView(TemplateView):
- template_name = 'account/account_view.html'
- def user_import(row):
- username = row[3]
- password = row[4]
- fullname = row[5]
- vip_code = row[2]
- points = row[6]
- user = User(username=username)
- user.set_password(password)
- user.save()
- account = Account(user=user, fullname=fullname, vip_code=vip_code)
- account.save()
- point = Point(account=account, point=points)
- point.save()
- print("Пользователь %s %s добавлен" % (username, password))
- class AccountImport(TemplateView):
- template_name = 'account/account_view.html'
- def get_context_data(self, **kwargs):
- context = super(AccountImport, self).get_context_data()
- host = '85.25.45.121'
- login = ''
- password = ''
- database = 'main'
- con = MySQLdb.connect(host=host, user=login, passwd=password, db=database, charset='utf8')
- cur = con.cursor()
- # cur.execute("SELECT VERSION()")
- # ver = cur.fetchone()
- # print("Database version : %s " % ver)
- sql = "select * from x17f_catalog_users"
- cur.execute(sql)
- rows = cur.fetchall()
- for row in rows:
- user_import(row)
- return context
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement