Skip to content

Commit

Permalink
Add non-public contribution types
Browse files Browse the repository at this point in the history
  • Loading branch information
mic4ael committed Nov 21, 2017
1 parent 47d06cb commit 796dc97
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -24,6 +24,8 @@ Improvements

- Allow specifying a default session for a track which will then be
used by default when accepting an abstract in that track (:issue:`3069`)
- Allow marking contribution types as private so they cannot be selected
by users submitting an abstract (:issue:`3138`)

Internal Changes
^^^^^^^^^^^^^^^^
Expand Down
@@ -0,0 +1,29 @@
"""Add is_private column to contribution types table
Revision ID: 566d5de4e0e5
Revises: 1d512a9ebb30
Create Date: 2017-11-01 11:49:47.532339
"""

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '566d5de4e0e5'
down_revision = '1d512a9ebb30'
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
'contribution_types',
sa.Column('is_private', sa.Boolean(), nullable=False, server_default='false'),
schema='events'
)
op.alter_column('contribution_types', 'is_private', server_default=None, schema='events')


def downgrade():
op.drop_column('contribution_types', 'is_private', schema='events')
2 changes: 1 addition & 1 deletion indico/modules/events/abstracts/controllers/abstract.py
Expand Up @@ -52,7 +52,7 @@ def _process(self):
abstract_form_class = make_abstract_form(self.event, management=self.management)
custom_field_values = {'custom_{}'.format(x.contribution_field_id): x.data for x in self.abstract.field_values}
defaults = FormDefaults(self.abstract, attachments=self.abstract.files, **custom_field_values)
form = abstract_form_class(obj=defaults, abstract=self.abstract, event=self.event)
form = abstract_form_class(obj=defaults, abstract=self.abstract, event=self.event, management=self.management)
if form.validate_on_submit():
update_abstract(self.abstract, *get_field_values(form.data))
flash(_("Abstract modified successfully"), 'success')
Expand Down
Expand Up @@ -117,7 +117,7 @@ def _process(self):
class RHCreateAbstract(RHAbstractListBase):
def _process(self):
abstract_form_class = make_abstract_form(self.event, notification_option=True, management=self.management)
form = abstract_form_class(event=self.event)
form = abstract_form_class(event=self.event, management=self.management)
if form.validate_on_submit():
data = form.data
send_notifications = data.pop('send_notifications')
Expand Down
2 changes: 1 addition & 1 deletion indico/modules/events/abstracts/controllers/display.py
Expand Up @@ -69,7 +69,7 @@ def _check_access(self):

def _process(self):
abstract_form_class = make_abstract_form(self.event, management=self.management)
form = abstract_form_class(event=self.event)
form = abstract_form_class(event=self.event, management=self.management)
if form.validate_on_submit():
abstract = create_abstract(self.event, *get_field_values(form.data), send_notifications=True)
flash(_("Your abstract '{}' has been successfully submitted. It is registered with the number "
Expand Down
9 changes: 8 additions & 1 deletion indico/modules/events/abstracts/forms.py
Expand Up @@ -467,14 +467,21 @@ class AbstractForm(IndicoForm):
def __init__(self, *args, **kwargs):
self.event = kwargs.pop('event')
self.abstract = kwargs.pop('abstract', None)
management = kwargs.pop('management', False)
description_settings = abstracts_settings.get(self.event, 'description_settings')
description_validators = self._get_description_validators(description_settings)
if description_validators:
inject_validators(self, 'description', description_validators)
if abstracts_settings.get(self.event, 'contrib_type_required'):
inject_validators(self, 'submitted_contrib_type', [DataRequired()])
super(AbstractForm, self).__init__(*args, **kwargs)
self.submitted_contrib_type.query = self.event.contribution_types
if management:
self.submitted_contrib_type.query = self.event.contribution_types
else:
criteria = [~ContributionType.is_private]
if self.abstract and self.abstract.submitted_contrib_type:
criteria.append(ContributionType.id == self.abstract.submitted_contrib_type.id)
self.submitted_contrib_type.query = self.event.contribution_types.filter(db.or_(*criteria))
if not self.submitted_contrib_type.query.count():
del self.submitted_contrib_type
if not self.event.cfa.allow_attachments:
Expand Down
6 changes: 5 additions & 1 deletion indico/modules/events/contributions/forms.py
Expand Up @@ -19,7 +19,7 @@
from datetime import timedelta

from wtforms.ext.sqlalchemy.fields import QuerySelectField
from wtforms.fields import StringField, TextAreaField
from wtforms.fields import BooleanField, StringField, TextAreaField
from wtforms.validators import DataRequired, ValidationError

from indico.core.db import db
Expand All @@ -36,6 +36,7 @@
from indico.web.forms.fields import (AccessControlListField, IndicoDateTimeField, IndicoLocationField,
IndicoProtectionField, IndicoTagListField, PrincipalListField, TimeDeltaField)
from indico.web.forms.validators import DateTimeRange, MaxDuration, UsedIf
from indico.web.forms.widgets import SwitchWidget


class ContributionForm(IndicoForm):
Expand Down Expand Up @@ -187,6 +188,9 @@ class ContributionTypeForm(IndicoForm):
"""Form to create or edit a ContributionType"""

name = StringField(_("Name"), [DataRequired()])
is_private = BooleanField(_("Private"), widget=SwitchWidget(),
description=_("If selected, this contribution type cannot be chosen by users "
"submitting an abstract."))
description = TextAreaField(_("Description"))

def __init__(self, *args, **kwargs):
Expand Down
5 changes: 5 additions & 0 deletions indico/modules/events/contributions/models/types.py
Expand Up @@ -51,6 +51,11 @@ def __table_args__(cls):
nullable=False,
default=''
)
is_private = db.Column(
db.Boolean,
nullable=False,
default=False
)

event = db.relationship(
'Event',
Expand Down
Expand Up @@ -2,6 +2,7 @@
<tr class="i-table">
<td class="i-table name-column">{{ contrib_type.name }}</td>
<td class="i-table">{{ contrib_type.description }}</td>
<td class="i-table">{{ _('Yes') if contrib_type.is_private else _('No') }}</td>
<td class="i-table action-column hide-if-locked">
<a class="js-edit-contribution-type icon-edit"
data-ajax-dialog
Expand Down
Expand Up @@ -20,6 +20,9 @@
<th class="i-table">
{% trans %}Description{% endtrans %}
</th>
<th class="i-table">
{% trans %}Private{% endtrans %}
</th>
<th class="i-table action-column hide-if-locked"></th>
</tr>
</thead>
Expand Down

0 comments on commit 796dc97

Please sign in to comment.