Esempio 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})
Esempio n. 2
0
def decline_request(request, event_id, request_id):    
    current_rq = Request.objects.get(id=request_id)
    event = current_rq.event
    current_rq.status = 'отклонена'
    current_rq.save()
    send_templated_email(
                         subject='Отклонение заявки',
                         email_template_name='events_manage_decline_email.html',
                         email_context={
                            'event': event
                         },
                         recipients=current_rq.user.data.user.email,
                         fail_silently=False,
                        )
    return redirect('events_manage_show_requests', event_id = event.id)
Esempio n. 3
0
def send(request):
    user = request.user
    if request.method == "POST":
        form = FeedBackForm(request.POST)
        if form.is_valid():
            cleaned_data = form.cleaned_data
            if cleaned_data["problem_type"] == "T":
                recipients = ["*****@*****.**", "*****@*****.**", "*****@*****.**"]
            else:
                recipients = ["*****@*****.**"]
            text = (
                cleaned_data["text"]
                + "\n\n\n"
                + "From: "
                + user.UserData.__unicode__()
                + "\n"
                + "E-mail: "
                + user.email
            )
            template = get_template_from_string(text)
            status = "success"
            try:
                send_templated_email(
                    subject=cleaned_data["subject"],
                    email_context={},
                    recipients=recipients,
                    template_file=template,
                    fail_silently=False,
                )
            except Exception as e:
                print(str(e))
                status = "Error sending mail"
            return HttpResponse(status)

    else:
        form = FeedBackForm()

    return render(request, "feedback_form.html", {"form": form})
Esempio n. 4
0
def accept_request(request, event_id, request_id):
    current_rq = Request.objects.get(id=request_id)
    user = current_rq.user
    event = current_rq.event  
    event_id = event.id
    if request.method == "POST":
        form = PriceChoiceForm(request.POST,event_id=event_id)
        if form.is_valid():
            spec = current_rq.user                
            current_rq.status = 'одобрена'
            p_group = form.cleaned_data['price_group']
            files =  glob.glob(os.path.join(os.path.join(settings.EVENT_ATTACHMENTS_DIR,str(event_id)), '*'))
            try:
                template_file = get_template_from_string(EmailTemplate.objects.get(event = event).text)
                send_templated_email(
                        subject='Подтверждение заявки',
                        template_file = template_file,
                        email_context={
                        'event': event.name,
                        'price': p_group.price,                        
                        },
	        			recipients=user.data.user.email,
                        fail_silently=False,
		            	files=files,
                )
            except ObjectDoesNotExist:
                pass #FIXME
            current_rq.price_group = p_group
            current_rq.save()
            status = "success"
            return HttpResponse(status)
    else:
        form = PriceChoiceForm(event_id=event_id) 
   
    return render(request,
                  'events_manage_price_choice_form.html',
                  {'form':form, 'event':event})
Esempio n. 5
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')