def signup(request): error = [False, ''] form = SignUpForm() if request.method == 'POST': form = SignUpForm(request.POST) userdata = (request.POST['username']).split() username = userdata[0] first_name = userdata[1] last_name = userdata[2] mail = request.POST['mail'] password1 = request.POST['password1'] password2 = request.POST['password2'] if form.is_valid() and password1 == password2 and len(password1) >= 6: user = User.objects.create_user(username, mail, password1) user.first_name = first_name user.last_name = last_name user.is_active = True user.save() userprofile = UserProfile() userprofile.user = user userprofile.vk = '' userprofile.facebook = '' userprofile.twitter = '' userprofile.phone = '' userprofile.save() # Добавление действия в ленту addAction(user, 'присоединился к сервису') setAch(user, 1) return redirect('/auth/in') else: print('form not valid!') error[0] = True error[1] = 'Введенные данные содержат ошибку' context = {"form": form, 'title': 'Регистрация', 'error': error[0], 'error_text': error[1]} return render(request, 'sign-up.html', context)
def add(request): if not request.user.is_authenticated(): return redirect('/auth/in') UpdateStatus(request.user) error = [False, ''] form = NoteAddForm() white = request.GET.get('white', False) if request.method == 'POST': data = request.POST form = NoteAddForm(data) title = data['title'] content = data['content'] if form.is_valid() and len(content) >= 10 and len(title) >= 2: note = Note() note.title = title note.content = content note.login = request.user note.pub_date = timezone.now() note.save() # добавление действия в таблицу addAction(request.user, 'добавил заметку <a href="/notes/%s/">"%s"</a>' % (note.id, note.title)) setAch(request.user, 2) return redirect('/notes/') else: error_message = 'Произошла ошибка' if len(content) < 10 or len(title) < 2: error_message = 'Заголовок должен быть не менее 2 символов. Содержание заметки не менее 10-ти символов' error[0] = True error[1] = error_message context = {'title': 'Заметки', 'form':form, 'error':error[0], 'error_text': error[1], 'white': white,} return render(request, 'notes_add.html', context)
def add(request): if not request.user.is_authenticated(): return redirect('/auth/in') UpdateStatus(request.user) error = [False, ''] form = EventAddForm() if request.method == 'POST': data = request.POST form = EventAddForm(data) if form.is_valid() and len(data['title']) >= 2 and len(data['date']) >= 10: event = Event() event.title = data['title'] event.description = data['description'] event.date = data['date'] event.login = request.user if 'is_required' in data: event.is_required = True else: event.is_required = False event.save() #Добавление действия в базу addAction(request.user, 'добавил мероприятие <a href="/events/%s">%s</a>' % (event.id, data['title'])) setAch(request.user, 14) return redirect('/') else: error_message = 'Произошла ошибка' if len(data['title'])< 2 or len(data['date']) < 10: error_message = 'Введите правильное название мероприятия и дату' error[0] = True error[1] = error_message context = {'title': 'Мероприятия', 'form': form, 'error':error[0], 'error_text': error[1]} return render(request, 'event_add.html', context)
def add(request): if not request.user.is_authenticated(): return redirect('/auth/in') UpdateStatus(request.user) error = [False, ''] form = NoteAddForm() if request.method == 'POST': data = request.POST form = NoteAddForm(data) title = data['title'] content = data['content'] if form.is_valid() and len(content) >= 10 and len(title) >= 2: note = Note() note.title = title note.content = content note.login = request.user note.pub_date = timezone.now() note.save() # добавление действия в таблицу addAction(request.user, 'добавил заметку <a href="/notes/%s/">"%s"</a>' % (note.id, note.title)) setAch(request.user, 2) return redirect('/notes/') else: error_message = 'Произошла ошибка' if len(content) < 10 or len(title) < 2: error_message = 'Заголовок должен быть не менее 2 символов. Содержание заметки не менее 10-ти символов' error[0] = True error[1] = error_message context = {'title': 'Заметки', 'form':form, 'error':error[0], 'error_text': error[1]} return render(request, 'notes_add.html', context)
def upload_photo(request): if not request.user.is_authenticated(): return redirect('/auth/in') if request.method == 'POST': form = UploadAvatarForm(request.POST, request.FILES) if form.is_valid(): try: newavatar = form.save(commit = False) me = UserProfile.objects.get(user = request.user) me.avatar = request.FILES['avatar'] me.save() addAction(request.user, 'изменил свою фотографию<br><img src="%s" class="ui small image">' % (avatar(request.user))) setAch(request.user, 4) except MultiValueDictKeyError: pass return redirect('/users/settings/')
def upload_photo(request): if not request.user.is_authenticated(): return redirect('/auth/in') if request.method == 'POST': form = UploadAvatarForm(request.POST, request.FILES) if form.is_valid(): try: newavatar = form.save(commit=False) me = UserProfile.objects.get(user=request.user) me.avatar = request.FILES['avatar'] me.save() addAction( request.user, 'изменил свою фотографию<br><img src="%s" class="ui small image">' % (avatar(request.user))) setAch(request.user, 4) except MultiValueDictKeyError: pass return redirect('/users/settings/')
def add(request): if not request.user.is_authenticated(): return redirect('/auth/in') UpdateStatus(request.user) error = [False, ''] form = AddPollForm() if request.method == 'POST': data = request.POST form = AddPollForm(data) options = data['options'].split('\n') if form.is_valid() and len(options) >= 2: poll = Question() poll.login = request.user poll.title = data['title'] poll.type = data['type'] poll.pub_date = timezone.now() if 'is_anon' in data: poll.is_anon = True else: poll.is_anon = False poll.is_closed = False poll.save() for opt in options: answer = Answer() answer.text = opt answer.save() poll.choices.add(answer) addAction( request.user, 'добавил опрос <a href="/polls/%s/">%s</a>' % (poll.id, poll.title)) setAch(request.user, 3) return redirect('/polls/') else: error_message = 'Проверьте правильность введенных данных. Количество вариантов ответа должно быть не менее двух' error[0] = True error[1] = error_message context = { 'title': 'Добавить опрос', 'form': form, 'error': error[0], 'error_message': error[1], } return render(request, 'add_poll.html', context)
def add(request): if not request.user.is_authenticated(): return redirect('/auth/in') UpdateStatus(request.user) error = [False, ''] form = EventAddForm() if request.method == 'POST': data = request.POST form = EventAddForm(data) if form.is_valid() and len(data['title']) >= 2 and len( data['date']) >= 10: event = Event() event.title = data['title'] event.description = data['description'] event.date = data['date'] event.login = request.user if 'is_required' in data: event.is_required = True else: event.is_required = False event.save() #Добавление действия в базу addAction( request.user, 'добавил мероприятие <a href="/events/%s">%s</a>' % (event.id, data['title'])) setAch(request.user, 14) return redirect('/') else: error_message = 'Произошла ошибка' if len(data['title']) < 2 or len(data['date']) < 10: error_message = 'Введите правильное название мероприятия и дату' error[0] = True error[1] = error_message context = { 'title': 'Мероприятия', 'form': form, 'error': error[0], 'error_text': error[1] } return render(request, 'event_add.html', context)
def signup(request): error = [False, ''] form = SignUpForm() if request.method == 'POST': form = SignUpForm(request.POST) userdata = (request.POST['username']).split() username = userdata[0] first_name = userdata[1] last_name = userdata[2] mail = request.POST['mail'] password1 = request.POST['password1'] password2 = request.POST['password2'] if form.is_valid() and password1 == password2 and len(password1) >= 6: user = User.objects.create_user(username, mail, password1) user.first_name = first_name user.last_name = last_name user.is_active = True user.save() userprofile = UserProfile() userprofile.user = user userprofile.vk = '' userprofile.facebook = '' userprofile.twitter = '' userprofile.phone = '' userprofile.save() # Добавление действия в ленту addAction(user, 'присоединился к сервису') setAch(user, 1) return redirect('/auth/in') else: print('form not valid!') error[0] = True error[1] = 'Введенные данные содержат ошибку' context = { "form": form, 'title': 'Регистрация', 'error': error[0], 'error_text': error[1] } return render(request, 'sign-up.html', context)
def add(request): if not request.user.is_authenticated(): return redirect('/auth/in') UpdateStatus(request.user) error = [False, ''] form = AddPollForm() if request.method == 'POST': data = request.POST form = AddPollForm(data) options = data['options'].split('\n') if form.is_valid() and len(options) >= 2: poll = Question() poll.login = request.user poll.title = data['title'] poll.type = data['type'] poll.pub_date = timezone.now() if 'is_anon' in data: poll.is_anon = True else: poll.is_anon = False poll.is_closed = False poll.save() for opt in options: answer = Answer() answer.text = opt answer.save() poll.choices.add(answer) addAction(request.user, 'добавил опрос <a href="/polls/%s/">%s</a>' % (poll.id, poll.title)) setAch(request.user, 3) return redirect('/polls/') else: error_message = 'Проверьте правильность введенных данных. Количество вариантов ответа должно быть не менее двух' error[0] = True error[1] = error_message context = { 'title': 'Добавить опрос', 'form': form, 'error': error[0], 'error_message': error[1], } return render(request, 'add_poll.html', context)