def add_dealer_2(): dealertype_bmw = DealerType.objects.get(name_en=u'BMW') dealer_nation = Dealer.objects.get(name=u'全国') # xlsfile = os.path.join(settings.RESOURCES_ROOT, u'third/dealer/APQ 2012 dealer list _To GFK_0723.xls') # xlsfile = os.path.join(settings.RESOURCES_ROOT, u'third/dealer/APQ 2012 dealer list _To GFK_0829.xls') xlsfile = os.path.join( settings.RESOURCES_ROOT, u'third/dealer/APQ 2012 dealer list _To GFK_0918.xls') book = xlrd.open_workbook(xlsfile) term = get_cur_input_term() #BMW经销 sh = book.sheet_by_index(0) print sh.name, sh.nrows, sh.ncols term.dealers = [] for rx in range(1, sh.nrows): add_row(sh, rx, dealer_nation, dealertype_bmw, term) #break #MINI经销 dealertype_mini = DealerType.objects.get(name_en=u'MINI') sh = book.sheet_by_index(1) print sh.name, sh.nrows, sh.ncols for rx in range(1, sh.nrows): add_row(sh, rx, dealer_nation, dealertype_mini, term) term.save()
def add_dealer_2(): dealertype_bmw = DealerType.objects.get(name_en=u'BMW') dealer_nation = Dealer.objects.get(name=u'全国') # xlsfile = os.path.join(settings.RESOURCES_ROOT, u'third/dealer/APQ 2012 dealer list _To GFK_0723.xls') # xlsfile = os.path.join(settings.RESOURCES_ROOT, u'third/dealer/APQ 2012 dealer list _To GFK_0829.xls') # xlsfile = os.path.join(settings.RESOURCES_ROOT, u'third/dealer/APQ 2012 dealer list _To GFK_0918.xls') xlsfile = os.path.join(settings.RESOURCES_ROOT, u'fouth/dealer/BMW Q4经销商大区经理小区经理调整_1214.xls') book = xlrd.open_workbook(xlsfile) term = get_cur_input_term() #BMW经销 sh = book.sheet_by_index(0) print sh.name, sh.nrows, sh.ncols term.dealers = [] for rx in range(1, sh.nrows): add_row(sh, rx, dealer_nation, dealertype_bmw, term) #break #MINI经销 dealertype_mini = DealerType.objects.get(name_en=u'MINI') sh = book.sheet_by_index(1) print sh.name, sh.nrows, sh.ncols for rx in range(1, sh.nrows): add_row(sh, rx, dealer_nation, dealertype_mini, term) term.save()
def add_router(): xlsfile = os.path.join(settings.RESOURCES_ROOT, u'fouth/router/路线图和评估员信息_1029.xls') book = xlrd.open_workbook(xlsfile) term = get_cur_input_term() #设置所有访问员为不活跃 g = Group.objects.get(name=enums.FW_INPUT_GROUP) users = User.objects.filter(groups__in=[g]) for u in users: u.is_staff = False u.is_active = False u.save() print u.username #路线 sh = book.sheet_by_index(0) print sh.name, sh.nrows, sh.ncols for rx in range(sh.nrows): texts = sh.row_values(rx) router, create = Router.objects.get_or_create(name=texts[0].strip(), term=term) texts.remove(texts[0]) while '' in texts: texts.remove('') print router.name, texts router.citys = '-'.join(texts) router.save() #访问员 #后台:只能在后台录入问卷。 #前台:没有权限登录前台。 sh = book.sheet_by_index(1) print sh.name, sh.nrows, sh.ncols for rx in range(1, sh.nrows): texts = sh.row_values(rx) username = texts[0].strip() password = '******' % int(texts[2]) uname = username user, create = User.objects.get_or_create(username=uname) user.set_password(password) user.is_staff = True user.is_active = True user.first_name = '%s %s' % (texts[1], username) user.groups = [ g, ] user.save() print user.first_name up, create = UserProfile.objects.get_or_create(user=user) p = UserPermission.objects.get(name=enums.FW_INPUT_PERMISSION) up.user_permissions = [ p, ] up.save()
def add_router(): xlsfile = os.path.join(settings.RESOURCES_ROOT, u'third/router/3121-602开心闹龙年项目评估员更新.xls') book = xlrd.open_workbook(xlsfile) term = get_cur_input_term() #设置所有访问员为不活跃 g = Group.objects.get(name=enums.FW_INPUT_GROUP) users = User.objects.filter(groups__in=[g]) for u in users: u.is_staff = False u.is_active = False u.save() print u.username #路线 sh = book.sheet_by_index(0) print sh.name, sh.nrows, sh.ncols for rx in range(sh.nrows): texts = sh.row_values(rx) router, create = Router.objects.get_or_create(name=texts[0].strip(), term=term) texts.remove(texts[0]) while '' in texts: texts.remove('') print router.name, texts router.citys = '-'.join(texts) router.save() #访问员 #后台:只能在后台录入问卷。 #前台:没有权限登录前台。 sh = book.sheet_by_index(1) print sh.name, sh.nrows, sh.ncols for rx in range(1, sh.nrows): texts = sh.row_values(rx) username = texts[0].strip() password = '******' % int(texts[2]) uname = username user, create = User.objects.get_or_create(username=uname) user.set_password(password) user.is_staff = True user.is_active = True user.first_name = '%s %s' % (texts[1], username) user.groups = [g, ] user.save() print user.first_name up, create = UserProfile.objects.get_or_create(user=user) p = UserPermission.objects.get(name=enums.FW_INPUT_PERMISSION) up.user_permissions = [p, ] up.save()
def add_MINI_dealer(): dealertype_mini = DealerType.objects.get(name_en=u'MINI') dealer_nation = Dealer.objects.get(name=u'全国') xlsfile = os.path.join(settings.RESOURCES_ROOT, u'first/dealer/Mini经销商名单_0415.xls') book = xlrd.open_workbook(xlsfile) #经销� sh = book.sheet_by_index(0) print sh.name, sh.nrows, sh.ncols term = get_cur_input_term() for rx in range(1, sh.nrows): add_row(sh, rx, dealer_nation, dealertype_mini, term) #break term.save()
def add_dealer(): xlsfile = os.path.join(settings.RESOURCES_ROOT, u'third/dealer/竞品经销商更新-0920.xls') book = xlrd.open_workbook(xlsfile) #经销� sh = book.sheet_by_index(0) print sh.name, sh.nrows, sh.ncols term = get_cur_input_term() dealers = [] dealers.extend(term.dealers.all()) term.dealers = dealers dealer_nation = Dealer.objects.get(name=u'全国') for rx in range(1, sh.nrows): add_row(sh, rx, dealer_nation, term) #break term.save()
def add_dealer(): dealertype_bmw = DealerType.objects.get(name_en=u'BMW') dealer_nation = Dealer.objects.get(name=u'全国') xlsfile = os.path.join(settings.RESOURCES_ROOT, u'first/dealer/APQ 2012 dealer list _0220.xls') book = xlrd.open_workbook(xlsfile) #经销� sh = book.sheet_by_index(0) print sh.name, sh.nrows, sh.ncols term = get_cur_input_term() term.dealers = [] for rx in range(1, sh.nrows): add_row(sh, rx, dealer_nation, dealertype_bmw, term) #break term.save()
def add_dealer_2(): dealertype_bmw = DealerType.objects.get(name_en=u'BMW') dealer_nation = Dealer.objects.get(name=u'全国') xlsfile = os.path.join(settings.RESOURCES_ROOT, u'first/dealer/APQ 2012 dealer list _0406(北区区域经理调整).xls') book = xlrd.open_workbook(xlsfile) #经销� sh = book.sheet_by_index(1) print sh.name, sh.nrows, sh.ncols term = get_cur_input_term() term.dealers = [] for rx in range(1, sh.nrows): add_row(sh, rx, dealer_nation, dealertype_bmw, term) #break term.save()