Ejemplo n.º 1
0
def create(request):
	if request.method == 'POST':
		form = CreateUserForm(request.POST)
		if form.is_valid():
			#creating user
			perms = { each : form.cleaned_data[each] 
					  for each in perms_to_classes.keys()}

			password = User.objects.make_random_password(length = 8)
			user = create_user(username = form.cleaned_data['email'],
							  password = password,
					 		  email = form.cleaned_data['email'],
						  	  perms = perms,
			)
			#sending mail
			send_templated_email(subject = 'Создан аккаунт', 
				email_template_name = 'user_manager_create_email.html',
				email_context = {'username' : user.username,
								 'password' : password,
								 'perms' : perms_to_list(perms),
								 'admin' : user.is_staff,
                                 'perms_to_language' : perms_to_language,
								 },
				recipients = user.email,
			)
			status = "success"
			return HttpResponse(status)
		
	else:
		form = CreateUserForm()
		
	return render(request, 'user_manager_create.html', {'form' : form})
Ejemplo n.º 2
0
def transfer(request):
    import csv
    import os
    from user_manager.source_functions import create_user
    from datetime import datetime
    from django.db import IntegrityError
    from base_source_functions import send_templated_email
    from dashboard.common_profile.source_functions import perms_to_list
    from user_manager.permissions import perms_to_language
    fields = ('Фамилия','Имя','Отчество','e-mail','Дата рождения','Телефон','Город рождения','Город проживания','Улица','Дом','Корпус','Квартира','Индекс','Тип документа','Серия','Номер','Кем выдан','Когда выдан','Действителен до', 'Код подразделения', 'ФИО отца','Телефон отца','ФИО матери','Телефон матери','Год выпуска','Школа','Учитель физики(истории)','Учитель математики(обществознания)','Директор школы')

    with open(os.path.join(BASE_DIR,'db.csv'),'rb') as csvfile:
        reader = csv.DictReader(csvfile, fieldnames=fields,delimiter=';')
        for row in reader:
            if (len(row['e-mail'])<30) and (len(row['e-mail'])>0):
                try:
                    password = User.objects.make_random_password(length = 8)
                    perms = {
					          			'event_worker' : False,
								        'teacher' : False,
								        'mentor' : False,
								        'observer' : False,
								        'regular' : True,
                                        'admin' : False,
			        }
                    user = create_user(username=row['e-mail'],email=row['e-mail'],password=password,perms=perms)
                    userdata = user.UserData
                    userdata.first_name = row['Имя']
                    userdata.second_name = row['Отчество']
                    userdata.last_name = row['Фамилия'] 
                    userdata.phone = row['Телефон']
                    userdata.save() 
                    regular = userdata.RegularUser
                    regular.birthdate = datetime.strptime(row['Дата рождения'], '%d.%m.%Y').date()
                    regular.birthplace = row['Город рождения']
                    regular.city = row['Город проживания']
                    regular.street = row['Улица']
                    regular.building = row['Дом']
                    regular.housing = row['Корпус']
                    regular.appartment = row['Квартира']
                    regular.postal_code = row['Индекс']
                    regular.parent_1 = row['ФИО отца']
                    regular.parent_1_phone = row['Телефон отца']
                    regular.parent_2 = row['ФИО матери']
                    regular.parent_2_phone = row['Телефон матери']
                    regular.grad_date = row['Год выпуска']
                    regular.modified = False
                    regular.save()
                    send_templated_email(subject = 'Создан аккаунт', 
				    email_template_name = 'regular_create_email.html',
				    email_context = {'username' : user.username,
								 'password' : password,
								 'perms' : perms_to_list(perms),
								 'admin' : user.is_staff,
                                 'perms_to_language' : perms_to_language,
								 },
				    recipients = user.email,
			)
                except IntegrityError:
                    pass
            else:
                pass                      

 
    return HttpResponse('success')