示例#1
0
文件: views.py 项目: apcom52/Yoda-old
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)
示例#2
0
文件: views.py 项目: apcom52/Yoda
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)
示例#3
0
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)
示例#4
0
文件: views.py 项目: apcom52/Yoda
def sold_inventory_item(request):
	from user.models import UserProfile	
	user = UserProfile.objects.get(user = request.user)

	if request.method == 'POST':
		data = request.POST
		item_id = data.get('id', False)
		if item_id:
			useritem = UserInventoryItem.objects.get(pk = item_id)
			if not useritem.stolen:
				user.bonus_points += useritem.price
			useritem.stolen = True
			useritem.save()

			user_item_text = ''
			item = Item.objects.get(pk = useritem.item_id)
			if useritem.quality == 1:
				user_item_text = "<span class='quality-1'>"
			elif useritem.quality == 2:
				user_item_text = "<span class='quality-2'>"
			elif useritem.quality == 3:
				user_item_text = "<span class='quality-3'>"
			user_item_text = user_item_text + item.title + "</span>" 
			

			user.save()
			addAction(request.user, 'продал %s из инвентаря за %s <i class="trophy icon"></i>' % (user_item_text, useritem.price,), False)		
			
			request.user.userprofile.save()
			return HttpResponse('ok', content_type='text/html')	
		return HttpResponse('ss' + item_id + 's', content_type='text/html')	
	return HttpResponse('no', content_type='text/html')	
示例#5
0
文件: views.py 项目: apcom52/Yoda-old
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)
示例#6
0
文件: models.py 项目: apcom52/Yoda
	def save_model(self, request, obj, form, change):
		from timetable.utils import addAction, sendNotification
		achievement = obj.ach_id
		user = obj.login
		sendNotification({
			'user': user,
			'title': 'Новое достижение',
			'text': 'Вы получили новое достижение "%s"' % (achievement.title,),
			'type': 3,
		})
		addAction(user, 'получил достижение<div class="comments"><div class="comment"><span class="avatar"><img src="%s"></span><div class="content"><span class="author">%s</span><div class="text">%s</div></div></div></div>' % (achievement.icon, achievement.title, achievement.description))
		obj.save()
示例#7
0
文件: views.py 项目: apcom52/Yoda
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/')
示例#8
0
文件: views.py 项目: apcom52/Yoda-old
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/')
示例#9
0
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)
示例#10
0
文件: views.py 项目: apcom52/Yoda-old
def poll_comment(request):
	if not request.user.is_authenticated(): return redirect('/auth/in')
	if request.method == 'POST':
		data = request.POST
		poll_id = data['item_id']
		try:
			poll = Question.objects.get(id = poll_id)
			user = request.user
			text = data['comment']
			text = text.strip()
			if len(text) >= 1:
				comment = PollComment()
				comment.login = user
				comment.poll = poll
				comment.comment = text
				comment.pub_date = timezone.now()
				comment.save()		
				addAction(user, 'добавил комментарий в опросе <a href="/polls/%s">%s</a>' % (poll.id, poll.title))
		except ObjectDoesNotExist:
			pass	
	return redirect('/polls/%s/' % (poll_id,))
示例#11
0
文件: views.py 项目: apcom52/Yoda
def note_comment(request):
	if not request.user.is_authenticated(): return redirect('/auth/in')
	if request.method == 'POST':
		data = request.POST
		note_id = data['item_id']
		try:
			note = Note.objects.get(id = int(note_id))
			user = request.user
			text = data['comment']
			text = text.strip()
			if len(text) >= 1:
				comment = NoteComment()
				comment.login = user
				comment.note = note
				comment.comment = text
				comment.pub_date = timezone.now()
				comment.save()		
				addAction(user, 'добавил комментарий в заметке <a href="/notes/%s">%s</a>' % (note.id, note.title))
		except ObjectDoesNotExist:
			pass	
	return redirect('/notes/%s/' % (note_id,))
示例#12
0
文件: views.py 项目: apcom52/Yoda-old
def event_comment(request):
	if not request.user.is_authenticated(): return redirect('/auth/in')
	if request.method == 'POST':
		data = request.POST
		event_id = data['item_id']
		try:
			event = Event.objects.get(id = int(event_id))
			user = request.user
			text = data['comment']
			text = text.strip()
			if len(text) >= 1:
				comment = EventComment()
				comment.login = user
				comment.event = event
				comment.comment = text
				comment.pub_date = timezone.now()
				comment.save()		
				addAction(user, 'добавил комментарий о мероприятии <a href="/events/%s">%s</a>' % (event.id, event.title))
		except ObjectDoesNotExist:
			pass	
	return redirect('/events/%s/' % (event_id,))
示例#13
0
def note_comment(request):
	if not request.user.is_authenticated(): return redirect('/auth/in')
	if request.method == 'POST':
		data = request.POST
		note_id = data['item_id']
		try:
			note = Note.objects.get(id = int(note_id))
			user = request.user
			text = data['comment']
			text = text.strip()
			if len(text) >= 1:
				comment = NoteComment()
				comment.login = user
				comment.note = note
				comment.comment = text
				comment.pub_date = timezone.now()
				comment.save()		
				addAction(user, 'добавил комментарий в заметке <a href="/notes/%s">%s</a>' % (note.id, note.title))
		except ObjectDoesNotExist:
			pass	
	return redirect('/notes/%s/' % (note_id,))
