Пример #1
0
def contrib_json():
    """Receives a user contribution and saves to the database

    This function will return a JSON format with the result of the
    operation. That can be successful or an error, if it finds any
    problem in data received or the lack of the authentication.
    """
    if not auth.is_authenticated():
        return msg.error(_(u'User not authenticated'))

    raise Exception('Not funny')

    form = ContribForm(csrf_enabled=False)
    if form.validate_on_submit():
        Contrib(title=form.data['title'].encode('utf-8'),
                content=form.data['content'].encode('utf-8'),
                theme=form.data['theme'],
                user=auth.authenticated_user())
        session.commit()

        # Returning the csrf
        data = {'data': _('Contribution received successful')}
        data.update({'csrf': form.csrf.data})
        return msg.ok(data)
    else:
        return format_csrf_error(form, form.errors, 'ValidationError')
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
#
# 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]))
Пример #5
0
# (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]))