Exemplo n.º 1
0
def quickadd_todo(request, url):
	if request.method == 'GET':
		site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))
		form = QuickAddTodoForm(request.GET)
	
		if form.is_valid() and ygauth.auth_user(request, url, site):
			new_todo = form.save(commit=False)

			members = MemberInfo.objects.filter(sites=site)
			members_list = members.values_list('first_name', flat=True)

			parse_data = parse_todo(new_todo.title, members_list)
			pretty_datetime = make_pretty_datetime(parse_data[1], parse_data[2])

			new_todo.title = parse_data[0]
			new_todo.due_date = parse_data[1]
			new_todo.due_time = parse_data[2]
			new_todo.pretty_date = pretty_datetime[0]
			new_todo.pretty_time = pretty_datetime[1]

			if not request.user.is_anonymous():
				new_todo.creator = request.user

			new_todo.order = ToDo.objects.filter(site=site).count() + 1
			new_todo.save()

			new_todo.assigned_members = members.filter(first_name__in=parse_data[3])

			new_todo.members = [member.first_name for member in new_todo.assigned_members.all()]

			return json.to_json_response(new_todo, include=('id', 'complete', 'title', 'members', 'due_date', 'pretty_date', 'pretty_time'))
		else:
			return json.to_json_response({'s': False, 'errors': form.errors.keys()})
Exemplo n.º 2
0
def add_group_members(request, url):
	"""Display and catch AddMembersForm"""
	
	extra = 3
	initial = []
	data = {}
	info_initial = {'description': ''}

	if request.method == 'POST' and request.POST['submitType'] != '':
		formCopy = request.POST.copy()
		mod = 0
		del formCopy['form-TOTAL_FORMS'], formCopy['form-INITIAL_FORMS']
		
		if request.POST['submitType'] == 'addRowSubmit':
			del formCopy['submitType']
			extra = 1
		
		if request.POST['submitType'] == 'removeRowSubmit':
			del formCopy['submitType']
			extra = 0
			last_row_values = [formCopy[key] for key in sorted(formCopy, reverse=True)[:3] if formCopy[key].strip() != '']
			if int(request.POST['form-TOTAL_FORMS']) > 1 and len(last_row_values) == 0:
				mod = -3

		info_initial['description'] = formCopy['description']
		del formCopy['description']

		template = ['email', 'first_name', 'phone']
		form_keys = sorted(formCopy)
		for i in range(0,(len(formCopy)+mod)/3):
			values = [formCopy[key] for key in form_keys[(i*3):(i*3+3)]]
			initial.append(zip(template, values))


	FormSet = formset_factory(AddMembersForm, formset=BaseAddMembersFormSet, extra=extra)

	if request.method == 'POST' and request.POST['submitType'] == 'saveSubmit':
		form = FormSet(request.POST)
		info_form = AddMembersExtraInfoForm(request.POST)
		if form.is_valid() and info_form.is_valid():
			form.save(url, info_form.cleaned_data['description'])

			#if request.user.is_anonymous():
			request.session['fresh_site'] = True

			return json.to_json_response({'s': True})
		else:
			data['s'] = False
	else:
		form = FormSet(initial=initial)
		info_form = AddMembersExtraInfoForm(initial=info_initial)
		data['s'] = False

	data['form'] = json.clean_json(json.render_to_json('members/add_members.html', {'form': form, 'info_form': info_form}))

	
	#return render_to_response('members/add_members.html', data, context_instance=RequestContext(request))
	return json.to_json_response(data)
Exemplo n.º 3
0
def get_all_site_info(request, url):
	"""AJAX view to return all site info on initial loading of the site"""
	site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))
	
	if not ygauth.auth_user(request, url, site):
		return

	discuss = {
		'new_discussion_form': display_new_discussion_form(request, url, True),
		'all_discussions': display_all_discussions(request, url, True)
	}

	files = {
		'all_files': display_all_files(request, url, True),
	}

	if request.user.is_authenticated():
		user = request.user.id
	else:
		user = 0

	response = {
		'site': site.id,
		'url': site.random_name,
		'media_url': settings.MEDIA_URL,
		'user': user,
		'discuss': discuss,
		'files': files,
		'settings_box': show_settings_box(request, url, True),
	}

	return json.to_json_response(response)
