Adding never expire button to admin dialog. Also adding training counts.

This commit is contained in:
Samuel Clay 2015-06-04 11:27:46 -07:00
parent 54db8505cb
commit e0b4c1fc64
5 changed files with 59 additions and 4 deletions

View file

@ -19,6 +19,7 @@ urlpatterns = patterns('',
url(r'^payment_history/?', views.payment_history, name='profile-payment-history'),
url(r'^cancel_premium/?', views.cancel_premium, name='profile-cancel-premium'),
url(r'^refund_premium/?', views.refund_premium, name='profile-refund-premium'),
url(r'^never_expire_premium/?', views.never_expire_premium, name='profile-never-expire-premium'),
url(r'^upgrade_premium/?', views.upgrade_premium, name='profile-upgrade-premium'),
url(r'^update_payment_history/?', views.update_payment_history, name='profile-update-payment-history'),
url(r'^delete_account/?', views.delete_account, name='profile-delete-account'),

View file

@ -23,6 +23,7 @@ from apps.profile.forms import RedeemCodeForm
from apps.reader.forms import SignupForm, LoginForm
from apps.rss_feeds.models import MStarredStory, MStarredStoryCounts
from apps.social.models import MSocialServices, MActivity, MSocialProfile
from apps.analyzer.models import MClassifierTitle, MClassifierAuthor, MClassifierFeed, MClassifierTag
from utils import json_functions as json
from utils.user_functions import ajax_login_required
from utils.view_functions import render_to
@ -407,6 +408,7 @@ def payment_history(request):
history = PaymentHistory.objects.filter(user=user)
statistics = {
"created_date": user.date_joined,
"last_seen_date": user.profile.last_seen_on,
"timezone": unicode(user.profile.timezone),
"stripe_id": user.profile.stripe_id,
@ -415,6 +417,12 @@ def payment_history(request):
"email": user.email,
"read_story_count": RUserStory.read_story_count(user.pk),
"feed_opens": UserSubscription.objects.filter(user=user).aggregate(sum=Sum('feed_opens'))['sum'],
"training": {
'title': MClassifierTitle.objects.filter(user_id=user.pk).count(),
'tag': MClassifierTag.objects.filter(user_id=user.pk).count(),
'author': MClassifierAuthor.objects.filter(user_id=user.pk).count(),
'feed': MClassifierFeed.objects.filter(user_id=user.pk).count(),
}
}
return {
@ -459,6 +467,19 @@ def upgrade_premium(request):
return {'code': 1 if upgraded else -1}
@staff_member_required
@ajax_login_required
@json.json_view
def never_expire_premium(request):
user_id = request.REQUEST.get('user_id')
user = User.objects.get(pk=user_id)
if user.profile.is_premium:
user.profile.premium_expire = None
user.profile.save()
return {'code': 1}
return {'code': -1}
@staff_member_required
@ajax_login_required
@json.json_view

View file

@ -7698,6 +7698,12 @@ form.opml_import_form input {
word-wrap: break-word;
overflow: hidden;
}
.NB-modal-admin .NB-admin-training-counts span {
padding-right: 8px;
}
.NB-modal-admin .NB-admin-training-counts span.NB-grey {
color: #D0D0D0;
}
/* ===================== */
/* = Email Story Modal = */

View file

@ -1641,6 +1641,10 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
this.make_request('/profile/refund_premium', data, callback, error_callback);
},
never_expire_premium: function(data, callback, error_callback) {
this.make_request('/profile/never_expire_premium', data, callback, error_callback);
},
delete_saved_stories: function(timestamp, callback, error_callback) {
var self = this;
var pre_callback = function(data) {

View file

@ -1,5 +1,7 @@
NEWSBLUR.ReaderUserAdmin = function(options) {
var defaults = {};
var defaults = {
width: 700
};
this.options = $.extend({}, defaults, options);
this.model = NEWSBLUR.assets;
@ -78,6 +80,7 @@ _.extend(NEWSBLUR.ReaderUserAdmin.prototype, {
]));
$actions.append($.make('div', { className: "NB-modal-submit-button NB-modal-submit-green NB-admin-action-refund", style: "float: left" }, "Full Refund"));
$actions.append($.make('div', { className: "NB-modal-submit-button NB-modal-submit-green NB-admin-action-refund-partial", style: "float: left" }, "Refund $12"));
$actions.append($.make('div', { className: "NB-modal-submit-button NB-modal-submit-green NB-admin-action-never-expire", style: "float: left" }, "Never expire"));
} else {
$actions.append($.make('div', { className: "NB-modal-submit-button NB-modal-submit-green NB-admin-action-upgrade" }, "Upgrade to premium"));
}
@ -86,20 +89,29 @@ _.extend(NEWSBLUR.ReaderUserAdmin.prototype, {
$actions.append($.make('div', { className: "NB-modal-submit-button NB-modal-submit-green NB-admin-action-opml", style: "float: left" }, "OPML"));
$statistics.append($.make('dl', [
$.make('dt', 'Stripe Id:'),
$.make('dd', $.make('a', { href: "https://manage.stripe.com/customers/" + data.statistics.stripe_id, className: 'NB-splash-link' }, data.statistics.stripe_id)),
$.make('dt', 'Created:'),
$.make('dd', data.statistics.created_date),
$.make('dt', 'Last seen:'),
$.make('dd', data.statistics.last_seen_date),
$.make('dt', 'Timezone:'),
$.make('dd', data.statistics.timezone),
$.make('dt', 'Email:'),
$.make('dd', data.statistics.email),
$.make('dt', 'Stripe Id:'),
$.make('dd', $.make('a', { href: "https://manage.stripe.com/customers/" + data.statistics.stripe_id, className: 'NB-splash-link' }, data.statistics.stripe_id)),
$.make('dt', 'Feeds:'),
$.make('dd', Inflector.commas(data.statistics.feeds)),
$.make('dt', 'Feed opens:'),
$.make('dd', Inflector.commas(data.statistics.feed_opens)),
$.make('dt', 'Read Stories:'),
$.make('dd', Inflector.commas(data.statistics.read_story_count))
$.make('dd', Inflector.commas(data.statistics.read_story_count)),
$.make('dt', 'Training:'),
$.make('dd', { className: 'NB-admin-training-counts' }, [
$.make('span', { className: data.statistics.training.title ? '' : 'NB-grey' }, 'Title: ' + data.statistics.training.title),
$.make('span', { className: data.statistics.training.author ? '' : 'NB-grey' }, 'Author: ' + data.statistics.training.author),
$.make('span', { className: data.statistics.training.tag ? '' : 'NB-grey' }, 'Tag: ' + data.statistics.training.tag),
$.make('span', { className: data.statistics.training.feed ? '' : 'NB-grey' }, 'Feed: ' + data.statistics.training.feed)
])
]));
$(window).resize();
}, this));
@ -135,6 +147,17 @@ _.extend(NEWSBLUR.ReaderUserAdmin.prototype, {
$(".NB-admin-action-refund").replaceWith($.make('div', 'Error: ' + JSON.stringify(data)));
});
});
$.targetIs(e, { tagSelector: '.NB-admin-action-never-expire' }, function($t, $p) {
e.preventDefault();
NEWSBLUR.assets.never_expire_premium({
'user_id': self.user.get('user_id')
}, function(data) {
self.fetch_payment_history();
}, function(data) {
$(".NB-admin-action-never-expire").replaceWith($.make('div', 'Error: ' + JSON.stringify(data)));
});
});
$.targetIs(e, { tagSelector: '.NB-admin-action-upgrade' }, function($t, $p) {
e.preventDefault();