<commit_before>from pyramid_layout.panel import panel_config

from deform import Form, ValidationFailure

import logging
logger = logging.getLogger(__name__)


class ProfilePanel(object):
    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.userid = request.matchdict.get('userid')
        self.collection = self.request.db.users

    def appstruct(self):
        appstruct = self.collection.find_one({'identifier': self.userid})
        if appstruct is None:
            appstruct = dict()
        return appstruct


class AccountPanel(ProfilePanel):
    def process_form(self, form):
        try:
            controls = self.request.POST.items()
            appstruct = form.validate(controls)
            user = self.collection.find_one({'identifier': self.userid})
            for key in ['name', 'email', 'organisation', 'notes']:
                user[key] = appstruct.get(key)
            self.collection.update({'identifier': self.userid}, user)
        except ValidationFailure, e:
            logger.exception('validation of form failed.')
            return dict(form=e.render())
        except Exception, e:
            logger.exception('update user failed.')
            self.request.session.flash('Update of your account failed. %s' % (e), queue='danger')
        else:
            self.request.session.flash("Your account was updated.", queue='success')

    @panel_config(name='profile_account', renderer='phoenix:templates/panels/form.pt')
    def panel(self):
        from .schema import AccountSchema
        form = Form(schema=AccountSchema(), buttons=('update',), formid='deform')
        if 'update' in self.request.POST:
            self.process_form(form)
        return dict(title="Account settings", form=form.render(self.appstruct()))


class TwitcherPanel(ProfilePanel):
    @panel_config(name='profile_twitcher', renderer='templates/people/panels/profile_twitcher.pt')
    def panel(self):
        from .schema import TwitcherSchema
        form = Form(schema=TwitcherSchema(), formid='deform')
        return dict(title="Twitcher access token", form=form.render(self.appstruct()))


class ESGFPanel(ProfilePanel):
    @panel_config(name='profile_esgf', renderer='templates/people/panels/profile_esgf.pt')
    def panel(self):
        from .schema import ESGFCredentialsSchema
        form = Form(schema=ESGFCredentialsSchema(), formid='deform')
        return dict(title="ESGF access token", form=form.render(self.appstruct()))

<commit_msg>using big button<commit_after>from pyramid_layout.panel import panel_config

from deform import Form, ValidationFailure, Button

import logging
logger = logging.getLogger(__name__)


class ProfilePanel(object):
    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.userid = request.matchdict.get('userid')
        self.collection = self.request.db.users

    def appstruct(self):
        appstruct = self.collection.find_one({'identifier': self.userid})
        if appstruct is None:
            appstruct = dict()
        return appstruct


class AccountPanel(ProfilePanel):
    def process_form(self, form):
        try:
            controls = self.request.POST.items()
            appstruct = form.validate(controls)
            user = self.collection.find_one({'identifier': self.userid})
            for key in ['name', 'email', 'organisation', 'notes']:
                user[key] = appstruct.get(key)
            self.collection.update({'identifier': self.userid}, user)
        except ValidationFailure, e:
            logger.exception('validation of form failed.')
            return dict(form=e.render())
        except Exception, e:
            logger.exception('update user failed.')
            self.request.session.flash('Update of your account failed. %s' % (e), queue='danger')
        else:
            self.request.session.flash("Your account was updated.", queue='success')

    @panel_config(name='profile_account', renderer='phoenix:templates/panels/form.pt')
    def panel(self):
        from .schema import AccountSchema
        btn = Button(name='update', title='Update Profile', css_class="btn btn-success btn-lg btn-block")
        form = Form(schema=AccountSchema(), buttons=(btn,), formid='deform')
        if 'update' in self.request.POST:
            self.process_form(form)
        return dict(title="Account settings", form=form.render(self.appstruct()))


class TwitcherPanel(ProfilePanel):
    @panel_config(name='profile_twitcher', renderer='templates/people/panels/profile_twitcher.pt')
    def panel(self):
        from .schema import TwitcherSchema
        form = Form(schema=TwitcherSchema(), formid='deform')
        return dict(title="Twitcher access token", form=form.render(self.appstruct()))


class ESGFPanel(ProfilePanel):
    @panel_config(name='profile_esgf', renderer='templates/people/panels/profile_esgf.pt')
    def panel(self):
        from .schema import ESGFCredentialsSchema
        form = Form(schema=ESGFCredentialsSchema(), formid='deform')
        return dict(title="ESGF access token", form=form.render(self.appstruct()))


{'fraction_non_alphanumeric': 0.12162162162162163, 'fraction_numerical': 0.0, 'mean_word_length': 3.205357142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6578871', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1412, 'n_words': 313}