Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
Original code spread across 28 templates in various permutations. Anytime I wanted to restructure tabs I'd have to change every damn template:
<ul class="tabs">
<li><a{% if not group %} class="on"{% endif %} href="{% url user_books username=reader.username %}">{% trans "All" %}</a></li>
<li><a{{ group|is_on:'finished' }} href="{% url user_book_group username=reader.username,group="finished" %}">{% trans "Finished" %}</a></li>
<li><a{{ group|is_on:'reading' }} href="{% url user_book_group username=reader.username,group="reading" %}">{% trans "Reading" %}</a></li>
<li><a{{ group|is_on:'plan-to-read' }} href="{% url user_book_group username=reader.username,group="plan-to-read" %}">{% trans "Plan to read" %}</a></li>
</ul>
Abstract it out to an XML tree:
@nathanborror
nathanborror / xmltohtml.py
Created July 27, 2011 06:55
XML to HTML template rendering
from lxml import objectify
from django import template
from django.template.loader import render_to_string
register = template.Library()
class XMLNode(template.Node):
def __init__(self, xml):
function Jtl(tpl) {
this._nodelist = this._compile(tpl);
}
Jtl.prototype = {
_compile : function(tpl) {
var tag_str = this._formRegx();
var tag_re = new RegExp(tag_str,'g');
var bits = new Jtl.StringBuilder(tpl).bsplit(tag_re);
bits = new Jtl.ArrayBuilder(bits).filter('');
@login_required
def comment_edit(request, comment_id, template_name='comments/edit.html'):
comment = get_object_or_404(Comment, pk=comment_id, user=request.user)
if request.POST:
data = request.POST.copy()
if not data.get('name', ''):
data["name"] = request.user.get_full_name() or request.user.username
if not data.get('email', ''):
data["email"] = request.user.email
The University of Kansas,
Let me briefly explain the process in which I'm trying to give you money:
1) I click a total of seven times to get to the point where I can pay my tuition and I'm greeted with: "Security Error: The authentication process failed or the page is not accessible to you at this moment." I decide to call the IT department and they say I need to try FireFox, it works. They go on to say if I allow third-party cookies on my initial browser the site would work. This is a terrible recommendation, third-party cookies are very insecure and should never be allowed. I'm trying to give you a lot of money and this should be easy.
2) I go to make a payment using my credit card. You only accept Mastercard and Discover, seriously? I only have Visa (along with everyone else) so this isn't going to work, not to mention the $25 fee you charge which, by this point is the turning of the blade. I'm trying to give you a lot of money and this should be easy.
3) I call the Bursars office they say use a check.
{% block content %}
- - -
<div class="section_wrapper">
<div class="section"></div>
<div class="section"></div>
<div class="section section_end"></div>
</div>
diff --git a/taggit/managers.py b/taggit/managers.py
index a751e21..918d256 100644
--- a/taggit/managers.py
+++ b/taggit/managers.py
@@ -2,7 +2,7 @@ from collections import defaultdict
import django
from django.contrib.contenttypes.models import ContentType
-from django.db import models
+from django.db import models, connection
The Department of Mad Scientists (Michael Belfiore)
- Highlight Loc. 184-92 | Added on Friday, January 01, 2010, 05:28 PM
The United States spent $651 billion on defense-related activities in 2009. That’s more than half of the U.S. discretionary budget, and more than the military budgets of China, Russia, and Europe combined. No less a figure than President Eisenhower—the same president who launched NASA and DARPA—warned of the direct cost to the nation’s citizens of extreme military spending. “Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed,” he told the American Society of Newspaper Editors in a speech that was broadcast over television and radio in April 1953. “The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is
@nathanborror
nathanborror / gist:266580
Created December 31, 2009 02:46
Readernaut API
=====================
Readernaut Public API
=====================
1.0 (pre-release)
=================
Reader Books
------------
# base.html
{% block content_wrapper %}
<div class="content">
{% block content %}{% endblock %}
</div>
{% endblock %}
# object_detail.html