Working on blogs.

master
Nick Sergeant 2012-05-31 22:32:32 -04:00
parent f0a517eec4
commit 8a31927ccb
7 changed files with 237 additions and 126 deletions

View File

@ -1,4 +1,48 @@
{% for snipt in snipts %}
<strong>{{ snipt.title }}</strong><br />
{{ snipt.code }}<br /><br />
{% endfor %}
{% extends "blogs/base.html" %}
{% load compress pagination_tags %}
{% 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 %}

View File

@ -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"
)

View File

@ -1262,3 +1262,21 @@ body.api div#disqus_thread {
body.blog article.snipt section.code {
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;
}

View File

@ -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;
}
}
}
}
}
}

View File

@ -73,10 +73,12 @@
</div>
<footer>
<ul class="attrs">
<li class="author">
<span style="background-image: url('https://secure.gravatar.com/avatar/{{ snipt.user.email|md5 }}?s=15&amp;d=https%3A%2F%2Fsnipt.net%2Fstatic%2Fimages%2Fauthor-icon.png');"></span>
<a href="{{ snipt.user.get_absolute_url }}">{{ snipt.user.username }}</a>
</li>
{% block author %}
<li class="author">
<span style="background-image: url('https://secure.gravatar.com/avatar/{{ snipt.user.email|md5 }}?s=15&amp;d=https%3A%2F%2Fsnipt.net%2Fstatic%2Fimages%2Fauthor-icon.png');"></span>
<a href="{{ snipt.user.get_absolute_url }}">{{ snipt.user.username }}</a>
</li>
{% endblock %}
{% if snipt.blog_post %}
<li class="created" title="{{ snipt.publish_date|date:"Y-m-d\TH:i:s" }}">{{ snipt.publish_date|naturalday }}</li>
{% else %}

View File

@ -7,6 +7,7 @@ from django.template import RequestContext
from annoying.decorators import render_to
from snipts.models import Favorite, Snipt
from django.db.models import Count
from blogs.views import list_blog
from django.conf import settings
from django.db.models import Q
from taggit.models import Tag
@ -27,6 +28,50 @@ def home(request):
else:
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')
def list_public(request, tag_slug=None):
@ -108,68 +153,6 @@ def list_user(request, username_or_custom_slug, tag_slug=None):
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):
snipt = get_object_or_404(Snipt, key=snipt_key)

View File

@ -12,12 +12,14 @@
<link rel="icon" href="{{ STATIC_URL }}images/favicon.ico">
{% compress css %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css" />
<link rel="stylesheet" type="text/x-scss" href="{{ STATIC_URL }}css/style.scss" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/themes.css" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/chosen.css" />
{% endcompress %}
{% block css %}
{% compress css %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css" />
<link rel="stylesheet" type="text/x-scss" href="{{ STATIC_URL }}css/style.scss" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/themes.css" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/chosen.css" />
{% endcompress %}
{% endblock %}
{% compress js %}
<script type="text/javascript" src="{{ STATIC_URL }}js/libs/underscore.js"></script>
@ -68,52 +70,54 @@
</head>
<body class="{% block body-class %}{% endblock %}">
<header class="main">
<div class="inner">
<div class="shadey"></div>
<h1><a href="{% if request.user.is_authenticated %}/{{ request.user.username }}/{% else %}/{% endif %}">Snipt</a></h1>
<form class="search" action="/search/" method="get">
<fieldset>
<div class="fields">
<input type="text" id="search-query" name="q" value="{{ query }}" placeholder="Search snipts" />
</div>
</fieldset>
</form>
<nav class="public">
<ul>
{% if not request.user.is_authenticated %}
<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="/signup/" {% if '/signup/' in request.path %} class="active"{% endif %}>Sign up</a>
</li>
{% else %}
<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>
{% block header %}
<header class="main">
<div class="inner">
<div class="shadey"></div>
<h1><a href="{% if request.user.is_authenticated %}/{{ request.user.username }}/{% else %}/{% endif %}">Snipt</a></h1>
<form class="search" action="/search/" method="get">
<fieldset>
<div class="fields">
<input type="text" id="search-query" name="q" value="{{ query }}" placeholder="Search snipts" />
</div>
</fieldset>
</form>
<nav class="public">
<ul>
{% if not request.user.is_authenticated %}
<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="/signup/" {% if '/signup/' in request.path %} class="active"{% endif %}>Sign up</a>
</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>
<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 %}
</ul>
</nav>
{% if request.user.is_authenticated and has_snipts %}
<aside class="nav"></aside>
{% endif %}
</div>
</header>
</ul>
</nav>
{% if request.user.is_authenticated and has_snipts %}
<aside class="nav"></aside>
{% endif %}
</div>
</header>
{% endblock %}
{% block sub-header %}
<header class="sub">
<div class="inner group">
@ -130,11 +134,13 @@
<section class="main group" id="main">
<div class="inner">
{% block content %}{% endblock %}
<div class="rochester-made">
<a href="http://rochestermade.com/" title="Rochester Made">
<img src="{{ STATIC_URL }}images/rochester-made.png" alt="" />
</a>
</div>
{% block rochester-made %}
<div class="rochester-made">
<a href="http://rochestermade.com/" title="Rochester Made">
<img src="{{ STATIC_URL }}images/rochester-made.png" alt="" />
</a>
</div>
{% endblock %}
</div>
{% block aside %}
<aside class="main">