示例#14
0
文件: views.py 项目: apcom52/Yoda-old
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)
示例#15
0
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)
示例#16
0
文件: views.py 项目: apcom52/Yoda-old
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)
示例#17
0
文件: views.py 项目: apcom52/Yoda-old
def event_comment(request):
    if not request.user.is_authenticated(): return redirect('/auth/in')
    if request.method == 'POST':
        data = request.POST
        event_id = data['item_id']
        try:
            event = Event.objects.get(id=int(event_id))
            user = request.user
            text = data['comment']
            text = text.strip()
            if len(text) >= 1:
                comment = EventComment()
                comment.login = user
                comment.event = event
                comment.comment = text
                comment.pub_date = timezone.now()
                comment.save()
                addAction(
                    user,
                    'добавил комментарий о мероприятии <a href="/events/%s">%s</a>'
                    % (event.id, event.title))
        except ObjectDoesNotExist:
            pass
    return redirect('/events/%s/' % (event_id, ))
示例#18
0
def poll_comment(request):
    if not request.user.is_authenticated(): return redirect('/auth/in')
    if request.method == 'POST':
        data = request.POST
        poll_id = data['item_id']
        try:
            poll = Question.objects.get(id=poll_id)
            user = request.user
            text = data['comment']
            text = text.strip()
            if len(text) >= 1:
                comment = PollComment()
                comment.login = user
                comment.poll = poll
                comment.comment = text
                comment.pub_date = timezone.now()
                comment.save()
                addAction(
                    user,
                    'добавил комментарий в опросе <a href="/polls/%s">%s</a>' %
                    (poll.id, poll.title))
        except ObjectDoesNotExist:
            pass
    return redirect('/polls/%s/' % (poll_id, ))
示例#19
0
文件: views.py 项目: apcom52/Yoda
def send_catapult(request):
	import random
	from timetable.utils import sendNotification

	if request.method == 'POST':
		data = request.POST
		item_id = data.get('item_id', False)
		if item_id:
			item = UserInventoryItem.objects.get(id = item_id)
			if item.stolen:
				return HttpResponse('no', content_type='text/html')

			users = User.objects.all().exclude(id = request.user.id).filter(is_active = True)
			rand_user = random.choice(users)

			new_item = UserInventoryItem()
			new_item.user = rand_user
			new_item.type = item.type
			new_item.item_id = item.item_id
			new_item.quality = item.quality
			new_item.price = item.price
			new_item.save()

			#Узнаем ID катапульты и убираем ее из инвентаря
			catapult_quality = 1
			catapult = Item.objects.get(title = 'Подаркопульта')
			catapult_id = catapult.id
			my_catapultes = UserInventoryItem.objects.all().filter(item_id = catapult_id).filter(user = request.user).filter(stolen = False).latest('id')
			if my_catapultes.quality == 2:
				catapult_quality = 2
			if my_catapultes.quality == 3:
				catapult_quality = 3
			my_catapultes.stolen = True
			my_catapultes.save()

			item.stolen = True
			item.save()

			catapult = Catapult()
			catapult.from_user = request.user
			catapult.to_user = rand_user
			catapult.item = new_item
			catapult.save()

			#Прибавляем очки пользователю
			from user.models import UserProfile	
			user = UserProfile.objects.get(user = request.user)

			catapult_text = "<span class='quality-%s'>подаркопульту</span>" % (catapult_quality,)
			if catapult_quality == 1:								
				if item.quality == 1:
					user.bonus_points += 5
				if item.quality == 2:
					user.bonus_points += 15
				if item.quality == 3:
					user.bonus_points += 25
			elif catapult_quality == 2:
				if item.quality == 1:
					user.bonus_points += 15
				if item.quality == 2:
					user.bonus_points += 35
				if item.quality == 3:
					user.bonus_points += 50
			elif catapult_quality == 3:				
				if item.quality == 1:
					user.bonus_points += 30
				if item.quality == 2:
					user.bonus_points += 55
				if item.quality == 3:
					user.bonus_points += 100

			db_item = Item.objects.get(pk = item.item_id)
			user_item_text = '<span class="quality-%s">%s</span>' % (item.quality, db_item.title,)

			user.save()

			sendNotification({
				'user': rand_user,
				'title': "Вы получили подарок",
				'text': "%s %s запустил в вас %s" % (request.user.get_full_name(), db_item.title),
				'type': 2,
			})
			addAction(request.user, 'запустил %s и бросил %s в <b>%s</b>' % (catapult_text, user_item_text, rand_user.get_full_name(),), False)
			return HttpResponse('%s' % (rand_user.get_full_name(),), content_type='text/html')
		return HttpResponse('no', content_type='text/html')
	else:
		return HttpResponse('no', content_type='text/html')