Exemple #1
0
def delete(request, status_pk):
	status = get_object_or_404(Status, pk=status_pk)

	if status.user != request.user:
		return json_view(error=(1, "Permission denied."))

	status.delete()
	return json_view()
Exemple #2
0
def read(request, notification_pk):
	try:
		notification = Notification.objects.get(pk = notification_pk)
	except Notification.ObjectNotFound:
		return json_view(error=(1, "Wrong request."))

	notification.is_unread = False
	notification.save()

	return json_view()
Exemple #3
0
def follow(request, user_pk):
	user = get_object_or_404(User, pk=user_pk)

	if Follow.objects.filter(user=request.user, target=user).count() != 0:
		return json_view(error=(1, "You are following this user."))

	Follow(user=request.user, target=user).save()
	url = reverse("kiqlist.users.views.friends") + "#followers"
	send_notification(user, "%s %s is now following you." % (request.user.first_name, request.user.last_name), url)
	return json_view()
Exemple #4
0
def unfollow(request, user_pk):
	user = get_object_or_404(User, pk=user_pk)

	try:
		follow = Follow.objects.filter(user=request.user, target=user).get()
	except Follow.DoesNotExist:
		return json_view(error=(1, "You are not following this user."))

	follow.delete()

	return json_view()
Exemple #5
0
def delete(request):
	try:
		date_cutoff_delta = timedelta(days = NOTIFICATIONS_DAYS_CUTOFF)
		date_cutoff = datetime.now().replace(tzinfo=utc) - date_cutoff_delta
		notifications = Notification.objects.filter(
			user = request.user,
			created__lt = date_cutoff
		)
	except Notification.ObjectNotFound:
		return json_view(error=(1, "Wrong request."))

	notifications.delete()

	return json_view()
Exemple #6
0
def report(request, id):
	goal = get_object_or_404(Goal, id)
	goal.reports += 1
	if goal.reports <= 1:
		pass # send email

	return json_view(data=Goal.objects.filter(id=id))
Exemple #7
0
def done_goals(request, user_pk=None):
	if user_pk:
		user = get_object_or_404(User, pk=user_pk)
		done_goals = Goal.objects.filter(user=user, is_done=True).order_by("-created")
	else:
		done_goals = Goal.objects.filter(is_done=True).order_by("-created")[:20]

	return json_view(data=done_goals)
Exemple #8
0
def delete(request, goal_pk):
	goal = get_object_or_404(Goal, pk=goal_pk)
	if goal.user != request.user:
		raise PermissionDenied

	goal.delete()

	return json_view()
Exemple #9
0
def following(request):
    following_users = [x.target for x in request.user.following.all()]
    goals = Goal.objects.filter(user__in=following_users)
    statuses = Status.objects.filter(user__in=following_users)

    data = sorted(chain(goals, statuses), key=attrgetter("created"), reverse=True)

    return json_view(data=data)
Exemple #10
0
def like(request, goal_pk):
	goal = get_object_or_404(Goal, pk=goal_pk)

	try:
		goallike = GoalLike.objects.get(user=request.user, goal=goal)
		goallike.delete()
	except GoalLike.DoesNotExist:
		GoalLike(user=request.user, goal=goal).save()

	return json_view(goal.goallike_set.count())
Exemple #11
0
def content_done(request, user_pk=None):
    if user_pk:
        user = get_object_or_404(User, pk=user_pk)
        done_goals = Goal.objects.filter(user=user, is_done=True)
        statuses = Status.objects.filter(user=user)
    else:
        done_goals = Goal.objects.filter(is_done=True)[:10]
        statuses = Status.objects.all()[:10]

    data = sorted(chain(done_goals, statuses), key=attrgetter("created"), reverse=True)

    return json_view(data=data)
Exemple #12
0
def following_activity(request):
	following_users = [x.target for x in request.user.following.all()]

	activity = []

	def get_user_dict(user):
		return {
			"pk": user.pk,
			"fields": {
				"first_name": user.first_name,
				"last_name": user.last_name
			}
		}

	follows =  Follow.objects.filter(user__in=following_users).order_by("-created")[:5]
	for follow in follows:
		activity.append({
			"type": "follow",
			"data": {
				"user": get_user_dict(follow.user),
				"target": get_user_dict(follow.target)
			},
			"created": follow.created
		})

	for user in following_users:
		last_goal_queryset = Goal.objects.filter(user=user).order_by("-created")

		if len(last_goal_queryset):
			last_goal = last_goal_queryset[0]
			goal_type = "done" if last_goal.is_done else "added"
			activity.append({
				"type": goal_type,
				"data": {
					"user": get_user_dict(last_goal.user)
				},
				"created": last_goal.created
			})

	activity = sorted(activity, key=operator.itemgetter("created"), reverse=True)[:5]

	for item in activity:
		del item["created"]

	return json_view(data=activity)
Exemple #13
0
def following_list(request):
	users = [x.target for x in request.user.following.all()]
	offset = int(request.GET.get("offset", 0))
	data = Status.objects.filter(user__in=users).order_by("-created")[offset:offset + settings.STATUSES_ON_PAGE_LIMIT]

	return json_view(data=data)
Exemple #14
0
def top_tags(request):
	top_tags = calculate_top_tags()
	return json_view(data=top_tags)
Exemple #15
0
def mark_as_old(request):
	pks = request.GET.get('pks').split(',')
	if len(pks) > 0 and pks[0]:
		Notification.objects.filter(user=request.user, pk__in=pks).update(is_new=False)

	return json_view()
Exemple #16
0
def all(request):
	notifications = Notification.objects.filter(user=request.user).order_by('-created')
	return json_view(notifications);
Exemple #17
0
def user_list(request, user_pk):
	user = get_object_or_404(User, pk=user_pk)
	offset = int(request.GET.get("offset", 0))
	data = Status.objects.filter(user=user).order_by("-created")[offset:offset + settings.STATUSES_ON_PAGE_LIMIT]

	return json_view(data=data)
Exemple #18
0
def lifelist(request, user_pk):
	user = get_object_or_404(User, pk=user_pk)
	goals = Goal.objects.filter(user=user).order_by("created").all()

	return json_view(data=goals)
Exemple #19
0
def json_search_by_tag(request, tag):
    return json_view(data=search(request, tag))
Exemple #20
0
def following_done_goals(request, user_pk):
	user = get_object_or_404(User, pk=user_pk)
	following_users = [x.target for x in request.user.following.all()]
	done_goals = Goal.objects.filter(user__in=following_users, is_done=True).order_by("-created")

	return json_view(data=done_goals)