Merge branch 'master' of github.com:samuelclay/NewsBlur

* 'master' of github.com:samuelclay/NewsBlur:
  Adding my very special mongo serialization backup utility to get around the damn unrepairable mongo database. This is taking 14 hours to run.
  Auto-refreshing feedback (1 min for staff, 10 min for everybody).
  Adding Nokia MeeGo client to user agents.
  Only show raw feeds in feed autocomplete.
This commit is contained in:
Samuel Clay 2011-12-18 21:25:04 -08:00
commit 2a3226259a
14 changed files with 92 additions and 19 deletions

View file

@ -41,13 +41,17 @@ def load_single_feed(request, feed_id):
@json.json_view
def feed_autocomplete(request):
query = request.GET['term']
query = request.GET.get('term')
if not query:
return dict(code=-1, message="Specify a search 'term'.")
feeds = []
for field in ['feed_address', 'feed_link', 'feed_title']:
if not feeds:
feeds = Feed.objects.filter(**{
'%s__icontains' % field: query,
'num_subscribers__gt': 1,
'branch_from_feed__isnull': True,
}).exclude(
Q(**{'%s__icontains' % field: 'token'}) |
Q(**{'%s__icontains' % field: 'private'})

View file

@ -12,4 +12,8 @@ def render_statistics_graphs(statistics):
def format_graph(n, max_value, height=30):
if n == 0 or max_value == 0:
return 1
return max(1, height * (n/float(max_value)))
return max(1, height * (n/float(max_value)))
@register.inclusion_tag('statistics/render_feedback_table.xhtml')
def render_feedback_table(feedbacks):
return dict(feedbacks=feedbacks)

View file

@ -3,4 +3,5 @@ from apps.statistics import views
urlpatterns = patterns('',
url(r'^dashboard_graphs', views.dashboard_graphs, name='statistics-graphs'),
url(r'^feedback_table', views.feedback_table, name='feedback-table'),
)

View file

@ -1,9 +1,15 @@
from django.template import RequestContext
from django.shortcuts import render_to_response
from apps.statistics.models import MStatistics
from apps.statistics.models import MStatistics, MFeedback
def dashboard_graphs(request):
statistics = MStatistics.all()
return render_to_response('statistics/render_statistics_graphs.xhtml', {
'statistics': statistics,
}, context_instance=RequestContext(request))
def feedback_table(request):
feedbacks = MFeedback.all()
return render_to_response('statistics/render_feedback_table.xhtml', {
'feedbacks': feedbacks,
}, context_instance=RequestContext(request))

6
fabfile.py vendored
View file

@ -153,11 +153,13 @@ def compress_media():
def backup_mongo():
with cd(os.path.join(env.NEWSBLUR_PATH, 'utils/backups')):
run('./mongo_backup.sh')
# run('./mongo_backup.sh')
run('python backup_mongo.py')
def backup_postgresql():
with cd(os.path.join(env.NEWSBLUR_PATH, 'utils/backups')):
run('./postgresql_backup.sh')
# run('./postgresql_backup.sh')
run('python backup_psql.py')
# ===============
# = Calibration =

View file

@ -792,6 +792,10 @@ NEWSBLUR.AssetModel.Reader.prototype = {
this.make_request('/statistics/dashboard_graphs', {}, callback, error_callback, {request_type: 'GET'});
},
load_feedback_table: function(callback, error_callback) {
this.make_request('/statistics/feedback_table', {}, callback, error_callback, {request_type: 'GET'});
},
save_feed_order: function(folders, callback) {
this.make_request('/reader/save_feed_order', {'folders': $.toJSON(folders)}, callback);
},

View file

@ -104,6 +104,7 @@
this.apply_tipsy_titles();
this.load_recommended_feeds();
this.setup_dashboard_graphs();
this.setup_feedback_table();
this.setup_howitworks_hovers();
this.load_url_next_param();
};
@ -5761,10 +5762,10 @@
clearInterval(this.locks.load_dashboard_graphs);
this.locks.load_dashboard_graphs = setInterval(_.bind(function() {
this.load_dashboard_graphs();
}, this), 10*60*1000);
}, this), NEWSBLUR.Globals.is_staff ? 60*1000 : 10*60*1000);
},
load_dashboard_graphs: function(direction, refresh) {
load_dashboard_graphs: function() {
var self = this;
var $module = $('.NB-module-stats');
$module.addClass('NB-loading');
@ -5777,6 +5778,28 @@
}, $.noop);
},
setup_feedback_table: function() {
// Reload feedback module every 10 minutes.
clearInterval(this.locks.load_feedback_table);
this.locks.load_feedback_table = setInterval(_.bind(function() {
this.load_feedback_table();
}, this), NEWSBLUR.Globals.is_staff ? 60*1000 : 10*60*1000);
},
load_feedback_table: function() {
var self = this;
var $module = $('.NB-feedback-table');
$module.addClass('NB-loading');
this.model.load_feedback_table(function(resp) {
if (!resp) return;
$module.removeClass('NB-loading');
$module.replaceWith(resp);
self.load_javascript_elements_on_page();
}, $.noop);
},
// ==========
// = Events =
// ==========

