A big ass commit. This commit converts the existing manual blog domain and theme selection to an automatic process. Closes #8

master
Nick Sergeant 2013-01-16 00:09:54 -05:00
parent e3c5646b24
commit 92493cf1a1
14 changed files with 194 additions and 105 deletions

View File

@ -4,4 +4,4 @@ from accounts.models import UserProfile
class AccountForm(ModelForm):
class Meta:
model = UserProfile
fields = ('gittip_username',)
exclude = ('user', 'is_pro', 'stripe_id',)

View File

@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'UserProfile.blog_domain'
db.add_column('accounts_userprofile', 'blog_domain',
self.gf('django.db.models.fields.CharField')(max_length=250, null=True, blank=True),
keep_default=False)
# Adding field 'UserProfile.blog_title'
db.add_column('accounts_userprofile', 'blog_title',
self.gf('django.db.models.fields.CharField')(max_length=250, null=True, blank=True),
keep_default=False)
# Adding field 'UserProfile.blog_theme'
db.add_column('accounts_userprofile', 'blog_theme',
self.gf('django.db.models.fields.CharField')(default='D', max_length=1),
keep_default=False)
def backwards(self, orm):
# Deleting field 'UserProfile.blog_domain'
db.delete_column('accounts_userprofile', 'blog_domain')
# Deleting field 'UserProfile.blog_title'
db.delete_column('accounts_userprofile', 'blog_title')
# Deleting field 'UserProfile.blog_theme'
db.delete_column('accounts_userprofile', 'blog_theme')
models = {
'accounts.userprofile': {
'Meta': {'object_name': 'UserProfile'},
'blog_domain': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
'blog_theme': ('django.db.models.fields.CharField', [], {'default': "'D'", 'max_length': '1'}),
'blog_title': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
'gittip_username': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_pro': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'stripe_id': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
},
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}
complete_apps = ['accounts']

View File

@ -1,12 +1,20 @@
from django.contrib.auth.models import User
from django.db import models
class UserProfile(models.Model):
THEME_CHOICES = (
('D', 'Default'),
('A', 'Pro Adams'),
)
user = models.ForeignKey(User, unique=True)
is_pro = models.BooleanField(default=False)
stripe_id = models.CharField(max_length=100, null=True, blank=True)
gittip_username = models.CharField(max_length=250, null=True, blank=True)
blog_title = models.CharField(max_length=250, null=True, blank=True)
blog_theme = models.CharField(max_length=1, null=False, blank=False, default='D', choices=THEME_CHOICES)
blog_domain = models.CharField(max_length=250, null=True, blank=True)
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])

View File

@ -28,10 +28,29 @@
<div class="control-group">
<label class="control-label" for="id_gittip_username">GitTip username:</label>
<div class="controls">
<input type="text" id="id_gittip_username" name="gittip_username" value="{% firstof request.user.profile.gittip_username '' %}">
{{ form.gittip_username }}
<span class="help-block">Your <a href="https://www.gittip.com/">GitTip</a> username, if you have one.</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="id_blog_title">Blog title:</label>
<div class="controls">
{{ form.blog_title }}
</div>
</div>
<div class="control-group">
<label class="control-label" for="id_blog_theme">Blog theme:</label>
<div class="controls">
{{ form.blog_theme }}
</div>
</div>
<div class="control-group">
<label class="control-label" for="id_blog_domain">Blog domain:</label>
<div class="controls">
{{ form.blog_domain }}
<span class="help-block">Like 'snipt.nicksergeant.com' or 'nicksergeant.com' (without quotes). Set your CNAME / A-record to point to 54.243.204.150</span>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Save</button>
</div>

View File