Exemplo n.º 4
0
def save_current_discussion_reply(request, url):
	site = get_object_or_404(GroupSite, Q(id=request.POST['site']) & (Q(random_name=url) | Q(name=url)))
	form = DiscussionReplyForm(request.POST)
	if request.method == 'POST' and form.is_valid() and ygauth.auth_user(request, url, site):
		post = Post(topic=form.cleaned_data['topic'], body=form.cleaned_data['body'])
		if request.user.is_authenticated():
			post.creator = request.user
			post.author = post.creator.first_name
		else:
			post.author = 'Anon'
		post.save()

		if request.user.is_authenticated():
			ReadStatus.objects.filter(Q(topic=form.cleaned_data['topic']) & ~Q(member=request.user)).update(read=False)

		members = MemberInfo.objects.filter(sites=site)
		if members.count > 0:
			email = YakEmail()
			for m in members:
				if request.user.is_authenticated() and request.user.id == m.id:
					continue
				email.add_email(to_addy=m.email, subject=post.topic.title, from_addy=site.get_site_title()+' YakGroup', template='discuss/emailPost.html', context={'topic': post.topic, 'post': post})
			email.send_all_emails()

		
		now = datetime.datetime.today()
		pretty_datetime = make_pretty_datetime(now.date(), now.time())

		post.created = pretty_datetime[1] + " " + pretty_datetime[0]
		post.body = post.body.replace('\n', '<br />')

		post.topic.save()

		return json.to_json_response(post, include=('author', 'created', 'body'))
Exemplo n.º 5
0
def file_uploads(request, url):
	site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))

	try:
		os.makedirs(settings.MEDIA_ROOT+'storage/'+site.random_name)
	except OSError:
		pass

	f = request.FILES['Filedata']
	file_count = File.objects.filter(site=site, original_name=f.name).count()

	if file_count==0:
		destination = open(settings.MEDIA_ROOT+'storage/'+site.random_name+'/'+f.name, 'wb+')
		new_name = f.name
	else:
		name_split = f.name.split('.')
		new_name = ''
		for i, name in enumerate(name_split[:-1]):
			if i == 0:
				new_name = new_name + name
			else:
				new_name = new_name + '.' + name
		new_name = new_name + '-' + str(file_count) + '.' + name_split.pop()
		destination = open(settings.MEDIA_ROOT+'storage/'+site.random_name+'/'+new_name, 'wb+')

	for chunk in f.chunks():
			destination.write(chunk)
	destination.close()

	file = File(site=site, original_name=f.name, name=new_name)
	if request.POST.get('user', 0):
		file.creator = User.objects.get(id=request.POST['user'])
	file.save()

	return json.to_json_response({'s': True})
Exemplo n.º 6
0
def viewmodify_todo_details(request, url):
	if request.method == 'POST':
		todo = get_object_or_404(ToDo, id=request.POST.get('id'))
		form = ToDoDetailsForm(request.POST, instance=todo)
		if form.is_valid():
			todo = form.save(commit=False)

			if todo.complete:
				todo.complete = 1
			else:
				todo.complete = 0
			
			parse_data = parse_todo(form.cleaned_data['due_date_string'])
			pretty_datetime = make_pretty_datetime(parse_data[1], parse_data[2])

			todo.due_date = parse_data[1]
			todo.due_time = parse_data[2]
			todo.pretty_date = pretty_datetime[0]
			todo.pretty_time = pretty_datetime[1]

			todo.save()
			form.save_m2m()
			todo.form_success = True
		else:
			todo.form_success = False
			todo.error_keys = form.errors.keys()

	else:
		site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))
		id = request.GET['id']

		if not ygauth.auth_user(request, url, site):
			return

		todo = get_object_or_404(ToDo, Q(id=id) & Q(site=site))
		form = ToDoDetailsForm(instance=todo)

	
	if todo.due_time is None:
		due_datetime = todo.due_date
	else:
		due_datetime = datetime.datetime.combine(todo.due_date, todo.due_time)

	#todo_description = todo.description.replace("\n", "<br />")

	data = {
		'todo': todo,
		#'todo_description': todo_description,
		'due_datetime': due_datetime
	}

	todo.members = [member.first_name for member in todo.assigned_members.all()]
	todo.table = json.render_to_json('todos/viewToDoDetails.html', data)
	todo.form = json.render_to_json('todos/modifyToDoDetails.html', {'form': form, 'todo': todo})
	
	return json.to_json_response(todo, include=('id', 'title', 'complete',
																							'table', 'form', 'members',
																							'due_date', 'pretty_time', 'pretty_date',
																							'form_success', 'error_keys'))
Exemplo n.º 7
0
def create_empty_discussion(request, url):
	site = get_object_or_404(GroupSite, Q(id=request.GET['site']) & (Q(random_name=url) | Q(name=url)))
	if ygauth.auth_user(request, url, site): 
		topic = Topic(site=site)
		if request.user.is_authenticated():
			topic.creator = request.user
		topic.save()
		return json.to_json_response(topic, include=('id',))
Exemplo n.º 8
0
def display_all_files(request, url, initial_load):
	site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))

	if ygauth.auth_user(request, url, site):
		files = File.objects.filter(site=site).order_by('-updated')
		all_files = json.render_to_json('files/allFiles.html', {'files': files, 'site': site, 'media_url': settings.MEDIA_URL})
		if initial_load:
			return all_files
		return json.to_json_response({'all_files': all_files})
