Working on blogs.
parent
f0a517eec4
commit
8a31927ccb
|
@ -1,4 +1,48 @@
|
||||||
{% for snipt in snipts %}
|
{% extends "blogs/base.html" %}
|
||||||
<strong>{{ snipt.title }}</strong><br />
|
|
||||||
{{ snipt.code }}<br /><br />
|
{% load compress pagination_tags %}
|
||||||
{% endfor %}
|
|
||||||
|
{% block js %}
|
||||||
|
{{ block.super }}
|
||||||
|
window.detail = false;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<section class="snipts" id="snipts">
|
||||||
|
{% autopaginate snipts 10 %}
|
||||||
|
{% for snipt in snipts %}
|
||||||
|
{% include "blogs/snipt-list.html" %}
|
||||||
|
{% empty %}
|
||||||
|
<div class="empty-snipts">
|
||||||
|
{{ user.username }} has no public snipts.
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% paginate %}
|
||||||
|
</section>
|
||||||
|
<script type="text/javascript" id="disqus">
|
||||||
|
var disqus_shortname = 'snipt-net';
|
||||||
|
{% if debug %}
|
||||||
|
var disqus_developer = 1;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
var s = document.createElement('script'); s.async = true;
|
||||||
|
s.type = 'text/javascript';
|
||||||
|
s.src = 'https://' + disqus_shortname + '.disqus.com/count.js';
|
||||||
|
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
|
||||||
|
}());
|
||||||
|
</script>
|
||||||
|
<script type="text/html" id="disqus-template">
|
||||||
|
var disqus_shortname = 'snipt-net';
|
||||||
|
{% if debug %}
|
||||||
|
var disqus_developer = 1;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
var s = document.createElement('script'); s.async = true;
|
||||||
|
s.type = 'text/javascript';
|
||||||
|
s.src = 'https://' + disqus_shortname + '.disqus.com/count.js';
|
||||||
|
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
|
||||||
|
}());
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -1 +1,33 @@
|
||||||
# Create your views here.
|
from django.shortcuts import get_object_or_404, render_to_response
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.template import RequestContext
|
||||||
|
from annoying.decorators import render_to
|
||||||
|
|
||||||
|
from snipts.models import Snipt
|
||||||
|
|
||||||
|
|
||||||
|
@render_to('blogs/list.html')
|
||||||
|
def list_blog(request, subdomain):
|
||||||
|
|
||||||
|
subdomain = subdomain.replace('-', '_')
|
||||||
|
user = get_object_or_404(User, username__iexact=subdomain)
|
||||||
|
snipts = Snipt.objects.filter(user=user, blog_post=True, public=True).order_by('-created')
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'snipts': snipts,
|
||||||
|
'user': user,
|
||||||
|
}
|
||||||
|
|
||||||
|
if 'rss' in request.GET:
|
||||||
|
context['snipts'] = context['snipts'][:20]
|
||||||
|
return rss(request, context)
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
def rss(request, context):
|
||||||
|
return render_to_response(
|
||||||
|
'rss.xml',
|
||||||
|
context,
|
||||||
|
context_instance=RequestContext(request),
|
||||||
|
mimetype="application/rss+xml"
|
||||||
|
)
|
||||||
|
|
|
@ -1262,3 +1262,21 @@ body.api div#disqus_thread {
|
||||||
body.blog article.snipt section.code {
|
body.blog article.snipt section.code {
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body.blog-site header.blog div.inner {
|
||||||
|
border-left: 1px solid rgba(229, 229, 229, 0.25);
|
||||||
|
margin: 30px auto 0 auto;
|
||||||
|
width: 939px;
|
||||||
|
}
|
||||||
|
body.blog-site header.blog div.inner h1 {
|
||||||
|
color: #0094AF;
|
||||||
|
font: normal 34px "Helvetica Neue", Helvetica, Arial, "Liberation Sans", FreeSans, sans-serif;
|
||||||
|
margin-left: 15px;
|
||||||
|
}
|
||||||
|
body.blog-site header.blog div.inner h1 a {
|
||||||
|
color: #0094AF;
|
||||||
|
}
|
||||||
|
body.blog-site header.blog div.inner h1 a:hover {
|
||||||
|
color: #292929;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
|
@ -1429,3 +1429,29 @@ body.blog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Blogs
|
||||||
|
body.blog-site {
|
||||||
|
header.blog {
|
||||||
|
div.inner {
|
||||||
|
border-left: 1px solid rgba(229, 229, 229, .25);
|
||||||
|
margin: 30px auto 0 auto;
|
||||||
|
width: 939px;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
color: #0094AF;
|
||||||
|
font: normal 34px $Helvetica;
|
||||||
|
margin-left: 15px;
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #0094AF;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #292929;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -73,10 +73,12 @@
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<ul class="attrs">
|
<ul class="attrs">
|
||||||
<li class="author">
|
{% block author %}
|
||||||
<span style="background-image: url('https://secure.gravatar.com/avatar/{{ snipt.user.email|md5 }}?s=15&d=https%3A%2F%2Fsnipt.net%2Fstatic%2Fimages%2Fauthor-icon.png');"></span>
|
<li class="author">
|
||||||
<a href="{{ snipt.user.get_absolute_url }}">{{ snipt.user.username }}</a>
|
<span style="background-image: url('https://secure.gravatar.com/avatar/{{ snipt.user.email|md5 }}?s=15&d=https%3A%2F%2Fsnipt.net%2Fstatic%2Fimages%2Fauthor-icon.png');"></span>
|
||||||
</li>
|
<a href="{{ snipt.user.get_absolute_url }}">{{ snipt.user.username }}</a>
|
||||||
|
</li>
|
||||||
|
{% endblock %}
|
||||||
{% if snipt.blog_post %}
|
{% if snipt.blog_post %}
|
||||||
<li class="created" title="{{ snipt.publish_date|date:"Y-m-d\TH:i:s" }}">{{ snipt.publish_date|naturalday }}</li>
|
<li class="created" title="{{ snipt.publish_date|date:"Y-m-d\TH:i:s" }}">{{ snipt.publish_date|naturalday }}</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
107
snipts/views.py
107
snipts/views.py
|
@ -7,6 +7,7 @@ from django.template import RequestContext
|
||||||
from annoying.decorators import render_to
|
from annoying.decorators import render_to
|
||||||
from snipts.models import Favorite, Snipt
|
from snipts.models import Favorite, Snipt
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
|
from blogs.views import list_blog
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from taggit.models import Tag
|
from taggit.models import Tag
|
||||||
|
@ -27,6 +28,50 @@ def home(request):
|
||||||
else:
|
else:
|
||||||
return list_public(request)
|
return list_public(request)
|
||||||
|
|
||||||
|
@render_to('snipts/detail.html')
|
||||||
|
def detail(request, username, snipt_slug):
|
||||||
|
|
||||||
|
snipt = get_object_or_404(Snipt, user__username=username, slug=snipt_slug)
|
||||||
|
user = snipt.user
|
||||||
|
|
||||||
|
if user != request.user:
|
||||||
|
if not snipt.public:
|
||||||
|
if 'key' not in request.GET:
|
||||||
|
raise Http404
|
||||||
|
else:
|
||||||
|
if request.GET.get('key') != snipt.key:
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
tags = Tag.objects
|
||||||
|
|
||||||
|
if user == request.user:
|
||||||
|
tags = tags.filter(snipt__user=user)
|
||||||
|
public = False
|
||||||
|
else:
|
||||||
|
tags = tags.filter(snipt__user=user, snipt__public=True)
|
||||||
|
public = True
|
||||||
|
|
||||||
|
tags = tags.annotate(count=Count('taggit_taggeditem_items__id'))
|
||||||
|
tags = tags.order_by('-count', 'name')
|
||||||
|
|
||||||
|
return {
|
||||||
|
'detail': True,
|
||||||
|
'has_snipts': True,
|
||||||
|
'public': public,
|
||||||
|
'snipt': snipt,
|
||||||
|
'tags': tags,
|
||||||
|
'user': user,
|
||||||
|
}
|
||||||
|
|
||||||
|
def embed(request, snipt_key):
|
||||||
|
snipt = get_object_or_404(Snipt, key=snipt_key)
|
||||||
|
|
||||||
|
lines = snipt.embedded.split('\n')
|
||||||
|
return render_to_response('snipts/embed.html',
|
||||||
|
{'lines': lines, 'snipt': snipt},
|
||||||
|
context_instance=RequestContext(request),
|
||||||
|
mimetype='application/javascript')
|
||||||
|
|
||||||
@render_to('snipts/list-public.html')
|
@render_to('snipts/list-public.html')
|
||||||
def list_public(request, tag_slug=None):
|
def list_public(request, tag_slug=None):
|
||||||
|
|
||||||
|
@ -108,68 +153,6 @@ def list_user(request, username_or_custom_slug, tag_slug=None):
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@render_to('blogs/list.html')
|
|
||||||
def list_blog(request, subdomain):
|
|
||||||
|
|
||||||
subdomain = subdomain.replace('-', '_')
|
|
||||||
user = get_object_or_404(User, username__iexact=subdomain)
|
|
||||||
snipts = Snipt.objects.filter(user=user, blog_post=True, public=True).order_by('-created')
|
|
||||||
|
|
||||||
context = {
|
|
||||||
'snipts': snipts,
|
|
||||||
'user': user,
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'rss' in request.GET:
|
|
||||||
context['snipts'] = context['snipts'][:20]
|
|
||||||
return rss(request, context)
|
|
||||||
|
|
||||||
return context
|
|
||||||
|
|
||||||
@render_to('snipts/detail.html')
|
|
||||||
def detail(request, username, snipt_slug):
|
|
||||||
|
|
||||||
snipt = get_object_or_404(Snipt, user__username=username, slug=snipt_slug)
|
|
||||||
user = snipt.user
|
|
||||||
|
|
||||||
if user != request.user:
|
|
||||||
if not snipt.public:
|
|
||||||
if 'key' not in request.GET:
|
|
||||||
raise Http404
|
|
||||||
else:
|
|
||||||
if request.GET.get('key') != snipt.key:
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
tags = Tag.objects
|
|
||||||
|
|
||||||
if user == request.user:
|
|
||||||
tags = tags.filter(snipt__user=user)
|
|
||||||
public = False
|
|
||||||
else:
|
|
||||||
tags = tags.filter(snipt__user=user, snipt__public=True)
|
|
||||||
public = True
|
|
||||||
|
|
||||||
tags = tags.annotate(count=Count('taggit_taggeditem_items__id'))
|
|
||||||
tags = tags.order_by('-count', 'name')
|
|
||||||
|
|
||||||
return {
|
|
||||||
'detail': True,
|
|
||||||
'has_snipts': True,
|
|
||||||
'public': public,
|
|
||||||
'snipt': snipt,
|
|
||||||
'tags': tags,
|
|
||||||
'user': user,
|
|
||||||
}
|
|
||||||
|
|
||||||
def embed(request, snipt_key):
|
|
||||||
snipt = get_object_or_404(Snipt, key=snipt_key)
|
|
||||||
|
|
||||||
lines = snipt.embedded.split('\n')
|
|
||||||
return render_to_response('snipts/embed.html',
|
|
||||||
{'lines': lines, 'snipt': snipt},
|
|
||||||
context_instance=RequestContext(request),
|
|
||||||
mimetype='application/javascript')
|
|
||||||
|
|
||||||
def raw(request, snipt_key):
|
def raw(request, snipt_key):
|
||||||
snipt = get_object_or_404(Snipt, key=snipt_key)
|
snipt = get_object_or_404(Snipt, key=snipt_key)
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,14 @@
|
||||||
|
|
||||||
<link rel="icon" href="{{ STATIC_URL }}images/favicon.ico">
|
<link rel="icon" href="{{ STATIC_URL }}images/favicon.ico">
|
||||||
|
|
||||||
{% compress css %}
|
{% block css %}
|
||||||
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css" />
|
{% compress css %}
|
||||||
<link rel="stylesheet" type="text/x-scss" href="{{ STATIC_URL }}css/style.scss" />
|
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/themes.css" />
|
<link rel="stylesheet" type="text/x-scss" href="{{ STATIC_URL }}css/style.scss" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/chosen.css" />
|
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/themes.css" />
|
||||||
{% endcompress %}
|
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/chosen.css" />
|
||||||
|
{% endcompress %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% compress js %}
|
{% compress js %}
|
||||||
<script type="text/javascript" src="{{ STATIC_URL }}js/libs/underscore.js"></script>
|
<script type="text/javascript" src="{{ STATIC_URL }}js/libs/underscore.js"></script>
|
||||||
|
@ -68,52 +70,54 @@
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body class="{% block body-class %}{% endblock %}">
|
<body class="{% block body-class %}{% endblock %}">
|
||||||
<header class="main">
|
{% block header %}
|
||||||
<div class="inner">
|
<header class="main">
|
||||||
<div class="shadey"></div>
|
<div class="inner">
|
||||||
<h1><a href="{% if request.user.is_authenticated %}/{{ request.user.username }}/{% else %}/{% endif %}">Snipt</a></h1>
|
<div class="shadey"></div>
|
||||||
<form class="search" action="/search/" method="get">
|
<h1><a href="{% if request.user.is_authenticated %}/{{ request.user.username }}/{% else %}/{% endif %}">Snipt</a></h1>
|
||||||
<fieldset>
|
<form class="search" action="/search/" method="get">
|
||||||
<div class="fields">
|
<fieldset>
|
||||||
<input type="text" id="search-query" name="q" value="{{ query }}" placeholder="Search snipts" />
|
<div class="fields">
|
||||||
</div>
|
<input type="text" id="search-query" name="q" value="{{ query }}" placeholder="Search snipts" />
|
||||||
</fieldset>
|
</div>
|
||||||
</form>
|
</fieldset>
|
||||||
<nav class="public">
|
</form>
|
||||||
<ul>
|
<nav class="public">
|
||||||
{% if not request.user.is_authenticated %}
|
<ul>
|
||||||
<li>
|
{% if not request.user.is_authenticated %}
|
||||||
<a href="/public/" {% if '/public/' in request.path or public %} class="active"{% endif %}>Public snipts</a>
|
<li>
|
||||||
</li>
|
<a href="/public/" {% if '/public/' in request.path or public %} class="active"{% endif %}>Public snipts</a>
|
||||||
<li>
|
</li>
|
||||||
<a href="/login/?next={{ request.path }}" {% if '/login/' in request.path %} class="active"{% endif %}>Log in</a>
|
<li>
|
||||||
</li>
|
<a href="/login/?next={{ request.path }}" {% if '/login/' in request.path %} class="active"{% endif %}>Log in</a>
|
||||||
<li>
|
</li>
|
||||||
<a href="/signup/" {% if '/signup/' in request.path %} class="active"{% endif %}>Sign up</a>
|
<li>
|
||||||
</li>
|
<a href="/signup/" {% if '/signup/' in request.path %} class="active"{% endif %}>Sign up</a>
|
||||||
{% else %}
|
</li>
|
||||||
<li>
|
|
||||||
<a href="/{{ request.user.username }}/" {% if request.user.username in request.path %} class="active"{% endif %}>My snipts</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="/public/" {% if '/public/' in request.path or public %} class="active"{% endif %}>Public snipts</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="/logout/?next={{ request.path }}">Log out</a>
|
|
||||||
</li>
|
|
||||||
{% if request.user.username == 'blog' %}
|
|
||||||
<li><button class="btn btn-info btn-large" id="add-snipt">Add Post <i class="icon-search icon-plus icon-white"></i></button></li>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><button class="btn btn-info btn-large" id="add-snipt">Add Snipt <i class="icon-search icon-plus icon-white"></i></button></li>
|
<li>
|
||||||
|
<a href="/{{ request.user.username }}/" {% if request.user.username in request.path %} class="active"{% endif %}>My snipts</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="/public/" {% if '/public/' in request.path or public %} class="active"{% endif %}>Public snipts</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="/logout/?next={{ request.path }}">Log out</a>
|
||||||
|
</li>
|
||||||
|
{% if request.user.username == 'blog' %}
|
||||||
|
<li><button class="btn btn-info btn-large" id="add-snipt">Add Post <i class="icon-search icon-plus icon-white"></i></button></li>
|
||||||
|
{% else %}
|
||||||
|
<li><button class="btn btn-info btn-large" id="add-snipt">Add Snipt <i class="icon-search icon-plus icon-white"></i></button></li>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
</ul>
|
||||||
</ul>
|
</nav>
|
||||||
</nav>
|
{% if request.user.is_authenticated and has_snipts %}
|
||||||
{% if request.user.is_authenticated and has_snipts %}
|
<aside class="nav"></aside>
|
||||||
<aside class="nav"></aside>
|
{% endif %}
|
||||||
{% endif %}
|
</div>
|
||||||
</div>
|
</header>
|
||||||
</header>
|
{% endblock %}
|
||||||
{% block sub-header %}
|
{% block sub-header %}
|
||||||
<header class="sub">
|
<header class="sub">
|
||||||
<div class="inner group">
|
<div class="inner group">
|
||||||
|
@ -130,11 +134,13 @@
|
||||||
<section class="main group" id="main">
|
<section class="main group" id="main">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
<div class="rochester-made">
|
{% block rochester-made %}
|
||||||
<a href="http://rochestermade.com/" title="Rochester Made">
|
<div class="rochester-made">
|
||||||
<img src="{{ STATIC_URL }}images/rochester-made.png" alt="" />
|
<a href="http://rochestermade.com/" title="Rochester Made">
|
||||||
</a>
|
<img src="{{ STATIC_URL }}images/rochester-made.png" alt="" />
|
||||||
</div>
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% block aside %}
|
{% block aside %}
|
||||||
<aside class="main">
|
<aside class="main">
|
||||||
|
|
Loading…
Reference in New Issue