@ -18,7 +18,14 @@ def account(request):
return HttpResponseRedirect('/account/')
else:
form = AccountForm()
profile = request.user.profile
form = AccountForm(initial={
'gittip_username': profile.gittip_username,
'blog_title': profile.blog_title,
'blog_theme': profile.blog_theme,
'blog_domain': profile.blog_domain
})
return {
'form': form

View File

@ -14,7 +14,6 @@ class BlogMiddleware:
if host != 'snipt.net' and host != 'snipt.localhost':
if len(host_s) > 2:
if host_s[1] == 'snipt':
# nick.snipt.net or nick.snipt.localhost
blog_user = ''.join(host_s[:-2])
@ -26,18 +25,9 @@ class BlogMiddleware:
else:
request.blog_user = get_object_or_404(User, username__iexact=blog_user)
# TODO: build this into account settings.
if host == 'rochacbruno.com.br':
request.blog_user = User.objects.get(id=2156)
if request.blog_user is None:
pro_users = User.objects.filter(userprofile__is_pro=True, username='nick')
if host == 'snips.witsoregon.com':
request.blog_user = User.objects.get(id=12291)
if host == 'snipt.joshhudnall.com':
request.blog_user = User.objects.get(id=10325)
if host == 'nicksergeant.com':
request.blog_user = User.objects.get(id=3)
if host == 'ashleysergeant.com':
request.blog_user = User.objects.get(id=18)
for pro_user in pro_users:
if host == pro_user.profile.blog_domain:
request.blog_user = pro_user

View File

@ -3,7 +3,14 @@
{% block body-class %}blog-site{% endblock %}
{% block html-class %}blog-site{% endblock %}
{% block page-title %}{% if blog_user.username == 'nick' %}// Nick Sergeant {% elif blog_user.username == 'blog' %}// Snipt Blog{% else %}// {{ blog_user.username }}{% endif %}{% endblock %}
{% block page-title %}
//
{% if blog_user.profile.blog_title %}
{{ blog_user.profile.blog_title }}
{% else %}
{{ blog_user.username }}
{% endif %}
{% endblock %}
{% block page-description %}{% endblock %}
{% block rochester-made %}{% endblock %}
@ -19,10 +26,8 @@
<div class="inner group">
<h1>
<a href="/">
{% if blog_user.username == 'nick' %}
Nick Sergeant
{% elif blog_user.username == 'blog' %}
Snipt Blog
{% if blog_user.profile.blog_title %}
{{ blog_user.profile.blog_title }}
{% else %}
{{ blog_user.username }}
{% endif %}

View File

@ -1,39 +1,14 @@
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
{% if request.blog_user.username == 'nick' %}
<atom:link href="http://nicksergeant.com/?rss" rel="self" type="application/rss+xml" />
<description>Nick Sergeant</description>
<title>Nick Sergeant</title>
<link>http://nicksergeant.com/?rss</link>
{% elif request.blog_user.username == 'ashley' %}
<atom:link href="http://ashleysergeant.com/?rss" rel="self" type="application/rss+xml" />
<description>Ashley Sergeant</description>
<title>Ashley Sergeant</title>
<link>http://ashleysergeant.com/?rss</link>
{% elif request.blog_user.username == 'gdemaderios' %}
<atom:link href="http://snips.witsoregon.com/?rss" rel="self" type="application/rss+xml" />
<description>gdemaderios</description>
<title>gdemaderios</title>
<link>http://snips.witsoregon.com/?rss</link>
{% elif request.blog_user.username == 'rochacbruno' %}
<atom:link href="http://rochacbruno.com.br/?rss" rel="self" type="application/rss+xml" />
<description>Bruno Cezar Rocha</description>
<title>Bruno Cezar Rocha</title>
<link>http://rochacbruno.com.br/?rss</link>
{% elif request.blog_user.username == 'joshhudnall' %}
<atom:link href="http://snipt.joshhudnall.com/?rss" rel="self" type="application/rss+xml" />
<description>Josh Hudnall</description>
<title>Josh Hudnall</title>
<link>http://snipt.joshhudnall.com/?rss</link>
{% elif request.blog_user.username == 'blog' %}
<atom:link href="https://blog.snipt.net/?rss" rel="self" type="application/rss+xml" />
<description>Snipt Blog</description>
<title>Snipt Blog</title>
<link>https://blog.snipt.net/?rss</link>
{% if request.blog_user.profile.is_pro %}
<atom:link href="{% if request.blog_user.profile.blog_domain %}http://{{ request.blog_user.profile.blog_domain }}/?rss{% else %}https://{{ request.blog_user.username }}.snipt.net/?rss{% endif %}" rel="self" type="application/rss+xml" />
<description>{% firstof request.blog_user.profile.blog_title request.blog_user.username %}</description>
<title>{% firstof request.blog_user.profile.blog_title request.blog_user.username %}</title>
<link>{% if request.blog_user.profile.blog_domain %}http://{{ request.blog_user.profile.blog_domain }}/?rss{% else %}https://{{ request.blog_user.username }}.snipt.net/?rss{% endif %}</link>
{% else %}
<atom:link href="https://{{ request.blog_user.username }}.snipt.net/?rss" rel="self" type="application/rss+xml" />
<description>{% if request.blog_user.username == 'nick' %}Nick Sergeant{% else %}{{ request.blog_user.username }}{% endif %}</description>
<title>{% if request.blog_user.username == 'nick' %}Nick Sergeant{% else %}{{ request.blog_user.username }}{% endif %}</title>
<description>{{ request.blog_user.username }}</description>
<title>{{ request.blog_user.username }}</title>
<link>https://{{ request.blog_user.username }}.snipt.net/?rss</link>
{% endif %}
{% for snipt in snipts %}

View File

@ -6,8 +6,17 @@
<title>
{% block page-title %}
{% if blog_user.username == 'nick' %}// Nick Sergeant{% elif blog_user.username == 'ashley' %}// Ashley Sergeant{% elif blog_user.username == 'blog' %}// Snipt Blog{% else %}// {{ blog_user.username }}{% endif %}{% endblock %}</title>
//
{% if blog_user.profile.blog_title %}
{{ blog_user.profile.blog_title }}
{% else %}
{{ blog_user.username }}
{% endif %}
{% endblock %}
</title>
<meta charset="utf-8" />
{% if 'page' in request.GET %}
<meta name="robots" content="noindex, follow" />
{% endif %}
@ -52,12 +61,8 @@
</a>
<div class="bio">
<a class="name" href="/">
{% if blog_user.username == 'nick' %}
Nick Sergeant
{% elif blog_user.username == 'blog' %}
Snipt Blog
{% elif blog_user.username == 'ashley' %}
Ashley Sergeant
{% if blog_user.profile.blog_title %}
{{ blog_user.profile.blog_title }}
{% else %}
{{ blog_user.username }}
{% endif %}
@ -66,8 +71,7 @@
<p>
I'm a front-end web developer in Rochester, NY working on the <a href="http://amara.org/">Amara</a> project for <a href="http://pculture.org/">PCF</a>. I also created <a href="https://snipt.net/">Snipt</a>.
</p>
{% endif %}
{% if blog_user.username == 'ashley' %}
{% elif blog_user.username == 'ashley' %}
<p>Life is like photography, we use<br />the negatives to develop.</p>
{% endif %}
</div>
@ -86,9 +90,7 @@
projects. View my <a href="/work/">work</a>, then<br />
<a href="mailto:nick@nicksergeant.com">email me</a>.
</p>
<iframe style="border: 0; margin: 0; padding: 0;"
src="https://www.gittip.com/nicksergeant/widget.html"
width="48pt" height="22pt"></iframe>
<iframe style="border: 0; margin: 0; padding: 0;" src="https://www.gittip.com/nicksergeant/widget.html" width="48pt" height="22pt"></iframe>
</section>
<section class="module projects">
<h1>Notable projects</h1>
@ -121,8 +123,7 @@
{% endfor %}
</ul>
</section>
{% endif %}
{% if blog_user.username == 'ashley' %}
{% elif blog_user.username == 'ashley' %}
<section class="module places">
<h1>Elsewhere</h1>
<ul>
@ -130,6 +131,12 @@
<li><a href="https://twitter.com/ashleysergeant">Twitter</a></li>
</ul>
</section>
{% else %}
{% if sidebar %}
<section class="module places">
{{ sidebar.stylized|safe }}
</section>
{% endif %}
{% endif %}
</aside>
</section>

View File

@ -1,12 +1,15 @@
from django.shortcuts import get_object_or_404, render_to_response
from annoying.functions import get_object_or_None
from django.template import RequestContext
from django.conf import settings
from snipts.models import Snipt
import datetime
THEME_CHOICES = {
'D': 'blogs/themes/default/',
'A': 'blogs/themes/pro-adams/',
}
def blog_list(request, username_or_custom_slug=None):
@ -41,10 +44,12 @@ def blog_list(request, username_or_custom_slug=None):
context['snipts'] = context['snipts'][:20]
return rss(request, context)
if request.blog_user.profile.is_pro and request.blog_user.username in ['nick', 'ashley']:
template = 'blogs/themes/pro-adams/list.html'
if request.blog_user.profile.is_pro:
template = THEME_CHOICES[request.blog_user.profile.blog_theme]
else:
template = 'blogs/themes/default/list.html'
template = THEME_CHOICES['D']
template = '{}/list.html'.format(template)
return render_to_response(
template,
@ -84,10 +89,12 @@ def blog_post(request, username_or_custom_slug):
'snipt': snipt,
}
if request.blog_user.profile.is_pro and request.blog_user.username in ['nick', 'ashley']:
template = 'blogs/themes/pro-adams/post.html'
if request.blog_user.profile.is_pro:
template = THEME_CHOICES[request.blog_user.profile.blog_theme]
else:
template = 'blogs/themes/default/post.html'
template = THEME_CHOICES['D']
template = '{}/post.html'.format(template)
return render_to_response(
template,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1420,6 +1420,11 @@ body.account {
div.control-group:first-of-type {
margin-top: 20px;
}
span.help-block {
color: #999;
font-size: 12px;
max-width: 370px;
}
}
}
}

