Permalink
Browse files

Renaming /stop-follow/ url to /unfollow/.

  • Loading branch information...
1 parent 5b2b9a2 commit 4b62d42bac0c82e857a58b58e295d88844307469 Nathan Borror committed Apr 20, 2009
@@ -11,7 +11,7 @@ <h2>Remove {{ to_user }} as a friend?</h2>
{% block content %}
- <form action="{% url relationship_stop_follow to_user_id=to_user.id %}" method="post">
+ <form action="{% url relationship_unfollow to_user_id=to_user.id %}" method="post">
<p>Are you sure you want to delete {{ to_user }} as a friend?
<button type="submit" name="submit" value="Indeed">Indeed</button></p>
</form>
View
@@ -7,7 +7,7 @@
view=relationship_views.follow,
name='relationship_follow'),
- url(r'^stop-following/(?P<to_user_id>\d+)/$',
- view=relationship_views.stop_follow,
- name='relationship_stop_follow'),
+ url(r'^unfollow/(?P<to_user_id>\d+)/$',
+ view=relationship_views.unfollow,
+ name='relationship_unfollow'),
)
View
@@ -5,6 +5,7 @@
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.db import models
+from django.utils import simplejson as json
Relationship = models.get_model('relationships', 'relationship')
@@ -18,8 +19,18 @@ def follow(request, to_user_id, template_name='relationships/relationship_add_co
relationship, created = Relationship.objects.get_or_create(from_user=from_user, to_user=to_user)
if request.is_ajax():
- context = "{'success': 'Success', 'to_user_id': '%s'}" % (to_user.id)
- return HttpResponse(context, mimetype="application/json")
+ response = {
+ 'success': 'Success',
+ 'to_user': {
+ 'username': to_user.username,
+ 'user_id': to_user.pk
+ },
+ 'from_user': {
+ 'username': from_user.username,
+ 'user_id': from_user.pk
+ }
+ }
+ return HttpResponse(json.dumps(response), mimetype="application/json")
else:
template_name = success_template_name
@@ -28,19 +39,29 @@ def follow(request, to_user_id, template_name='relationships/relationship_add_co
@login_required
-def stop_follow(request, to_user_id, template_name='relationships/relationship_delete_confirm.html', success_template_name='relationships/relationship_delete_success.html', mimetype='text/html'):
+def unfollow(request, to_user_id, template_name='relationships/relationship_delete_confirm.html', success_template_name='relationships/relationship_delete_success.html', mimetype='text/html'):
to_user = get_object_or_404(User, pk=to_user_id)
from_user = request.user
-
+
if request.is_ajax() or request.POST:
relationship = get_object_or_404(Relationship, to_user=to_user, from_user=from_user)
relationship.delete()
-
+
if request.is_ajax():
- context = "{'success': 'Success', 'to_user_id': '%s'}" % (to_user.id)
- return HttpResponse(context, mimetype="application/json")
+ response = {
+ 'success': 'Success',
+ 'to_user': {
+ 'username': to_user.username,
+ 'user_id': to_user.pk
+ },
+ 'from_user': {
+ 'username': from_user.username,
+ 'user_id': from_user.pk
+ }
+ }
+ return HttpResponse(json.dumps(response), mimetype="application/json")
else:
template_name = success_template_name
-
+
context = {'to_user': to_user}
return render_to_response(template_name, context, context_instance=RequestContext(request), mimetype=mimetype)

0 comments on commit 4b62d42

Please sign in to comment.