2012-06-26 08:33:29 -07:00
|
|
|
from django.contrib.auth.models import User
|
2014-05-04 19:47:15 -07:00
|
|
|
from datetime import date
|
|
|
|
from datetime import datetime
|
2012-06-26 08:33:29 -07:00
|
|
|
from django.db import models
|
2013-04-04 09:39:20 -07:00
|
|
|
from snipts.models import Snipt
|
2012-06-26 08:33:29 -07:00
|
|
|
|
2012-07-18 21:39:43 -07:00
|
|
|
class UserProfile(models.Model):
|
2013-01-15 21:09:54 -08:00
|
|
|
|
2013-10-18 21:41:00 -07:00
|
|
|
LIST_VIEW_CHOICES = (
|
|
|
|
('N', 'Normal'),
|
|
|
|
('C', 'Compact'),
|
|
|
|
)
|
|
|
|
|
2013-02-04 11:40:45 -08:00
|
|
|
EDITOR_CHOICES = (
|
|
|
|
('C', 'CodeMirror'),
|
|
|
|
('T', 'Textarea'),
|
|
|
|
)
|
|
|
|
|
2013-01-15 21:09:54 -08:00
|
|
|
THEME_CHOICES = (
|
|
|
|
('D', 'Default'),
|
|
|
|
('A', 'Pro Adams'),
|
|
|
|
)
|
|
|
|
|
2013-02-05 12:24:51 -08:00
|
|
|
EDITOR_THEME_CHOICES = (
|
|
|
|
('default', 'Default'),
|
|
|
|
('ambiance', 'Ambiance'),
|
|
|
|
('blackboard', 'Blackboard'),
|
|
|
|
('cobalt', 'Cobalt'),
|
|
|
|
('eclipse', 'Eclipse'),
|
|
|
|
('elegant', 'Elegant'),
|
|
|
|
('erlang-dark', 'Erlang Dark'),
|
|
|
|
('lesser-dark', 'Lesser Dark'),
|
|
|
|
('monokai', 'Monokai'),
|
|
|
|
('neat', 'Neat'),
|
|
|
|
('night', 'Night'),
|
|
|
|
('rubyblue', 'Ruby Blue'),
|
|
|
|
('solarized dark', 'Solarized Dark'),
|
|
|
|
('solarized light', 'Solarized Light'),
|
|
|
|
('twilight', 'Twilight'),
|
|
|
|
('vibrant-ink', 'Vibrant Ink'),
|
|
|
|
('xq-dark', 'XQ Dark'),
|
|
|
|
)
|
|
|
|
|
2013-02-08 21:06:22 -08:00
|
|
|
# User
|
2013-01-13 09:51:25 -08:00
|
|
|
user = models.ForeignKey(User, unique=True)
|
|
|
|
is_pro = models.BooleanField(default=False)
|
2014-06-27 07:24:35 -07:00
|
|
|
pro_date = models.DateTimeField(blank=True, null=True)
|
2013-01-13 09:51:25 -08:00
|
|
|
stripe_id = models.CharField(max_length=100, null=True, blank=True)
|
2013-04-14 19:57:23 -07:00
|
|
|
has_gravatar = models.BooleanField(default=False)
|
2013-10-18 21:41:00 -07:00
|
|
|
list_view = models.CharField(max_length=1, null=False, blank=False,default='N', choices=LIST_VIEW_CHOICES)
|
2013-01-13 09:51:25 -08:00
|
|
|
|
2013-02-08 21:06:22 -08:00
|
|
|
# Blog
|
2013-01-15 21:09:54 -08:00
|
|
|
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)
|
2013-02-08 21:06:22 -08:00
|
|
|
|
|
|
|
# Editor
|
2013-02-04 11:40:45 -08:00
|
|
|
default_editor = models.CharField(max_length=250, null=False, blank=False, default='C', choices=EDITOR_CHOICES)
|
2013-02-05 12:24:51 -08:00
|
|
|
editor_theme = models.CharField(max_length=250, null=False, blank=False, default='default', choices=EDITOR_THEME_CHOICES)
|
2012-07-08 20:21:36 -07:00
|
|
|
|
2013-02-08 21:06:22 -08:00
|
|
|
# Services and Analytics
|
2013-02-02 20:01:34 -08:00
|
|
|
gittip_username = models.CharField(max_length=250, null=True, blank=True)
|
|
|
|
disqus_shortname = models.CharField(max_length=250, null=True, blank=True)
|
2013-02-05 06:59:43 -08:00
|
|
|
google_analytics_tracking_id = models.CharField(max_length=250, null=True, blank=True)
|
2013-02-07 07:58:26 -08:00
|
|
|
gauges_site_id = models.CharField(max_length=250, null=True, blank=True)
|
2013-02-02 20:01:34 -08:00
|
|
|
|
2013-02-08 21:06:22 -08:00
|
|
|
# Google Ads
|
|
|
|
google_ad_client = models.CharField(max_length=250, null=True, blank=True)
|
|
|
|
google_ad_slot = models.CharField(max_length=250, null=True, blank=True)
|
|
|
|
google_ad_width = models.CharField(max_length=250, null=True, blank=True)
|
|
|
|
google_ad_height = models.CharField(max_length=250, null=True, blank=True)
|
|
|
|
|
2013-04-04 09:39:20 -07:00
|
|
|
def get_blog_posts(self):
|
|
|
|
return Snipt.objects.filter(user=self.user, blog_post=True, public=True)
|
|
|
|
|
2013-02-11 22:32:44 -08:00
|
|
|
def get_primary_blog_domain(self):
|
|
|
|
if not self.blog_domain:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return self.blog_domain.split(' ')[0]
|
|
|
|
|
2013-04-05 07:22:14 -07:00
|
|
|
def get_user_profile_url(self):
|
|
|
|
|
|
|
|
# If the user has a blog domain, use that.
|
|
|
|
if self.blog_domain:
|
|
|
|
url = 'http://{}'.format(self.get_primary_blog_domain())
|
|
|
|
|
|
|
|
# Otherwise, if they have blog posts, use their Snipt blog URL.
|
|
|
|
elif self.get_blog_posts():
|
|
|
|
url = 'https://{}.snipt.net/'.format(self.user.username)
|
|
|
|
|
|
|
|
# Otherwise, use their regular Snipt profile page.
|
|
|
|
else:
|
|
|
|
url = 'https://snipt.net/{}/'.format(self.user.username)
|
|
|
|
|
|
|
|
return url
|
|
|
|
|
2013-04-15 12:01:04 -07:00
|
|
|
def has_public_snipts(self):
|
|
|
|
return True if Snipt.objects.filter(user=self, public=True).count() > 0 else False
|
2013-02-11 22:32:44 -08:00
|
|
|
|
2014-05-04 19:47:15 -07:00
|
|
|
def get_account_age(self):
|
|
|
|
delta = datetime.now().replace(tzinfo=None) - self.user.date_joined.replace(tzinfo=None)
|
|
|
|
return delta.days
|
|
|
|
|
2012-06-26 08:33:29 -07:00
|
|
|
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
|