Add new field in Registration General settings

I have added a new field in the Registration General Settings area but the field data is not entered in the database.
The field that I created is related to the “Registration fee” (DB field name: base_price) and is named “Registration fee info” (DB field name: base_price_info, data type: text ).
After the modifications I made, I restarted the celery and apache.

I am able to see the new field on the Registration General setting HTML page, but when I enter a value the database is not updated and I get an error when a new registration is created (see below).

I know that I am doing something wrong but I do not know how to move forward.
I would appreciate your help.

This field along with one more field that I added in Billable form (which works fine) are needed so that I can have an itemized cart for PayPal that includes budget information for our financial team.

The following is what I did to add the new field:

  • Manually I added the new field in the following database tables:
    Schema: event_registration
    Tables: forms, registrations

  • Then added the field in the following files:

    • ./modules/events/registration/models/registrations.py
      added base_price_info field:
class Registration(db.Model):
    # ...
    #: PENELOPE - base_price_info  base registration fee info
    base_price_info = db.Column(
        db.String,
        nullable=True
    )
  • ./modules/events/registration/forms.py
    Add base_price_info in the _price_fields = ('currency', 'base_price', 'base_price_info')
class RegistrationFormForm(IndicoForm):
    _price_fields = ('currency', 'base_price', 'base_price_info')
  • ./modules/events/registration/util.py
def create_registration(regform, data, invitation=None, management=False, notify_user=True, skip_moderation=None):
    user = session.user if session else None
    registration = Registration(registration_form=regform, user=get_user_by_email(data['email']),
                                base_price=regform.base_price, currency=regform.currency, base_price_info=regform.base_price_info)
  • ./modules/events/registration/templates/display/_registration_summary_blocks.html
                    {% if registration.base_price %}
                        <tr class="regform-done-table-item">
                            <td class="text-left">
                                {% trans %}Registration fee{% endtrans %}
                            </td>
                            <td></td>
                            <td class="text-right">
                                {{ registration.render_base_price() }}
                                <br>
                                {{ registration.base_price_info }}
                
                            </td>
                        </tr>

New registration error message in indico.log:

Traceback (most recent call last):
  File "/opt/indico/.venv/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/indico/.venv/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/indico/.venv/lib/python2.7/site-packages/indico/web/flask/util.py", line 114, in wrapper
    return obj().process()
  File "/opt/indico/.venv/lib/python2.7/site-packages/indico/web/rh.py", line 289, in process
    res = self._do_process()
  File "/opt/indico/.venv/lib/python2.7/site-packages/indico/web/rh.py", line 259, in _do_process
    rv = self._process()
  File "/opt/indico/.venv/lib/python2.7/site-packages/indico/modules/events/registration/controllers/management/reglists.py", line 283, in _process
    create_registration(self.regform, data, management=True, notify_user=notify_user)
  File "/opt/indico/.venv/lib/python2.7/site-packages/indico/core/db/sqlalchemy/util/session.py", line 29, in wrapper
    return fn(*args, **kwargs)
  File "/opt/indico/.venv/lib/python2.7/site-packages/indico/modules/events/registration/util.py", line 218, in create_registration
    base_price=regform.base_price, currency=regform.currency, base_price_info=regform.base_price_info)
AttributeError: 'RegistrationForm' object has no attribute 'base_price_info'

You only added the new column to Registration but not to RegistrationForm.

Actually, you only need it in RegistrationForm unless you want to save the current message when someone registers (we do this with the base price so changes to it do not affect existing registrations).

Adrian Mönnich response:

you only added the new column to Registration but not to

RegistrationForm.

Actually, you only need it in RegistrationForm unless you want to save 
the current message when someone registers (we do this with the base 
price so changes to it do not affect existing registrations).

My question to this response is:
I do needed it in the registration data of a person too, so this should be fine.
My question is: Where is the RegistrationForm located? I could not find any other files that I had to added the new field information except the ones I listed above.

Thank you
Penelope

It’s in indico/modules/events/registration/models/forms.py

BTW, you should not modify the database manually! Edit your models and then run this command to generate an alembic revision:

indico db migrate -m 'Add base_price_info column'

You can then apply it to the database using indico db upgrade and revert using indico db downgrade.

I have already added the field in this file as follows:

#: PENELOPE - The base registration fee information
base_price_info = db.Column(
    db.String, 
    nullable=True
)

The problem should be that I added the field manually and did not use the commands as I did not know about them.
I will remove the manually added field and then then added using the commands you provided.

Thank you
Penelope

THANK YOU!

After deleted the manually added fields and run the commands:

indico db migrate -m ‘Add base_price_info column’
indico db upgrade

Everything is working!

I’ll let you know as soon as the PayPal plugin that itemizes the cart is working. Could this piece of code be added to indico? I believe that other people might find it useful

Feel free to send a pull request against master containing your changes!

1 Like

Great! I will do so when everything is working as it should.

In order to support cart itemization in the PayPal plugin, I changed that following files:

./indico/modules/events/registration/fields/base.py
./indico/modules/events/registration/models/registrations.py
./indico/modules/events/registration/models/forms.py
./indico/modules/events/registration/forms.py
./indico/modules/events/registration/util.py
./indico/htdocs/js/indico/modules/registration/form/field.js
./indico/htdocs/js/indico/modules/registration/form/tpls/fields/dialogs/billable.tpl.html
./indico_payment_paypal/templates/event_payment_form.html
./indico_payment_paypal/plugin.py

The indico file changes are due to the addition of an extra field in the registration tables (named base_price_info) that provides information for the item_number_n PayPal field.

Would that be OK to send a pull request against the master?

1 Like