Example #1
0
def done(request, goal_pk):
	goal = get_object_or_404(Goal, pk=goal_pk)
	if goal.user != request.user:
		raise PermissionDenied

	if request.method == "POST":
		form = DoneGoalForm(request.POST, request.FILES)
		if form.is_valid():
			cleaned_data = form.clean()

			if cleaned_data['image']:
				GoalImage(image=cleaned_data['image'], goal=goal).save()

			if cleaned_data['description']:
				goal.description = cleaned_data['description']

			goal.is_done = True
			goal.save()

		return redirect("/users/profile/") # users.views.profile

	return ajax_form_view(request,
						  DoneGoalForm,
						  None,
						  "goals/done.html",
						  template_variables={"goal": goal},
						  initial={"description": goal.description})
Example #2
0
def edit_password(request):
	def success(form):
		request.user.set_password(form.cleaned_data.get("password"))
		request.user.save()

	return ajax_form_view(request, ChangePasswordForm, success, "users/edit_password_form.html",
						  form_kwargs={"user": request.user})
Example #3
0
def edit_profile(request):
	profile = request.session[SessionKeys.KEY_PROFILE]

	def success(form):
		request.user.first_name = form.cleaned_data.get("first_name")
		request.user.last_name = form.cleaned_data.get("last_name")
		request.user.email = form.cleaned_data.get("email")
		request.user.save()

		profile.about = form.cleaned_data.get("about")
		profile.location = form.cleaned_data.get("location")
		profile.save()

		request.session.modified = True

	initial = {
		"first_name": request.user.first_name,
		"last_name": request.user.last_name,
		"email": request.user.email,
		"about": profile.about,
		"location": profile.location
	}

	return ajax_form_view(request, ProfileForm, success, "users/edit_profile_form.html",
						  initial=initial)
Example #4
0
def login(request):
	def success(form):
		user = form.user
		auth_login(request, user)
		session = request.session
		session[SessionKeys.KEY_PROFILE] = Profile.objects.get(user=user)

	return ajax_form_view(request, LoginForm, success, "users/login.html")
Example #5
0
def edit(request, goal_pk):
	goal = get_object_or_404(Goal, pk=goal_pk)
	if goal.user != request.user:
		raise PermissionDenied

	def success(form):
		goal = form.save(commit=False)
		goal.save()

		return goal

	return ajax_form_view(request, GoalForm, success, "goals/form.html", instance=goal)
Example #6
0
def reply(request, status_pk):
	reply_status = get_object_or_404(Status, pk=status_pk)

	if request.method != "POST":
		new_status = Status(content="@%s%s" % (reply_status.user.first_name, reply_status.user.last_name))
	else:
		new_status = None

	def success(form):
		status = form.save(commit=False)
		status.user = request.user
		status.save()

	return ajax_form_view(request, StatusForm, success, "statuses/form.html", instance=new_status, template_variables={"reply_status": reply_status})
Example #7
0
def add(request):
	def success(form):
		status = form.save(commit=False)
		status.user = request.user
		tags = extract_hash_tags(request.POST.get('status-tags'))
		status.save()
		for tag in tags:
			tag.save()
			tag.status_set.add(status)
			tag.save()

		return status

	return ajax_form_view(request, StatusForm, success, "statuses/form.html")
Example #8
0
def add(request):
	def success(form):
		goal = form.save(commit=False)
		goal.user = request.user
		tags = extract_hash_tags(request.POST.get('status-tags'))
		goal.save()
		for tag in tags:
			tag.save()
			tag.goal_set.add(goal)
			tag.save()

		return goal

	return ajax_form_view(request, GoalForm, success, "goals/form.html")
Example #9
0
def add_comment(request, goal_pk):
	goal = get_object_or_404(Goal, pk=goal_pk)

	def success(form):
		goalcomment = form.save(commit=False)
		goalcomment.goal = goal
		goalcomment.user = request.user
		goalcomment.save()

		if goalcomment.user != goal.user:
			send_notification(
				goal.user,
				"%s %s commented on your goal \"%s\"." % (request.user.first_name, request.user.last_name, goal.title),
				"#goal/" + str(goal.pk) + "/view")

		return goalcomment

	return ajax_form_view(request, GoalCommentForm, success, "goals/comment_form.html",
						  template_variables={"goal": goal})
Example #10
0
def register(request):
	def success(form):
		cleaned_data = form.clean()
		user = User.objects.create_user(cleaned_data.get("username"), email=cleaned_data.get("email"), password=cleaned_data.get("password"))
		user.first_name = cleaned_data.get("first_name")
		user.last_name = cleaned_data.get("last_name")
		user.is_active = False
		user.save()

		activation_key = ActivationKey(user=user, key=hashlib.md5(str(time.ctime())).hexdigest())
		activation_key.save()

		current_site = get_current_site(request)
		send_noreply_mail(
			request,
			"activation_key",
			"Activate your account on %s" % current_site.name,
			{"user": user, "activation_key": activation_key, "current_site": current_site},
			user.email
		)

	return ajax_form_view(request, RegisterForm, success, "users/register.html")
Example #11
0
def relist(request, goal_pk):
	relist_goal = get_object_or_404(Goal, pk=goal_pk)

	if request.method != "POST":
		new_goal = Goal(
			image=relist_goal.image,
			title=relist_goal.title,
			description=relist_goal.description,
		)

	else:
		new_goal = None

	def success(form):
		goal = form.save(commit=False)
		goal.user = request.user
		goal.save()

		GoalRelist(user=request.user, goal=relist_goal).save()

		return relist_goal.goalrelist_set.count()

	return ajax_form_view(request, GoalForm, success, "goals/form.html", instance=new_goal,
						  template_variables={"relist_goal": relist_goal})
Example #12
0
def start_conversation(request, template="private_messages/start_conversation_form.html"):
	def success(form):
		return form.user

	return ajax_form_view(request, StartConversationForm, success, template)
Example #13
0
def tag_form(request):
    def success(form):
        return form.cleaned_data.get("tag")

    return ajax_form_view(request, HashTagForm, success, "hash_tags/tag_form.html")
Example #14
0
def tag_form(request):
	def success(form):
		return form.cleaned_data.get("tag")

	return ajax_form_view(request, GoalTagForm, success, "goals/tag_form.html")