View file

@ -12,6 +12,7 @@
'is_authenticated' : {{ user.is_authenticated|yesno:"true,false" }},
'is_anonymous' : {{ user.is_anonymous|yesno:"true,false" }},
'is_premium' : {{ user.profile.is_premium|yesno:"true,false" }},
'is_staff' : {{ user.profile.is_staff|yesno:"true,false" }},
'secret_token' : "{{ user.profile.secret_token }}",
'username' : "{{ user.username|safe }}",
'email' : "{{ user.email|safe }}",

View file

@ -66,17 +66,7 @@ $(document).ready(function() {
Community Feedback
</h3>
<table class="" cellpadding="0" cellspacing="0">
{% for feedback in feedbacks %}
<tr class="NB-module-feature {% if forloop.last %}last{% endif %}">
<td class="NB-module-feature-date">{{ feedback.date }}</td>
<td class="NB-module-feature-description">
<span class="NB-module-feature-tag NB-tag-{{ feedback.style }}">{{ feedback.style }}</span>
<a href="{{ feedback.url }}">{{ feedback.subject|typogrify }}</a>
</td>
</tr>
{% endfor %}
</table>
{% render_feedback_table feedbacks %}
</div>

View file

@ -0,0 +1,13 @@
{% load utils_tags typogrify_tags %}
<table class="NB-feedback-table" cellpadding="0" cellspacing="0">
{% for feedback in feedbacks %}
<tr class="NB-module-feature {% if forloop.last %}last{% endif %}">
<td class="NB-module-feature-date">{{ feedback.date }}</td>
<td class="NB-module-feature-description">
<span class="NB-module-feature-tag NB-tag-{{ feedback.style }}">{{ feedback.style }}</span>
<a href="{{ feedback.url }}">{{ feedback.subject|typogrify }}</a>
</td>
</tr>
{% endfor %}
</table>

View file

@ -2,7 +2,7 @@ import os
import sys
import shutil
CURRENT_DIR = os.path.dirname(__file__)
CURRENT_DIR = os.path.dirname(os.getcwd())
NEWSBLUR_DIR = ''.join([CURRENT_DIR, '/../../'])
sys.path.insert(0, NEWSBLUR_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

View file

@ -0,0 +1,23 @@
# Use this script to copy the contents of MongoDB from one server
# to another using only pymongo. This circumvents the mongod --repair
# option, which can fucking fail.
import sys
import pymongo
db01 = pymongo.Connection('db01:27018')
db02 = pymongo.Connection('db02:27018')
story_feed_id = 5799
total = db01.newsblur.stories.count()
stories = db01.newsblur.stories.find({'story_feed_id': {'$gte': story_feed_id}}, sort=[('story_feed_id', pymongo.ASCENDING), ('story_date', pymongo.DESCENDING)])
i = 0
for story in stories:
if story.get('story_feed_id', 0) != story_feed_id:
story_feed_id = story['story_feed_id']
print " ---> Inserted %s stories (%s%%)" % (
i, round(i/float(total), 2)
)
print " ---> At feed_id: %s" % story_feed_id
sys.stdout.flush()
db02.newsblur.stories.insert(story)
i += 1

View file

@ -26,6 +26,8 @@ def user(u, msg):
platform = 'Chrome'
elif 'Safari' in user_agent:
platform = 'Safari'
elif 'MeeGo' in user_agent:
platform = 'MeeGo'
elif 'Firefox' in user_agent:
platform = 'FF'
elif 'Opera' in user_agent: