Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Snippet(models.Model):
updated_date = models.DateTimeField(auto_now=True)
bookmark_count = models.IntegerField(default=0) # denormalized count
rating_score = models.IntegerField(default=0) # denormalized score
download_count=models.IntegerField(default=0)

ratings = Ratings()
tags = TaggableManager(blank=True)
Expand Down
2 changes: 2 additions & 0 deletions cab/views/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def snippet_detail(request, snippet_id):

def download_snippet(request, snippet_id):
snippet = get_object_or_404(Snippet, pk=snippet_id)
count=Snippet.objects.get(pk=snippet_id).download_count+1
Snippet.objects.filter(pk=snippet_id).update(download_count=count)
response = HttpResponse(snippet.code, content_type="text/plain")
filename = f"{snippet.id}.{snippet.language.file_extension}"
response["Content-Disposition"] = f"attachment; filename={filename}"
Expand Down
6 changes: 6 additions & 0 deletions djangosnippets/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -6897,3 +6897,9 @@ footer .heroku {
a.button:hover {
text-decoration: none
}



.click_count{
color: grey;
}
2 changes: 1 addition & 1 deletion djangosnippets/templates/cab/snippet_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{% if user.is_authenticated %}
<li><a class="actions__flag" href="{% url 'cab_snippet_flag' object.id %}" title="Flag this snippet"><i class="fa fa-fw fa-warning"></i><span>Flag this snippet</span></a></li>
{% endif %}
<li><a href="{% url 'cab_snippet_download' snippet_id=object.id %}" type="{{ object.language.mime_type }}" title="Download"><i class="fa fa-fw fa-arrow-circle-o-down"></i><span>Download</span></a></li>
<li ><a style="padding-right: 0px;" href="{% url 'cab_snippet_download' snippet_id=object.id %}" type="{{ object.language.mime_type }}" title="Download"><i class="fa fa-fw fa-arrow-circle-o-down"></i><span>Download</span></a><i class="click_count"> {{object.download_count}}</i></li>
<li><a href="{% url 'cab_snippet_raw' snippet_id=object.id %}" title="Raw"><i class="fa fa-fw fa-align-left"></i><span>Raw</span></a></li>
</ul>
<div id="description">{{ object.description_html|safe }}</div>
Expand Down