View File

@ -126,19 +126,8 @@ class Snipt(models.Model):
def get_absolute_url(self):
if self.blog_post:
if self.user.id == 3:
if settings.DEBUG:
return 'http://nick.snipt.localhost/{}/'.format(self.slug)
else:
return 'http://nicksergeant.com/{}/'.format(self.slug)
elif self.user.id == 18:
return 'http://ashleysergeant.com/{}/'.format(self.slug)
elif self.user.id == 12291:
return 'http://snips.witsoregon.com/{}/'.format(self.slug)
elif self.user.id == 2156:
return 'http://rochacbruno.com.br/{}/'.format(self.slug)
elif self.user.id == 10325:
return 'http://snipt.joshhudnall.com/{}/'.format(self.slug)
if self.user.profile.is_pro and self.user.profile.blog_domain is not None:
return 'http://{}/{}/'.format(self.user.profile.blog_domain, self.slug)
else:
return 'https://{}.snipt.net/{}/'.format(self.user.username.replace('_', '-'), self.slug)
@ -153,19 +142,8 @@ class Snipt(models.Model):
def get_full_absolute_url(self):
if self.blog_post:
if self.user.id == 3:
if settings.DEBUG:
return 'http://nick.snipt.localhost/{}/'.format(self.slug)
else:
return 'http://nicksergeant.com/{}/'.format(self.slug)
elif self.user.id == 18:
return 'http://ashleysergeant.com/{}/'.format(self.slug)
elif self.user.id == 12291:
return 'http://snips.witsoregon.com/{}/'.format(self.slug)
elif self.user.id == 2156:
return 'http://rochacbruno.com.br/{}/'.format(self.slug)
elif self.user.id == 10325:
return 'http://snipt.joshhudnall.com/{}/'.format(self.slug)
if self.user.profile.is_pro and self.user.profile.blog_domain is not None:
return 'http://{}/{}/'.format(self.user.profile.blog_domain, self.slug)
else:
return 'https://{}.snipt.net/{}/'.format(self.user.username, self.slug)