Preliminary primary blog domain support.
parent
2e780d00b6
commit
4ab1f2a623
|
@ -59,4 +59,11 @@ class UserProfile(models.Model):
|
|||
google_ad_width = models.CharField(max_length=250, null=True, blank=True)
|
||||
google_ad_height = models.CharField(max_length=250, null=True, blank=True)
|
||||
|
||||
def get_primary_blog_domain(self):
|
||||
if not self.blog_domain:
|
||||
return None
|
||||
else:
|
||||
return self.blog_domain.split(' ')[0]
|
||||
|
||||
|
||||
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
@ -32,3 +33,6 @@ class BlogMiddleware:
|
|||
if pro_user.profile.blog_domain:
|
||||
if host in pro_user.profile.blog_domain.split(' '):
|
||||
request.blog_user = pro_user
|
||||
|
||||
if host != pro_user.profile.get_primary_blog_domain:
|
||||
return HttpResponseRedirect(pro_user.profile.get_primary_blog_domain)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
{% if request.blog_user.profile.is_pro %}
|
||||
<atom:link href="{% if request.blog_user.profile.blog_domain and 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" />
|
||||
<atom:link href="{% if request.blog_user.profile.get_primary_blog_domain and 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>
|
||||
<link>{% if request.blog_user.profile.get_primary_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>{{ request.blog_user.username }}</description>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<label class="control-label" for="id_blog_domain">Blog domain:</label>
|
||||
<div class="controls">
|
||||
<input id="id_blog_domain" type="text" ng-model="user.blog_domain" maxlength="250">
|
||||
<span class="help-block">Like 'snipt.nicksergeant.com' or 'nicksergeant.com' (without quotes). Set your CNAME / A-record to point to 96.126.110.160</span>
|
||||
<span class="help-block">Like 'snipt.nicksergeant.com' or 'nicksergeant.com' (without quotes). Set your CNAME / A-record to point to 96.126.110.160. You can use multiple domains here: separate each domain with a space. The first domain will be your primary domain. All other domains will redirect to your primary domain.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -127,8 +127,8 @@ class Snipt(models.Model):
|
|||
def get_absolute_url(self):
|
||||
|
||||
if self.blog_post:
|
||||
if self.user.profile.is_pro and self.user.profile.blog_domain is not None and self.user.profile.blog_domain != '':
|
||||
return 'http://{}/{}/'.format(self.user.profile.blog_domain, self.slug)
|
||||
if self.user.profile.is_pro and self.user.profile.blog_domain:
|
||||
return 'http://{}/{}/'.format(self.user.profile.blog_domain.split(' ')[0], self.slug)
|
||||
else:
|
||||
return 'https://{}.snipt.net/{}/'.format(self.user.username.replace('_', '-'), self.slug)
|
||||
|
||||
|
@ -143,8 +143,8 @@ class Snipt(models.Model):
|
|||
def get_full_absolute_url(self):
|
||||
|
||||
if self.blog_post:
|
||||
if self.user.profile.is_pro and self.user.profile.blog_domain is not None and self.user.profile.blog_domain != '':
|
||||
return 'http://{}/{}/'.format(self.user.profile.blog_domain, self.slug)
|
||||
if self.user.profile.is_pro and self.user.profile.blog_domain:
|
||||
return 'http://{}/{}/'.format(self.user.profile.blog_domain.split(' ')[0], self.slug)
|
||||
else:
|
||||
return 'https://{}.snipt.net/{}/'.format(self.user.username, self.slug)
|
||||
|
||||
|
|
Loading…
Reference in New Issue