Exemplo n.º 9
0
def rename_site(request, url):
	"""Rename group site"""
	data = {}
	if request.method == 'POST':
		site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))
		form = RenameSiteForm(request.POST, instance=site)
		if form.is_valid():
			new_site = form.save(commit=False)
			new_site.name_changed = True
			new_site.save()
			return json.to_json_response({'s': True, 'title': new_site.title})
		else:
			data = {'s': False, 'errors': form.errors.keys()}
	else:
		form = RenameSiteForm()

	data['form'] = json.clean_json(json.render_to_json('sites/renameSiteForm.html', {'form': form}))
	
	return json.to_json_response(data)
Exemplo n.º 10
0
def disable_show_settings_box(request, url):
	"""Sets the show_settings value for a particular user"""

	site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))
	if not request.user.is_anonymous() and ygauth.auth_user(request, url, site):
		user = MemberInfo.objects.get(email=request.user.email)
		user.show_settings = False
		user.save()

	return json.to_json_response({'s': True})
Exemplo n.º 11
0
def reorder_todos(request, url):
	site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))
	if ygauth.auth_user(request, url, site):
		todos_list = [int(item) for item in request.GET.getlist('todo[]')]
		todos = ToDo.objects.in_bulk(todos_list)

		for i, item in enumerate(todos_list):
			todos[item].order = i + 1
			todos[item].save()

		return json.to_json_response({'s': True})
Exemplo n.º 12
0
def assign_related_todo(request, url):
	site = get_object_or_404(GroupSite, Q(id=request.POST['site']) & (Q(random_name=url) | Q(name=url)))
	form = RelatedToDoForm(request.POST)
	if request.method == 'POST' and form.is_valid() and ygauth.auth_user(request, url, site):
		todo_id = form.cleaned_data['todo']
		file_id = form.cleaned_data['item']

		todo = get_object_or_404(ToDo, id=todo_id)
		file = get_object_or_404(File, id=file_id)
		file.todos.add(todo)

		return json.to_json_response({'s': True})
Exemplo n.º 13
0
def display_all_discussions(request, url, initial_load):
	site = get_object_or_404(GroupSite, (Q(random_name=url) | Q(name=url)))

	if ygauth.auth_user(request, url, site):
		topics = Topic.objects.filter(site=site, empty=False).order_by('-updated')
		for t in topics:
			t.read = t.read_status(request.user)
		all_discussions = json.render_to_json('discuss/allDiscussions.html', {'topics': topics, 'user': request.user})
		if initial_load:
			return all_discussions

		return json.to_json_response({'all_discussions': all_discussions})
Exemplo n.º 14
0
def get_all_todos(request, url):
	if request.method == 'GET':
		site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))

		if not ygauth.auth_user(request, url, site):
			return

		todos = ToDo.objects.filter(site=site.id).order_by('order')

		for i, todo in enumerate(todos):
			todos[i].members = [member.first_name for member in todo.assigned_members.all()]

		return json.to_json_response(todos, include=('id', 'complete', 'title', 'members', 'due_date', 'pretty_date', 'pretty_time'))
Exemplo n.º 15
0
def save_new_discussion(request, url):
	site = get_object_or_404(GroupSite, Q(id=request.POST['site']) & (Q(random_name=url) | Q(name=url)))
	topic = get_object_or_404(Topic, id=request.POST['new_discussion_id'], site=site, empty=True)
	form = NewDiscussionForm(request.POST, instance=topic)
	if request.method == 'POST' and form.is_valid() and ygauth.auth_user(request, url, site):
		topic = form.save(commit=False)
		topic.empty = False
		topic.save()
		post = Post(topic=topic, body=form.cleaned_data['body'])
		if request.user.is_authenticated():
			post.creator = request.user
		post.save()
		form.cleaned_data['success'] = True

		members = MemberInfo.objects.filter(sites=site)
		if members.count() > 0:
			email = YakEmail()
			for m in members:
				r = ReadStatus(member=m, topic=topic)
				if request.user.is_authenticated() and m.id == request.user.id:
					r.read = True
				r.save()
				if request.user.is_authenticated() and request.user.id == m.id:
					continue
				email.add_email(to_addy=m.email, subject=topic.title, from_addy=site.get_site_title()+' YakGroup', template='discuss/emailPost.html', context={'topic': topic, 'post': post})
			email.send_all_emails()

		return json.to_json_response(form.cleaned_data)
	else:
		discussion_form = json.render_to_json('discuss/newDiscussion.html', {'form': form, 'site': site.id})
		response = {
			'error_keys': form.errors.keys(),
			'form': discussion_form,
			'success': False
		}

		return json.to_json_response(response)
