def signlogup(request): data = get_global_data(request) data['message'] = False if request.user.is_authenticated(): return HttpResponseRedirect('/profile/') elif request.method == 'POST': form = LoginForm(request.POST) if form.is_valid() and 'password' in request.POST: username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: request.session.set_expiry(60*60*24*365) login(request, user) return HttpResponseRedirect('/profile/') else: data['message'] = 'Эккаунт заблокирован' else: data['message'] = 'Неправильная пара логин/пароль' elif 'username' in request.POST: username = request.POST['username'] try: user = User.objects.create_user(username, username, username) user.is_active = False user.is_staff = False activate_code = md5.new(username).hexdigest() send_html_mail('Activation letter', username, {'name': username, 'code': activate_code}, 'emails/activate_letter.html', sender='*****@*****.**') user.save() profile = Profile(user = user, phone = '+7 ') profile.save() return { 'message': 'Спасибо за регистрацию. Вам выслано письмо с инструкциями по активации эккаунта.' } except: if User.objects.get(username=username) is not None: data['message'] = 'Пользователь с таким e-mail уже зарегистрирован' else: data['message'] = 'Неизвестная ошибка при добавлении пользователя. Обратитесь в поддержку' else: form = LoginForm() data['login_form'] = form return data
def save(self): user = User.objects.get(id = self.client) send_html_mail(u'Ваш заказ изменён', user.email, {'order_info': self}, 'emails/order_status_changed_mail.html', sender='*****@*****.**') super(ccOrder, self).save()
def order(request): data = get_global_data(request) user_id = request.user.id if request.method == 'POST': # If the form has been submitted... order = Order(request.POST, request.FILES) # A form bound to the POST data if order.is_valid(): # All validation rules pass # Создаём переменные для принятых данных product = order.cleaned_data['product'] format = order.cleaned_data['format'] time = order.cleaned_data['time'] circulation = order.cleaned_data['circulation'] paper = order.cleaned_data['paper'] chromacity = order.cleaned_data['chromacity'] cost = order.cleaned_data['cost'] not_cash = order.cleaned_data['not_cash'] need_deliver = order.cleaned_data['need_deliver'] # Создаём переменные для оставшихся данных,которых нет в форме is_delivered = False order_status = 0 client = user_id # Создаём новый объект Заказа new_order = OrderModel( client = client, product = product, format = format, time = time, circulation = circulation, paper = paper, chromacity = chromacity, cost = cost, not_cash = not_cash, need_deliver = need_deliver, is_delivered = is_delivered, order_status = order_status, enter_date = datetime.datetime.now(), end_date = datetime.datetime.now(), ) # Попробуем записать на сервер первый файл try: handle_uploaded_file(request.FILES['file1'], 'client_files') file1_is_uploadded = True except: file1_is_uploadded = False # Попробуем записать на сервер второй файл try: handle_uploaded_file(request.FILES['file2'], 'client_files') file2_is_uploadded = True except: file2_is_uploadded = False if file1_is_uploadded: new_order.file1 = request.FILES['file1'] if file2_is_uploadded: new_order.file2 = request.FILES['file2'] # Генерация txt-файла для 1C f = open(DIRNAME_TO_WRITABLE_DIR+'/media/orders_logs/client-'+unicode(client)+'_'+unicode(datetime.datetime.now())+'.txt', 'w') order_desc = unicode(client) + '|' + unicode(product) + '|' + unicode(format) + '|' + unicode(time) + '|' + unicode(circulation) + '|' + unicode(paper) + '|' + unicode(chromacity) + '|' + unicode(cost) + '|' + unicode(not_cash) + '|' + unicode(need_deliver) + '|' + unicode(datetime.datetime.now()) #f.write(order_desc) f.close() # Отправляем пользователю сообщение, что его заказ - принят send_html_mail('Ваш заказ принят', request.user.email, {'name': request.user.first_name + ' ' + request.user.last_name}, 'emails/order_sent_mail.html', sender='*****@*****.**') # Сохраняем новый заказ в базу new_order.save() return HttpResponseRedirect('/profile/orders/') # Redirect after POST else: order = Order() # An unbound form data['order'] = order return data