mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Adding delete saved stories older than date feature in Account dialog.
This commit is contained in:
parent
6d69401887
commit
c69de89d36
6 changed files with 115 additions and 1 deletions
|
@ -22,6 +22,7 @@ urlpatterns = patterns('',
|
||||||
url(r'^delete_account/?', views.delete_account, name='profile-delete-account'),
|
url(r'^delete_account/?', views.delete_account, name='profile-delete-account'),
|
||||||
url(r'^forgot_password_return/?', views.forgot_password_return, name='profile-forgot-password-return'),
|
url(r'^forgot_password_return/?', views.forgot_password_return, name='profile-forgot-password-return'),
|
||||||
url(r'^forgot_password/?', views.forgot_password, name='profile-forgot-password'),
|
url(r'^forgot_password/?', views.forgot_password, name='profile-forgot-password'),
|
||||||
|
url(r'^delete_starred_stories/?', views.delete_starred_stories, name='profile-delete-starred-stories'),
|
||||||
url(r'^delete_all_sites/?', views.delete_all_sites, name='profile-delete-all-sites'),
|
url(r'^delete_all_sites/?', views.delete_all_sites, name='profile-delete-all-sites'),
|
||||||
url(r'^email_optout/?', views.email_optout, name='profile-email-optout'),
|
url(r'^email_optout/?', views.email_optout, name='profile-email-optout'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,6 +20,7 @@ from apps.reader.models import UserSubscription, UserSubscriptionFolders, RUserS
|
||||||
from apps.profile.forms import StripePlusPaymentForm, PLANS, DeleteAccountForm
|
from apps.profile.forms import StripePlusPaymentForm, PLANS, DeleteAccountForm
|
||||||
from apps.profile.forms import ForgotPasswordForm, ForgotPasswordReturnForm, AccountSettingsForm
|
from apps.profile.forms import ForgotPasswordForm, ForgotPasswordReturnForm, AccountSettingsForm
|
||||||
from apps.reader.forms import SignupForm, LoginForm
|
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.social.models import MSocialServices, MActivity, MSocialProfile
|
||||||
from utils import json_functions as json
|
from utils import json_functions as json
|
||||||
from utils.user_functions import ajax_login_required
|
from utils.user_functions import ajax_login_required
|
||||||
|
@ -479,6 +480,29 @@ def forgot_password_return(request):
|
||||||
'forgot_password_return_form': form,
|
'forgot_password_return_form': form,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ajax_login_required
|
||||||
|
@json.json_view
|
||||||
|
def delete_starred_stories(request):
|
||||||
|
timestamp = request.POST.get('timestamp', None)
|
||||||
|
if timestamp:
|
||||||
|
delete_date = datetime.datetime.fromtimestamp(int(timestamp))
|
||||||
|
else:
|
||||||
|
delete_date = datetime.datetime.now()
|
||||||
|
starred_stories = MStarredStory.objects.filter(user_id=request.user.pk,
|
||||||
|
starred_date__lte=delete_date)
|
||||||
|
stories_deleted = starred_stories.count()
|
||||||
|
starred_stories.delete()
|
||||||
|
|
||||||
|
MStarredStoryCounts.count_for_user(request.user.pk, total_only=True)
|
||||||
|
starred_counts, starred_count = MStarredStoryCounts.user_counts(request.user.pk, include_total=True)
|
||||||
|
|
||||||
|
logging.user(request.user, "~BC~FRDeleting %s/%s starred stories (%s)" % (stories_deleted,
|
||||||
|
stories_deleted+starred_count, delete_date))
|
||||||
|
|
||||||
|
return dict(code=1, stories_deleted=stories_deleted, starred_counts=starred_counts,
|
||||||
|
starred_count=starred_count)
|
||||||
|
|
||||||
|
|
||||||
@ajax_login_required
|
@ajax_login_required
|
||||||
@json.json_view
|
@json.json_view
|
||||||
def delete_all_sites(request):
|
def delete_all_sites(request):
|
||||||
|
|
|
@ -9247,6 +9247,9 @@ form.opml_import_form input {
|
||||||
.NB-modal-account .NB-account-premium-cancel {
|
.NB-modal-account .NB-account-premium-cancel {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
.NB-modal-account .NB-preference-saved-stories-date {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
/* ================ */
|
/* ================ */
|
||||||
/* = Static Pages = */
|
/* = Static Pages = */
|
||||||
|
|
|
@ -1575,6 +1575,22 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
||||||
this.make_request('/profile/refund_premium', data, callback, error_callback);
|
this.make_request('/profile/refund_premium', data, callback, error_callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
delete_saved_stories: function(timestamp, callback, error_callback) {
|
||||||
|
var self = this;
|
||||||
|
var pre_callback = function(data) {
|
||||||
|
if (data.starred_counts) {
|
||||||
|
self.starred_feeds.reset(data.starred_counts, {parse: true});
|
||||||
|
}
|
||||||
|
self.starred_count = data.starred_count;
|
||||||
|
|
||||||
|
if (callback) callback(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.make_request('/profile/delete_starred_stories', {
|
||||||
|
timestamp: timestamp
|
||||||
|
}, pre_callback, error_callback);
|
||||||
|
},
|
||||||
|
|
||||||
delete_all_sites: function(callback, error_callback) {
|
delete_all_sites: function(callback, error_callback) {
|
||||||
this.make_request('/profile/delete_all_sites', {}, callback, error_callback);
|
this.make_request('/profile/delete_all_sites', {}, callback, error_callback);
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,6 +31,7 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
|
||||||
this.select_preferences();
|
this.select_preferences();
|
||||||
|
|
||||||
this.fetch_payment_history();
|
this.fetch_payment_history();
|
||||||
|
this.render_dates();
|
||||||
},
|
},
|
||||||
|
|
||||||
make_modal: function() {
|
make_modal: function() {
|
||||||
|
@ -99,13 +100,22 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
|
||||||
$.make('div', { className: 'NB-preference-sublabel' }, 'Download this XML file as a backup')
|
$.make('div', { className: 'NB-preference-sublabel' }, 'Download this XML file as a backup')
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
|
$.make('div', { className: 'NB-preference NB-preference-delete' }, [
|
||||||
|
$.make('div', { className: 'NB-preference-options' }, [
|
||||||
|
$.make('div', { className: 'NB-preference-saved-stories-date' }),
|
||||||
|
$.make('div', { className: 'NB-modal-submit-button NB-modal-submit-red NB-account-delete-saved-stories' }, 'Delete my saved stories')
|
||||||
|
]),
|
||||||
|
$.make('div', { className: 'NB-preference-label'}, [
|
||||||
|
'Erase your saved stories'
|
||||||
|
])
|
||||||
|
]),
|
||||||
$.make('div', { className: 'NB-preference NB-preference-delete' }, [
|
$.make('div', { className: 'NB-preference NB-preference-delete' }, [
|
||||||
$.make('div', { className: 'NB-preference-options' }, [
|
$.make('div', { className: 'NB-preference-options' }, [
|
||||||
$.make('div', { className: 'NB-modal-submit-button NB-modal-submit-red NB-account-delete-all-sites' }, 'Delete all of my sites')
|
$.make('div', { className: 'NB-modal-submit-button NB-modal-submit-red NB-account-delete-all-sites' }, 'Delete all of my sites')
|
||||||
]),
|
]),
|
||||||
$.make('div', { className: 'NB-preference-label'}, [
|
$.make('div', { className: 'NB-preference-label'}, [
|
||||||
'Erase yourself',
|
'Erase yourself',
|
||||||
$.make('div', { className: 'NB-preference-sublabel' }, 'Notice: You will be emailed a backup of your sites')
|
$.make('div', { className: 'NB-preference-sublabel' }, 'Friendly note: You will be emailed a backup of your sites')
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
$.make('div', { className: 'NB-preference NB-preference-delete' }, [
|
$.make('div', { className: 'NB-preference NB-preference-delete' }, [
|
||||||
|
@ -207,6 +217,41 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
render_dates: function() {
|
||||||
|
var now = new Date();
|
||||||
|
var this_year = now.getFullYear();
|
||||||
|
var this_month = now.getMonth();
|
||||||
|
var this_day = now.getDate();
|
||||||
|
|
||||||
|
var $dates = $(".NB-preference-saved-stories-date", this.$modal);
|
||||||
|
|
||||||
|
var $months = $.make('select', { name: 'month' });
|
||||||
|
_.each(NEWSBLUR.utils.monthNames, function(name, i) {
|
||||||
|
var $option = $.make('option', { value: i+"" }, name);
|
||||||
|
if (this_month == i) $option.attr('selected', 'selected');
|
||||||
|
$months.append($option);
|
||||||
|
});
|
||||||
|
|
||||||
|
var $days = $.make('select', { name: 'day' });
|
||||||
|
_.each(_.range(0, 31), function(name, i) {
|
||||||
|
var $option = $.make('option', { value: i+1+"" }, i+1);
|
||||||
|
if (this_day == i+1) $option.attr('selected', 'selected');
|
||||||
|
$days.append($option);
|
||||||
|
});
|
||||||
|
|
||||||
|
var $years = $.make('select', { name: 'year' });
|
||||||
|
_.each(_.range(2009, this_year+1), function(name, i) {
|
||||||
|
var $option = $.make('option', { value: name+"" }, name);
|
||||||
|
if (this_year == name) $option.attr('selected', 'selected');
|
||||||
|
$years.append($option);
|
||||||
|
});
|
||||||
|
|
||||||
|
$dates.append($.make('span', 'Older than: '));
|
||||||
|
$dates.append($months);
|
||||||
|
$dates.append($days);
|
||||||
|
$dates.append($years);
|
||||||
|
},
|
||||||
|
|
||||||
animate_fields: function() {
|
animate_fields: function() {
|
||||||
if (this.options.animate_email) {
|
if (this.options.animate_email) {
|
||||||
this.switch_tab('emails');
|
this.switch_tab('emails');
|
||||||
|
@ -293,6 +338,25 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
delete_saved_stories: function() {
|
||||||
|
var $link = $(".NB-account-delete-saved-stories", this.$modal);
|
||||||
|
var year = parseInt($("select[name=year]", this.$modal).val(), 10);
|
||||||
|
var month = parseInt($("select[name=month]", this.$modal).val(), 10);
|
||||||
|
var day = parseInt($("select[name=day]", this.$modal).val(), 10);
|
||||||
|
|
||||||
|
var timestamp = (new Date(year, month, day)).getTime() / 1000;
|
||||||
|
if (window.confirm("Positive you want to delete your saved stories?")) {
|
||||||
|
NEWSBLUR.assets.delete_saved_stories(timestamp, _.bind(function(data) {
|
||||||
|
NEWSBLUR.reader.update_starred_count();
|
||||||
|
$link.replaceWith($.make('div', Inflector.pluralize('story', data.stories_deleted, true) + ' ' + Inflector.pluralize('has', data.stories_deleted) +
|
||||||
|
' been deleted.'));
|
||||||
|
}, this), _.bind(function() {
|
||||||
|
NEWSBLUR.reader.update_starred_count();
|
||||||
|
$link.replaceWith($.make('div', { className: 'NB-error' }, 'There was a problem deleting your saved stories.')).show();
|
||||||
|
}, this));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
handle_cancel: function() {
|
handle_cancel: function() {
|
||||||
var $cancel = $('.NB-modal-cancel', this.$modal);
|
var $cancel = $('.NB-modal-cancel', this.$modal);
|
||||||
|
|
||||||
|
@ -415,6 +479,11 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
|
||||||
|
|
||||||
self.delete_all_sites();
|
self.delete_all_sites();
|
||||||
});
|
});
|
||||||
|
$.targetIs(e, { tagSelector: '.NB-account-delete-saved-stories' }, function($t, $p) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
self.delete_saved_stories();
|
||||||
|
});
|
||||||
$.targetIs(e, { tagSelector: '.NB-modal-cancel' }, function($t, $p) {
|
$.targetIs(e, { tagSelector: '.NB-modal-cancel' }, function($t, $p) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|
1
media/js/vendor/inflector.js
vendored
1
media/js/vendor/inflector.js
vendored
|
@ -88,6 +88,7 @@ window.Inflector = {
|
||||||
if (count != 1) {
|
if (count != 1) {
|
||||||
if (s == 'person') s = 'people';
|
if (s == 'person') s = 'people';
|
||||||
else if (s == 'is') s = 'are';
|
else if (s == 'is') s = 'are';
|
||||||
|
else if (s == 'has') s = 'have';
|
||||||
else if (s == 'following') s = s;
|
else if (s == 'following') s = s;
|
||||||
else if (s.match(/y$/i)) s = s.replace(/y$/i, 'ies');
|
else if (s.match(/y$/i)) s = s.replace(/y$/i, 'ies');
|
||||||
else s = s + 's';
|
else s = s + 's';
|
||||||
|
|
Loading…
Add table
Reference in a new issue