Exemplo n.º 16
0
def update_todo_date(request,url):
	if request.method == 'POST':
		todo = get_object_or_404(ToDo, id=request.POST.get('id'))
		form = ToDoUpdateDateForm(request.POST, instance=todo)
		if form.is_valid():
			todo = form.save(commit=False)

			pretty_datetime = make_pretty_datetime(todo.due_date, todo.due_time)
			todo.pretty_date = pretty_datetime[0]
			todo.pretty_time = pretty_datetime[1]

			todo.save()

			todo.members = [member.first_name for member in todo.assigned_members.all()]

		return json.to_json_response(todo, include=('id', 'complete', 'title', 'members', 'due_date', 'pretty_date', 'pretty_time'))
Exemplo n.º 17
0
def remove_related_todo(request, url):
	site = get_object_or_404(GroupSite, Q(id=request.POST['site']) & (Q(random_name=url) | Q(name=url)))
	form = RelatedToDoForm(request.POST)
	if request.method == 'POST' and form.is_valid() and ygauth.auth_user(request, url, site):
		todo_id = form.cleaned_data['todo']
		topic_id = form.cleaned_data['item']

		todo = get_object_or_404(ToDo, id=todo_id)
		topic = get_object_or_404(Topic, id=topic_id)
		topic.todos.remove(todo)

		todos = topic.todos.all().order_by('order')

		todos_table = json.render_to_json('discuss/relatedTodosTable.html', {'todos': todos})

		return json.to_json_response({'todos_table': todos_table})
Exemplo n.º 18
0
def remove_related_file(request, url):
	site = get_object_or_404(GroupSite, Q(id=request.POST['site']) & (Q(random_name=url) | Q(name=url)))
	form = RelatedToDoForm(request.POST)
	if request.method == 'POST' and form.is_valid() and ygauth.auth_user(request, url, site):
		todo_id = form.cleaned_data['todo']
		file_id = form.cleaned_data['item']

		todo = get_object_or_404(ToDo, id=todo_id)
		file = get_object_or_404(File, id=file_id)
		#file.todos.remove(todo)
		todo.file_set.remove(file)

		#todos = file.todos.all().order_by('order')

		files_table = json.render_to_json('todos/relatedFilesTable.html', {'todo': todo})

		return json.to_json_response({'files_table': files_table})
Exemplo n.º 19
0
def display_current_discussion(request, url):
	site = get_object_or_404(GroupSite, Q(id=request.GET['site']) & (Q(random_name=url) | Q(name=url)))
	if ygauth.auth_user(request, url, site):
		topic = Topic.objects.get(id=request.GET['id'])
		posts = Post.objects.filter(topic=topic).order_by('updated')
		todos = topic.todos.all().order_by('order')

		if request.user.is_authenticated():
			r = ReadStatus.objects.get_or_create(member=request.user, topic=topic)
			r[0].read = True
			r[0].save()

		fdict = {}
		for todo in todos:
			for file in todo.file_set.all():
				fdict[file.id] = file

		current_discussion = json.render_to_json('discuss/currentDiscussion.html', {'posts': posts, 'topic': topic, 'todos': todos, 'files': fdict.values()})
		return json.to_json_response({'current_discussion': current_discussion})
Exemplo n.º 20
0
def toggle_complete_status(request, url):
	site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))
	if ygauth.auth_user(request, url, site):
		id = request.GET.get('id')

		#sometimes the value for complete gets returned as 'true' or 'false' or 1 or 0. Not sure why
		if request.GET.get('complete') == 'true':
			complete = 1
		elif request.GET.get('complete') == 'false':
			complete = 0
		else:
			complete = int(request.GET.get('complete'))

		todo = ToDo.objects.get(id=id, site=site)

		if complete:
			todo.complete = 0
		else:
			todo.complete = 1

		todo.save()

		return json.to_json_response(todo, include=('id', 'complete'))
Exemplo n.º 21
0
def get_site_id(request, url):
	"""AJAX view to return site id"""
	if request.method == 'GET':
		site = get_object_or_404(GroupSite, Q(random_name=url) | Q(name=url))
		response = {'site': site.id}
		return json.to_json_response(response)
Exemplo n.º 22
0
def delete_empty_discussion(request, url):
	site = get_object_or_404(GroupSite, Q(id=request.POST['site']) & (Q(random_name=url) | Q(name=url)))
	if request.method == 'POST' and ygauth.auth_user(request, url, site):
		topic = get_object_or_404(Topic, id=request.POST['discussion'], site=site, empty=True)
		topic.delete()
		return json.to_json_response({'s': True})
Exemplo n.º 23
0
def load_quick_tour(request, url):
	content = json.clean_json(json.render_to_json('sites/quickTour.html', {'MEDIA_URL': settings.MEDIA_URL}))
	return json.to_json_response({'content': content})