def contribs_choosen(): """Lists all contributions in the JSON format""" contribs = {} for key in THEMES.keys(): contribs[key] = {'name': THEMES[key], 'children': []} count = 11 if key == 'familia' else 10 for data in wordpress.pairwise.getSortedByScore(0, count, key)[0]: cid = loads(data['data'])['id'] # This is _nasty_. The team that carried about organizing # contribution approved something wrong. Yes, now we have # invalid data on our db. This was the better way I figured # out to fix it right now, but obviously something better # must be done when we have more time. if cid == 1213: continue contrib = Contrib.get(cid) final = _format_contrib(contrib) final['author'] = contrib.user.name final['score'] = data['score'] final['votes'] = { 'score': data['score'], 'total': data['votes'], 'won': data['won'], 'lost': data['lost'], } final['children'] = [] for subcontrib in contrib.children: subfinal = _format_contrib(subcontrib) subfinal['author'] = subcontrib.user.name final['children'].append(subfinal) for subcontrib in Contrib.query.filter_by(parent=contrib.id): subfinal = _format_contrib(subcontrib) subfinal['author'] = subcontrib.user.name final['children'].append(subfinal) contribs[key]['children'].append(final) return dumps(contribs)
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from gd.model import Contrib, session erros = 0 bugados = [] for i in range(1, 1000): try: contrib = Contrib.get(i) if contrib is not None: print contrib.id contrib.title = contrib.title.decode('utf-8') contrib.content = contrib.content.decode('utf-8') session.commit() except Exception, exc: session.rollback() erros += 1 bugados.append({'id': i, 'exception': exc}) print( 'Foram encontrados %d erros, provavelmente esses objetos ' 'já são unicode') % (erros) print 'Seguem os erros: %s' % (', '.join([str(x['id']) for x in bugados]))
# (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from gd.model import Contrib, session erros = 0 bugados = [] for i in range(1, 1000): try: contrib = Contrib.get(i) if contrib is not None: print contrib.id contrib.title = contrib.title.decode('utf-8') contrib.content = contrib.content.decode('utf-8') session.commit() except Exception, exc: session.rollback() erros += 1 bugados.append({ 'id': i, 'exception': exc }) print ('Foram encontrados %d erros, provavelmente esses objetos ' 'já são unicode') % (erros) print 'Seguem os erros: %s' % (', '.join([str(x['id']) for x in bugados]))