Working on new Snipt Pro flow.
parent
f227b26fe1
commit
000aa11940
|
@ -1,4 +1,6 @@
|
|||
from django.contrib.auth.models import User
|
||||
from datetime import date
|
||||
from datetime import datetime
|
||||
from django.db import models
|
||||
from snipts.models import Snipt
|
||||
|
||||
|
@ -95,4 +97,8 @@ class UserProfile(models.Model):
|
|||
def has_public_snipts(self):
|
||||
return True if Snipt.objects.filter(user=self, public=True).count() > 0 else False
|
||||
|
||||
def get_account_age(self):
|
||||
delta = datetime.now().replace(tzinfo=None) - self.user.date_joined.replace(tzinfo=None)
|
||||
return delta.days
|
||||
|
||||
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
|
||||
|
|
|
@ -389,7 +389,7 @@ function setFullScreen(cm,full){var wrap=cm.getWrapperElement();if(full){wrap.cl
|
|||
cm.refresh();}
|
||||
window.editor.on(window,'resize',function(){var showing=document.body.getElementsByClassName('CodeMirror-fullscreen')[0];if(!showing)return;showing.CodeMirror.getWrapperElement().style.height=winHeight()+'px';});window.editor.setOption('extraKeys',{'Cmd-Enter':function(cm){that.save();window.site.snipt_list.escapeUI();return false;},'F11':function(cm){setFullScreen(cm,!isFullScreen(cm));},'Esc':function(cm){if(isFullScreen(cm))setFullScreen(cm,false);}});}});Snipt.SniptListView=Backbone.View.extend({el:'section#snipts',initialize:function(opts){var that=this;opts.snipts.each(this.addExistingSnipt);this.keyboardShortcuts();var cmd;if(navigator.platform=='MacPPC'||navigator.platform=='MacIntel'){cmd='Cmd';}
|
||||
else{cmd='Ctrl';}
|
||||
$('span.cmd-ctrl').text(cmd);$('button#add-snipt').click(function(){that.addNewSnipt();});},addExistingSnipt:function(){var $el=$(this);var $created=$('li.created',$el);var $h1=$('header h1 a',$el);var $public=$('div.public',$el);var $blog_post=$('div.blog-post',$el);var $publish_date=$('div.publish-date',$el);var $user=$('li.author a',$el);var is_public=$public.text()==='True'?true:false;var is_blog_post=$blog_post.text()==='True'?true:false;var tag_lis=$('section.tags li',$el);var tags=[];for(var i=0;i<tag_lis.length;i++){var $tag=$('a',tag_lis.eq(i));tags[i]={name:$tag.text(),absolute_url:$tag.attr('href')};}
|
||||
$('span.cmd-ctrl').text(cmd);$('button#add-snipt').click(function(){if(window.user_account_age>7&&!window.user_is_pro){window.location='/pro/?expired=true';}else{that.addNewSnipt();}});},addExistingSnipt:function(){var $el=$(this);var $created=$('li.created',$el);var $h1=$('header h1 a',$el);var $public=$('div.public',$el);var $blog_post=$('div.blog-post',$el);var $publish_date=$('div.publish-date',$el);var $user=$('li.author a',$el);var is_public=$public.text()==='True'?true:false;var is_blog_post=$blog_post.text()==='True'?true:false;var tag_lis=$('section.tags li',$el);var tags=[];for(var i=0;i<tag_lis.length;i++){var $tag=$('a',tag_lis.eq(i));tags[i]={name:$tag.text(),absolute_url:$tag.attr('href')};}
|
||||
var is_pro=$user.siblings('span.pro').length?true:false;var data={code:$('textarea.raw',$el).text(),description:$('textarea.description',$el).text(),created:$created.attr('title'),created_formatted:$created.text(),embed_url:$('div.embed-url',$el).text(),raw_url:$('div.raw-url',$el).text(),absolute_url:$h1.attr('href'),favorite_id:$el.data('favorite-id'),id:parseInt($el.attr('id').replace('snipt-',''),0),key:$('div.key',$el).text(),lexer:$('div.lexer',$el).text(),lexer_name:$('div.lexer-name',$el).text(),line_count:parseInt($('div.line-count',$el).text(),0),modified:$('div.modified',$el).text(),resource_uri:$('div.resource-uri',$el).text(),slug:$('div.slug',$el).text(),stylized:$('div.stylized',$el).text(),tags:tags,publish_date:$publish_date.text(),tags_list:$('div.tags-list',$el).text(),title:$h1.text(),user:{absolute_url:$user.attr('href'),username:$user.text(),profile:{is_pro:is_pro}}};data['public']=is_public;data.blog_post=is_blog_post;var view=new Snipt.SniptView({el:this,model:new Snipt.SniptModel(data)});},addNewSnipt:function(){var $articleNewSnipt=$('article#new-snipt');if($articleNewSnipt.length===0){window.site.snipt_list.$el.prepend('<article id="new-snipt" class="hidden snipt"></article>');var data={id:'',blog_post:false,code:'',description:'',tags:[],tags_list:'',title:'',lexer:'text',lexer_name:'Text only',new_from_js:true,public:false,user:{username:'',profile:{is_pro:window.user_is_pro}}};var newSniptView=new Snipt.SniptView({el:$('article#new-snipt'),model:new Snipt.SniptModel(data)});newSniptView.edit(true);}else{$articleNewSnipt.trigger('edit');}
|
||||
return false;},escapeUI:function(destroyed){if(window.editing||destroyed){if(!window.site.$html.hasClass('detail')){window.site.$body.removeClass('detail');}
|
||||
window.site.$main_edit.hide();window.site.$body.removeClass('editing');window.site.$main.show();window.editing=true;window.ui_halted=false;if(window.site.$snipts.index(window.$selected)===0){window.scrollTo(0,0);}else{window.site.$html_body.animate({scrollTop:window.$selected.offset().top-50},0);}
|
||||
|
|
|
@ -579,10 +579,12 @@
|
|||
}
|
||||
$('span.cmd-ctrl').text(cmd);
|
||||
|
||||
// This should probably be handled more traditionally
|
||||
// (in a backbone view / events)
|
||||
$('button#add-snipt').click(function() {
|
||||
that.addNewSnipt();
|
||||
if (window.user_account_age > 7 && !window.user_is_pro) {
|
||||
window.location = '/pro/?expired=true';
|
||||
} else {
|
||||
that.addNewSnipt();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ from haystack.query import SearchQuerySet
|
|||
from accounts.models import UserProfile
|
||||
from tastypie.cache import SimpleCache
|
||||
from tastypie.fields import ListField
|
||||
from django.http import HttpResponse
|
||||
from taggit.models import Tag
|
||||
from django.db import models
|
||||
from tastypie import fields
|
||||
|
@ -162,6 +163,17 @@ class FavoriteValidation(Validation):
|
|||
|
||||
return errors
|
||||
|
||||
class SniptValidation(Validation):
|
||||
def is_valid(self, bundle, request=None):
|
||||
errors = {}
|
||||
|
||||
if 'pk' not in bundle.data and \
|
||||
request.user.profile.get_account_age() > 7 and \
|
||||
request.user.profile.is_pro == False:
|
||||
errors['expired'] = "Your trial has expired. You'll need to subscribe in order to create new snipts. Read more at https://blog.snipt.net/moving-away-from-free-accounts-and-planning-for-the-future/."
|
||||
|
||||
return errors
|
||||
|
||||
class UserProfileValidation(Validation):
|
||||
def is_valid(self, bundle, request=None):
|
||||
errors = {}
|
||||
|
@ -354,6 +366,7 @@ class PrivateSniptResource(ModelResource):
|
|||
list_allowed_methods = ['get', 'post']
|
||||
authentication = ApiKeyAuthentication()
|
||||
authorization = PrivateSniptAuthorization()
|
||||
validation = SniptValidation()
|
||||
ordering = ['created', 'modified',]
|
||||
always_return_data = True
|
||||
max_limit = 200
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block add-snipt %}
|
||||
<li class="add-snipt">
|
||||
<button class="btn btn-info btn-large" id="add-snipt">
|
||||
Add {% if request.user.username == 'blog' %}Post{% else %}Snipt{% endif %}
|
||||
<i class="icon-search icon-plus icon-white"></i>
|
||||
</button>
|
||||
</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block page-title %}/ {% if snipt.title %}{{ snipt.title }}{% else %}Untitled{% endif %} / {{ user.username }} - {{ block.super }}{% endblock %}
|
||||
{% block html-class %}detail{% endblock %}
|
||||
{% block body-class %}{% if request.path == '/api/' or request.path == '/blogging/' %}snipt-page{% else %}detail{% endif %}{% endblock %}
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
{% extends "snipts/list.html" %}
|
||||
|
||||
{% block add-snipt %}
|
||||
<li class="add-snipt">
|
||||
<button class="btn btn-info btn-large" id="add-snipt">
|
||||
Add {% if request.user.username == 'blog' %}Post{% else %}Snipt{% endif %}
|
||||
<i class="icon-search icon-plus icon-white"></i>
|
||||
</button>
|
||||
</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
<li><a href="/public/">public</a></li>
|
||||
{% if tag %}
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
{% extends "snipts/list.html" %}
|
||||
|
||||
{% block add-snipt %}
|
||||
<li class="add-snipt">
|
||||
<button class="btn btn-info btn-large" id="add-snipt">
|
||||
Add {% if request.user.username == 'blog' %}Post{% else %}Snipt{% endif %}
|
||||
<i class="icon-search icon-plus icon-white"></i>
|
||||
</button>
|
||||
</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
<li><a href="/{{ user.username }}/">{{ user.username }}</a></li>
|
||||
{% if tag %}
|
||||
|
|
|
@ -102,12 +102,7 @@
|
|||
<li>
|
||||
<a href="/public/" {% if '/public/' in request.path or public %} class="active"{% endif %}>Public snipts</a>
|
||||
</li>
|
||||
<li class="add-snipt">
|
||||
<button class="btn btn-info btn-large" id="add-snipt">
|
||||
Add {% if request.user.username == 'blog' %}Post{% else %}Snipt{% endif %}
|
||||
<i class="icon-search icon-plus icon-white"></i>
|
||||
</button>
|
||||
</li>
|
||||
{% block add-snipt %}{% endblock %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
|
@ -255,9 +250,11 @@
|
|||
{% block main-edit %}
|
||||
<section class="main group hidden" id="main-edit"></section>
|
||||
{% endblock %}
|
||||
{% if request.user.is_authenticated and request.user.profile.get_account_age > 7 %}
|
||||
<div class="get-support">
|
||||
<a class="btn btn-info" href="/pro/">Get support »</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% block keyboard-shortcuts %}
|
||||
<div class="modal hide" id="keyboard-shortcuts">
|
||||
<div class="modal-header">
|
||||
|
@ -365,6 +362,7 @@
|
|||
window.user_ip = '{{ request.META.REMOTE_ADDR }}';
|
||||
window.user_profile_id = {% firstof request.user.profile.id 'null' %};
|
||||
window.user_email = '{{ request.user.email }}';
|
||||
window.user_account_age = {% firstof request.user.profile.get_account_age 'null' %};
|
||||
|
||||
{% if public %}
|
||||
window.pub = {{ public|lower }};
|
||||
|
@ -417,7 +415,7 @@
|
|||
{% include 'snipts/snipt-edit-js-template.html' %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% if request.user.is_authenticated and request.user.is_pro %}
|
||||
{% if request.user.is_authenticated and request.user.is_pro or request.user.profile.get_account_age <= 7 %}
|
||||
{% if not debug %}
|
||||
{% block intercom %}
|
||||
<script id="IntercomSettingsScriptTag">
|
||||
|
|
Loading…
Reference in New Issue