Bringing Account information to the API.
parent
8c4b7b3bf0
commit
83bda92684
File diff suppressed because one or more lines are too long
|
@ -55,8 +55,10 @@
|
||||||
|
|
||||||
var promise = $http({
|
var promise = $http({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: '/api/account/',
|
url: '/api/private/profile/' + window.user_profile_id + '/',
|
||||||
headers: {}
|
headers: {
|
||||||
|
'Authorization': 'ApiKey ' + window.user + ':' + window.api_key
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
|
@ -71,7 +73,7 @@
|
||||||
$scope.route = $route;
|
$scope.route = $route;
|
||||||
|
|
||||||
AccountStorage.getAccount().then(function(response) {
|
AccountStorage.getAccount().then(function(response) {
|
||||||
console.log(response);
|
$scope.user = response.data;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
|
||||||
(function(){if(typeof angular!=='undefined'){var root=this;var $=root.jQuery;var app=angular.module('Account',[],function($routeProvider,$locationProvider){$locationProvider.html5Mode(true);$routeProvider.when('/account/',{templateUrl:'/media/js/src/modules/partials/profile.html',controller:controllers.ProfileController});$routeProvider.when('/account/billing/',{templateUrl:'/media/js/src/modules/partials/billing.html',controller:controllers.BillingController});$routeProvider.when('/account/blogging/',{templateUrl:'/media/js/src/modules/partials/blogging.html',controller:controllers.BloggingController});$routeProvider.when('/account/editor/',{templateUrl:'/media/js/src/modules/partials/editor.html',controller:controllers.EditorController});$routeProvider.otherwise({'redirectTo':function(routeParams,locationPath){window.location=locationPath;}});});app.config(function($interpolateProvider){$interpolateProvider.startSymbol('[[');$interpolateProvider.endSymbol(']]');});app.factory('AccountStorage',function($http){return{getAccount:function(){var promise=$http({method:'GET',url:'/api/account/',headers:{}});return promise;}};});var controllers={};controllers.MainController=function($scope,$route,AccountStorage){$scope.route=$route;AccountStorage.getAccount().then(function(response){console.log(response);});};controllers.BillingController=function($scope){$scope.section='Billing';};controllers.BloggingController=function($scope){$scope.section='Blogging';};controllers.EditorController=function($scope){$scope.section='Editor';};controllers.ProfileController=function($scope){$scope.section='Profile';};app.controller(controllers);}}).call(this);
|
(function(){if(typeof angular!=='undefined'){var root=this;var $=root.jQuery;var app=angular.module('Account',[],function($routeProvider,$locationProvider){$locationProvider.html5Mode(true);$routeProvider.when('/account/',{templateUrl:'/media/js/src/modules/partials/profile.html',controller:controllers.ProfileController});$routeProvider.when('/account/billing/',{templateUrl:'/media/js/src/modules/partials/billing.html',controller:controllers.BillingController});$routeProvider.when('/account/blogging/',{templateUrl:'/media/js/src/modules/partials/blogging.html',controller:controllers.BloggingController});$routeProvider.when('/account/editor/',{templateUrl:'/media/js/src/modules/partials/editor.html',controller:controllers.EditorController});$routeProvider.otherwise({'redirectTo':function(routeParams,locationPath){window.location=locationPath;}});});app.config(function($interpolateProvider){$interpolateProvider.startSymbol('[[');$interpolateProvider.endSymbol(']]');});app.factory('AccountStorage',function($http){return{getAccount:function(){var promise=$http({method:'GET',url:'/api/private/profile/'+window.user_profile_id+'/',headers:{'Authorization':'ApiKey '+window.user+':'+window.api_key}});return promise;}};});var controllers={};controllers.MainController=function($scope,$route,AccountStorage){$scope.route=$route;AccountStorage.getAccount().then(function(response){$scope.user=response.data;});};controllers.BillingController=function($scope){$scope.section='Billing';};controllers.BloggingController=function($scope){$scope.section='Blogging';};controllers.EditorController=function($scope){$scope.section='Editor';};controllers.ProfileController=function($scope){$scope.section='Profile';};app.controller(controllers);}}).call(this);
|
|
@ -8,6 +8,7 @@ from tastypie.validation import Validation
|
||||||
from tastypie.models import create_api_key
|
from tastypie.models import create_api_key
|
||||||
from snipts.models import Favorite, Snipt
|
from snipts.models import Favorite, Snipt
|
||||||
from haystack.query import SearchQuerySet
|
from haystack.query import SearchQuerySet
|
||||||
|
from accounts.models import UserProfile
|
||||||
from tastypie.cache import SimpleCache
|
from tastypie.cache import SimpleCache
|
||||||
from tastypie.fields import ListField
|
from tastypie.fields import ListField
|
||||||
from taggit.models import Tag
|
from taggit.models import Tag
|
||||||
|
@ -117,7 +118,32 @@ class PublicSniptResource(ModelResource):
|
||||||
return orm_filters
|
return orm_filters
|
||||||
|
|
||||||
|
|
||||||
|
class PrivateUserProfileResource(ModelResource):
|
||||||
|
class Meta:
|
||||||
|
queryset = UserProfile.objects.all()
|
||||||
|
resource_name = 'profile'
|
||||||
|
excludes = ['is_pro', 'stripe_id']
|
||||||
|
include_absolute_url = False
|
||||||
|
allowed_methods = ['get', 'put']
|
||||||
|
list_allowed_methods = []
|
||||||
|
authentication = ApiKeyAuthentication()
|
||||||
|
authorization = Authorization()
|
||||||
|
always_return_data = True
|
||||||
|
max_limit = 200
|
||||||
|
cache = SimpleCache()
|
||||||
|
|
||||||
|
def apply_authorization_limits(self, request, object_list):
|
||||||
|
return object_list.filter(user=request.user)
|
||||||
|
|
||||||
|
def dehydrate(self, bundle):
|
||||||
|
bundle.data['email'] = bundle.obj.user.email
|
||||||
|
bundle.data['username'] = bundle.obj.user.username
|
||||||
|
bundle.data['api_key'] = bundle.obj.user.api_key.key
|
||||||
|
return bundle
|
||||||
|
|
||||||
class PrivateUserResource(ModelResource):
|
class PrivateUserResource(ModelResource):
|
||||||
|
profile = fields.ForeignKey(PrivateUserProfileResource, 'profile', full=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
queryset = User.objects.all()
|
queryset = User.objects.all()
|
||||||
resource_name = 'user'
|
resource_name = 'user'
|
||||||
|
@ -136,9 +162,6 @@ class PrivateUserResource(ModelResource):
|
||||||
|
|
||||||
def dehydrate(self, bundle):
|
def dehydrate(self, bundle):
|
||||||
bundle.data['email_md5'] = hashlib.md5(bundle.obj.email.lower()).hexdigest()
|
bundle.data['email_md5'] = hashlib.md5(bundle.obj.email.lower()).hexdigest()
|
||||||
bundle.data['profile'] = {
|
|
||||||
'is_pro': bundle.obj.profile.is_pro
|
|
||||||
}
|
|
||||||
return bundle
|
return bundle
|
||||||
|
|
||||||
class PrivateTagResource(ModelResource):
|
class PrivateTagResource(ModelResource):
|
||||||
|
|
|
@ -334,23 +334,35 @@
|
||||||
{% block inline-js %}
|
{% block inline-js %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
{% block js %}
|
{% block js %}
|
||||||
|
|
||||||
window.user = '{{ request.user.username }}';
|
window.user = '{{ request.user.username }}';
|
||||||
|
window.user_id = {{ request.user.id }};
|
||||||
|
window.user_profile_id = {{ request.user.profile.id }};
|
||||||
|
|
||||||
{% if public %}
|
{% if public %}
|
||||||
window.pub = {{ public|lower }};
|
window.pub = {{ public|lower }};
|
||||||
{% else %}
|
{% else %}
|
||||||
window.pub = null;
|
window.pub = null;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
window.api_key = '{{ request.user.api_key.key }}';
|
window.api_key = '{{ request.user.api_key.key }}';
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% if tag %}
|
{% if tag %}
|
||||||
|
|
||||||
window.tag = '{{ tag.name }}';
|
window.tag = '{{ tag.name }}';
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if request.user.profile.is_pro %}
|
{% if request.user.profile.is_pro %}
|
||||||
|
|
||||||
window.user_is_pro = true;
|
window.user_is_pro = true;
|
||||||
window.default_editor = '{{ request.user.profile.get_default_editor_display|lower }}';
|
window.default_editor = '{{ request.user.profile.get_default_editor_display|lower }}';
|
||||||
window.editor_theme = '{{ request.user.profile.editor_theme }}';
|
window.editor_theme = '{{ request.user.profile.editor_theme }}';
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
window.user_is_pro = false;
|
window.user_is_pro = false;
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
1
urls.py
1
urls.py
|
@ -23,6 +23,7 @@ private_api.register(PrivateSniptResource())
|
||||||
private_api.register(PrivateTagResource())
|
private_api.register(PrivateTagResource())
|
||||||
private_api.register(PrivateUserResource())
|
private_api.register(PrivateUserResource())
|
||||||
private_api.register(PrivateFavoriteResource())
|
private_api.register(PrivateFavoriteResource())
|
||||||
|
private_api.register(PrivateUserProfileResource())
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue