def event(request, id): if not request.user.is_authenticated(): return redirect('/auth/in') try: UpdateStatus(request.user) _bingo = bingo(request.user) event = Event.objects.get(id = id) visit = [] not_sure = [] no_visit = [] your_answer = 0 try: visiters = UserVisitEvent.objects.all().filter(event = event) for visiter in visiters: current = { 'username': '******' % (visiter.login.first_name, visiter.login.last_name), 'user_id': visiter.login.id, 'avatar': avatar(visiter.login), } if visiter.login == request.user: your_answer = visiter.answer if visiter.answer == 1: visit.append(current) elif visiter.answer == 2: not_sure.append(current) elif visiter.answer == 3: no_visit.append(current) except ObjectDoesNotExist: pass comments = [] comments_list = EventComment.objects.all().filter(event = event) for comment in comments_list: comment_text = comment.comment#parseSmiles(comment.comment) comments.append({ 'username': '******' %(comment.login.first_name, comment.login.last_name), 'avatar': avatar(comment.login), 'text': comment_text, 'date': comment.pub_date, 'user_id': comment.login.id, }) context = { 'event': event, 'visit': visit, 'not_sure': not_sure, 'no_visit': no_visit, 'your_answer': your_answer, 'author': event.login, 'author_username': '******' % (event.login.first_name, event.login.last_name), 'author_avatar': avatar(event.login), 'comments': comments, 'comment_url': '/events/comment/', 'comment_item_id': event.id, 'bingo': _bingo, #'smiles': getSmiles(request.user), } return render(request, 'event.html', context) except ObjectDoesNotExist: return redirect('/polls/')
def note(request, id): if not request.user.is_authenticated(): return redirect('/auth/in') try: bonus = setBonusPoints(request.user) _bingo = bingo(request.user) UpdateStatus(request.user) context = {} note = Note.objects.get(id = id) note.views += 1 note.save() us = note.login user_is_author = False white = request.GET.get('white', False) try: if request.user.username == us.username or request.user.is_admin: user_is_author = True except AttributeError: pass username = us.first_name + ' ' + us.last_name comments = [] comments_list = NoteComment.objects.all().filter(note = note) for comment in comments_list: comment_text = comment.comment#parseSmiles(comment.comment) comments.append({ 'username': '******' %(comment.login.first_name, comment.login.last_name), 'avatar': avatar(comment.login), 'text': comment_text, 'date': comment.pub_date, 'user_id': comment.login.id, }) notes = Note.objects.order_by('-pub_date').all() #Подгатавливаем контент content = wiki2html(note.content) context = { 'title': note.title, 'content': content, 'login': us.id, 'pub_date': note.pub_date, 'views': note.views, 'user_is_author': user_is_author, 'username': username, 'id': note.id, 'user': us, 'note': note, 'comments': comments, 'comment_url': '/notes/comment/', 'comment_item_id': note.id, 'bingo': _bingo, 'bonus': bonus, 'notes': notes, 'white': white, #'smiles': getSmiles(request.user), } return render(request, 'note.html', context) except ObjectDoesNotExist: return redirect('/notes/')
def user_settings(request): if not request.user.is_authenticated(): return redirect('/auth/in') UpdateStatus(request.user) avatar_upload = UploadAvatarForm() change_password = ChangePasswordForm() set_contacts = SetContactForm(initial = {'vk': request.user.userprofile.vk, 'facebook': request.user.userprofile.facebook, 'twitter': request.user.userprofile.twitter, 'phone': request.user.userprofile.phone}) error_password = request.GET.get('error_password', False) context = { 'title': 'Настройки (beta)', 'current_avatar': avatar(request.user), 'avatar_upload': avatar_upload, 'change_password': change_password, 'set_contacts': set_contacts, 'error_password': error_password, } return render(request, 'settings.html', context)
def note(request, id): if not request.user.is_authenticated(): return redirect('/auth/in') try: UpdateStatus(request.user) context = {} note = Note.objects.get(id = id) note.views += 1 note.save() us = note.login user_is_author = False try: if request.user.username == us.username or request.user.is_admin: user_is_author = True except AttributeError: pass username = us.first_name + ' ' + us.last_name comments = [] comments_list = NoteComment.objects.all().filter(note = note) for comment in comments_list: comments.append({ 'username': '******' %(comment.login.first_name, comment.login.last_name), 'avatar': avatar(comment.login), 'text': comment.comment, 'date': comment.pub_date, 'user_id': comment.login.id, }) #Подгатавливаем контент content = wiki2html(note.content) context = { 'title': note.title, 'content': content, 'login': us.id, 'pub_date': note.pub_date, 'views': note.views, 'user_is_author': user_is_author, 'username': username, 'id': note.id, 'user': us, 'note': note, 'comments': comments, 'comment_url': '/notes/comment/', 'comment_item_id': note.id, } return render(request, 'note.html', context) except ObjectDoesNotExist: return redirect('/notes/')
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 settings(request): if not request.user.is_authenticated(): return redirect('/auth/in') UpdateStatus(request.user) avatar_upload = UploadAvatarForm() change_password = ChangePasswordForm() set_contacts = SetContactForm( initial={ 'vk': request.user.userprofile.vk, 'facebook': request.user.userprofile.facebook, 'twitter': request.user.userprofile.twitter, 'phone': request.user.userprofile.phone }) error_password = request.GET.get('error_password', False) context = { 'title': 'Настройки', 'current_avatar': avatar(request.user), 'avatar_upload': avatar_upload, 'change_password': change_password, 'set_contacts': set_contacts, 'error_password': error_password, } return render(request, 'settings.html', context)
def event(request, id): if not request.user.is_authenticated(): return redirect('/auth/in') try: UpdateStatus(request.user) event = Event.objects.get(id=id) visit = [] not_sure = [] no_visit = [] your_answer = 0 try: visiters = UserVisitEvent.objects.all().filter(event=event) for visiter in visiters: current = { 'username': '******' % (visiter.login.first_name, visiter.login.last_name), 'user_id': visiter.login.id, 'avatar': avatar(visiter.login), } if visiter.login == request.user: your_answer = visiter.answer if visiter.answer == 1: visit.append(current) elif visiter.answer == 2: not_sure.append(current) elif visiter.answer == 3: no_visit.append(current) except ObjectDoesNotExist: pass comments = [] comments_list = EventComment.objects.all().filter(event=event) for comment in comments_list: comments.append({ 'username': '******' % (comment.login.first_name, comment.login.last_name), 'avatar': avatar(comment.login), 'text': comment.comment, 'date': comment.pub_date, 'user_id': comment.login.id, }) context = { 'event': event, 'visit': visit, 'not_sure': not_sure, 'no_visit': no_visit, 'your_answer': your_answer, 'author': event.login, 'author_username': '******' % (event.login.first_name, event.login.last_name), 'author_avatar': avatar(event.login), 'comments': comments, 'comment_url': '/events/comment/', 'comment_item_id': event.id, } return render(request, 'event.html', context) except ObjectDoesNotExist: return redirect('/polls/')
def getProfileInfo(id): user = User.objects.get(id=id) username = user.first_name + ' ' + user.last_name avt = avatar(user) morph = pymorphy2.MorphAnalyzer() #Онлайн is_online = isOnline(user) last_visit = user.userprofile.last_visit points = pointsumm(user) points_morph = morph.parse('очко')[0] friends = [] friends_list = User.objects.all().exclude( id=id).order_by('-userprofile__last_visit') for friend in friends_list: fr_user = User.objects.get(id=friend.id) is_friend_online = isOnline(fr_user) current = { 'user_id': friend.id, 'username': '******' % (friend.first_name, friend.last_name), 'avatar': avatar(friend), 'is_online': is_friend_online, } friends.append(current) #получение звания пользователя rank = getrank(user) #получение удобочитаемого номера last_phone = user.userprofile.phone phone = '+7 (%s)-%s-%s-%s' % (last_phone[0:3], last_phone[3:6], last_phone[6:8], last_phone[8:10]) act_list = Action.objects.all().filter(login=user).order_by('-pub_date') actions_morph = morph.parse('действие')[0] actions = [] for action in act_list: user = action.login avt = avatar(user) cur_action = { 'avatar': avt, 'username': username, 'user_id': user.id, 'action_text': action.text, 'pub_date': action.pub_date, } actions.append(cur_action) my_last_achievements = [] #try: my_ach = AchUnlocked.objects.all().filter(login=user).order_by('-pub_date') last_achievements = my_ach[:5] for ach in last_achievements: my_last_achievements.append({ 'title': ach.ach_id.title, 'icon': ach.ach_id.icon, 'description': ach.ach_id.description, }) ach_counter_morph = morph.parse('достижение')[0] context = { 'title': username, 'user': user, 'bodyclass': 'profile-page', 'avatar': avt, 'friends': friends, 'actions': actions, 'active_page': 1, 'actions_morph': actions_morph.make_agree_with_number(len(act_list)).word, 'xp': points, 'xp_morph': points_morph.make_agree_with_number(points).word, 'ach_counter': len(my_ach), 'ach_counter_morph': ach_counter_morph.make_agree_with_number(len(my_ach)).word, 'last_achievements': my_last_achievements, 'rank': rank, 'contacts': user.userprofile, 'phone': phone, 'is_online': is_online, 'last_visit': last_visit, } return context
def poll(request, id): if not request.user.is_authenticated(): return redirect('/auth/in') try: UpdateStatus(request.user) poll = Question.objects.get(id=id) voted_count = len(QueAns.objects.all().filter(question=poll)) you_voted = False if poll.login == request.user or request.user.is_superuser: is_author = True else: is_author = False votes = [] comments = [] comments_list = PollComment.objects.all().filter(poll=poll) for comment in comments_list: comments.append({ 'username': '******' % (comment.login.first_name, comment.login.last_name), 'avatar': avatar(comment.login), 'text': comment.comment, 'date': comment.pub_date, 'user_id': comment.login.id, }) if QueAns.objects.filter(login=request.user, question=poll) or poll.is_closed: you_voted = True for choice in poll.choices.all(): voters = [] for us in QueAns.objects.all().filter(answer=choice.id): user = us.login current = { 'user': user, 'avatar': avatar(user), } voters.append(current) opt = { 'text': choice.text, 'users': voters, } votes.append(opt) else: if request.method == 'POST': data = request.POST for opt in data.getlist('options'): choice = QueAns() choice.login = request.user choice.question = poll choice.answer = int(opt) choice.save() return redirect('/polls/' + str(poll.id)) context = { 'title': poll.title, 'poll': poll, 'is_author': is_author, 'avatar': avatar(poll.login), 'voted_count': voted_count, 'you_voted': you_voted, 'votes': votes, 'comments': comments, 'comment_url': '/polls/comment/', 'comment_item_id': poll.id, } return render(request, 'poll.html', context) except ObjectDoesNotExist: return redirect('/polls/')
def poll(request, id): if not request.user.is_authenticated(): return redirect('/auth/in') try: UpdateStatus(request.user) poll = Question.objects.get(id = id) voted_count = len(QueAns.objects.all().filter(question = poll)) you_voted = False if poll.login == request.user or request.user.is_superuser: is_author = True else: is_author = False votes = [] comments = [] comments_list = PollComment.objects.all().filter(poll = poll) for comment in comments_list: comments.append({ 'username': '******' %(comment.login.first_name, comment.login.last_name), 'avatar': avatar(comment.login), 'text': comment.comment, 'date': comment.pub_date, 'user_id': comment.login.id, }) if QueAns.objects.filter(login = request.user, question = poll) or poll.is_closed: you_voted = True for choice in poll.choices.all(): voters = [] for us in QueAns.objects.all().filter(answer = choice.id): user = us.login current = { 'user': user, 'avatar': avatar(user), } voters.append(current) opt = { 'text': choice.text, 'users': voters, } votes.append(opt) else: if request.method == 'POST': data = request.POST for opt in data.getlist('options'): choice = QueAns() choice.login = request.user choice.question = poll choice.answer = int(opt) choice.save() return redirect('/polls/' + str(poll.id)) context = { 'title': poll.title, 'poll': poll, 'is_author': is_author, 'avatar': avatar(poll.login), 'voted_count': voted_count, 'you_voted': you_voted, 'votes': votes, 'comments': comments, 'comment_url': '/polls/comment/', 'comment_item_id': poll.id, } return render(request, 'poll.html', context) except ObjectDoesNotExist: return redirect('/polls/')
def getProfileInfo(id): user = User.objects.get(id = id) username = user.first_name + ' ' + user.last_name avt = avatar(user) morph = pymorphy2.MorphAnalyzer() #Онлайн is_online = isOnline(user) last_visit = user.userprofile.last_visit points = pointsumm(user) points_morph = morph.parse('очко')[0] friends = [] friends_list = User.objects.all().exclude(id = id).order_by('-userprofile__last_visit') for friend in friends_list: fr_user = User.objects.get(id = friend.id) is_friend_online = isOnline(fr_user) current = { 'user_id': friend.id, 'username': '******' % (friend.first_name, friend.last_name), 'avatar': avatar(friend), 'is_online': is_friend_online, } friends.append(current) #получение звания пользователя rank = getrank(user) #получение удобочитаемого номера last_phone = user.userprofile.phone phone = '+7 (%s)-%s-%s-%s' % (last_phone[0:3], last_phone[3:6], last_phone[6:8], last_phone[8:10]) act_list = Action.objects.all().filter(login = user).order_by('-pub_date') actions_morph = morph.parse('действие')[0] actions = [] for action in act_list: user = action.login avt = avatar(user) cur_action = { 'avatar': avt, 'username': username, 'user_id': user.id, 'action_text': action.text, 'pub_date': action.pub_date, } actions.append(cur_action) my_last_achievements = [] #try: my_ach = AchUnlocked.objects.all().filter(login = user).order_by('-pub_date') last_achievements = my_ach[:5] for ach in last_achievements: my_last_achievements.append({ 'title': ach.ach_id.title, 'icon': ach.ach_id.icon, 'description': ach.ach_id.description, }) ach_counter_morph = morph.parse('достижение')[0] context = { 'title': username, 'user': user, 'bodyclass': 'profile-page', 'avatar': avt, 'friends': friends, 'actions': actions, 'active_page': 1, 'actions_morph': actions_morph.make_agree_with_number(len(act_list)).word, 'xp': points, 'xp_morph': points_morph.make_agree_with_number(points).word, 'ach_counter': len(my_ach), 'ach_counter_morph': ach_counter_morph.make_agree_with_number(len(my_ach)).word, 'last_achievements': my_last_achievements, 'rank': rank, 'contacts': user.userprofile, 'phone': phone, 'is_online': is_online, 'last_visit': last_visit, } return 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/')