Skip to content

Commit

Permalink
Add option to remove bookmarks (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
jajodiaraghav authored Sep 5, 2017
1 parent 42f8e8f commit 4a6919d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions bugheist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
url(r'^' + settings.ADMIN_URL + '/', include(admin.site.urls)),
url(r'^like_issue/(?P<issue_pk>\d+)/$', website.views.like_issue, name="like_issue"),
url(r'^save_issue/(?P<issue_pk>\d+)/$', website.views.save_issue, name="save_issue"),
url(r'^unsave_issue/(?P<issue_pk>\d+)/$', website.views.unsave_issue, name="unsave_issue"),
url(r'^issue/edit/$', website.views.IssueEdit),
url(r'^issue/update/$', website.views.UpdateIssue),
url(r'^issue/(?P<slug>\w+)/$', IssueView.as_view(), name="issue_view"),
Expand Down
5 changes: 4 additions & 1 deletion website/templates/_bookmarks.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<div class="list-group">
{% for i in bookmarks %}
<div class="list-group-item">
<button type="button" class="close" name="{{i.pk}}" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<a href="{{ i.get_absolute_url }}" class="list-group-item-heading">
<strong>{{ i.description|truncatechars:50 }}</strong>
<strong>{{ i.description|truncatechars:50 }}</strong>
</a>
<span class="badge text-capitalize">{{i.status}}</span>
<p class="list-group-item-text">{{ i.user }}</p>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion website/templates/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h3 class="page-header">
</button>
{% if request.user.is_authenticated %}
<span class="like_btn">
{% include 'likers.html' %}
{% include '_likes.html' %}
</span>
<a class="bookmark btn btn-success btn-xs" name="{{ object.pk }}" >
<i class="fa fa-bookmark-o"></i> Bookmark
Expand Down
23 changes: 22 additions & 1 deletion website/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
color: inherit;
text-decoration: inherit;
}

.img-thumbnail {
width: 200px;
height: 200px;
Expand Down Expand Up @@ -112,6 +111,10 @@
width: 200px;
margin-top: 10px;
}
.list-group-item .badge {
margin-right: 30px;
margin-top: 10px;
}
{% endblock %}

{% block content %}
Expand Down Expand Up @@ -368,5 +371,23 @@ <h1 class="page-header text-capitalize">{{ user.username }}</h1>
}
});
});

$('body').on('click', '.list-group-item button', function (e){
e.preventDefault();
var issue_pk = $(this).attr('name');
var el = $(this);
$.ajax({
type: 'GET',
url: '/unsave_issue/'+issue_pk+'/',
data:{},
success: function(data) {
el.parent().remove();
$.notify("Bookmark Removed!", {style: "custom", className: "success"});
},
error: function() {
$.notify("Some error occurred!", {style: "custom", className: "danger"});
}
});
});
</script>
{% endblock %}
17 changes: 11 additions & 6 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,7 @@ def form_valid(self, form):

def follow_user(request,user):
if request.method == "GET":
userx = User.objects.get(username=user)
context={}
userx = User.objects.get(username=user)
flag = 0
list_userfrof = request.user.userprofile.follows.all()
for prof in list_userfrof:
Expand Down Expand Up @@ -929,14 +928,20 @@ def like_issue(request,issue_pk):
total_votes = UserProfile.objects.filter(issue_upvoted=issue).count()
context['object'] = issue
context['likes'] = total_votes
return render(request,'likers.html',context)
return render(request, '_likes.html', context)

@login_required(login_url='/accounts/login')
def save_issue(request, issue_pk):
context={}
issue_pk=int(issue_pk)
issue = Issue.objects.get(pk=issue_pk)
userprof = UserProfile.objects.get(user=request.user)
userprof.issue_saved.add(issue)
context['bookmarks'] = userprof.issue_saved.all()
return render(request,'_bookmarks.html',context)
return HttpResponse('OK')

@login_required(login_url='/accounts/login')
def unsave_issue(request, issue_pk):
issue_pk=int(issue_pk)
issue = Issue.objects.get(pk=issue_pk)
userprof = UserProfile.objects.get(user=request.user)
userprof.issue_saved.remove(issue)
return HttpResponse('OK')

0 comments on commit 4a6919d

Please sign in to comment.