def _save_categories(self, meeting):
     for category_default in meeting.meeting_type.default_categories:
         category = copy_attributes(Category(), category_default)
         category.title = copy_attributes(Translation(),
                                          category_default.title)
         category.meeting = meeting
         db.session.add(category)
         db.session.flush()
 def _save_categories(self, meeting):
     for category_default in meeting.meeting_type.default_categories:
         category = copy_attributes(Category(), category_default)
         category.title = copy_attributes(Translation(),
                                          category_default.title)
         category.tags = category_default.tags
         category.meeting = meeting
         db.session.add(category)
         db.session.flush()
 def _clone_categories(self, meeting, categories):
     for category in categories:
         with db.session.no_autoflush:
             clone = copy_attributes(Category(), category)
             clone.tags = category.tags
             clone.title = copy_attributes(Translation(), category.title)
             clone.meeting = meeting
             db.session.add(clone)
             db.session.flush()
 def _clone_relation(self, meeting, children, translation_attrs=[],
                     exclude_fk=True):
     for child in children:
         clone = copy_attributes(child.__class__(), child,
                                 exclude_fk=exclude_fk)
         for attr in translation_attrs:
             setattr(clone, attr,
                     copy_attributes(Translation(), getattr(child, attr)))
         clone.meeting = meeting
         db.session.add(clone)
         db.session.flush()
 def _clone_relation(self, meeting, children, translation_attrs=[],
                     exclude_fk=True):
     for child in children:
         clone = copy_attributes(child.__class__(), child,
                                 exclude_fk=exclude_fk)
         for attr in translation_attrs:
             setattr(clone, attr,
                     copy_attributes(Translation(), getattr(child, attr)))
         clone.meeting = meeting
         db.session.add(clone)
         db.session.flush()
Beispiel #6
0
 def _save_phrases(self, meeting):
     phrases_default = (PhraseDefault.query.filter_by(
         meeting_type_slug=meeting.meeting_type_slug))
     for phrase_default in phrases_default:
         phrase = copy_attributes(Phrase(), phrase_default)
         phrase.description = (
             copy_attributes(Translation(), phrase_default.description)
             if phrase_default.description else Translation(english=''))
         phrase.meeting = meeting
         db.session.add(phrase)
         db.session.flush()
 def _save_phrases(self, meeting):
     phrases_default = (
         PhraseDefault.query
         .filter_by(meeting_type_slug=meeting.meeting_type_slug)
     )
     for phrase_default in phrases_default:
         phrase = copy_attributes(Phrase(), phrase_default)
         phrase.description = (
             copy_attributes(Translation(), phrase_default.description)
             if phrase_default.description else Translation(english=''))
         phrase.meeting = meeting
         db.session.add(phrase)
         db.session.flush()
def copy_missing_phrases(default_phrases, migrated_meeting):
    last_sort = max([x.sort for x in migrated_meeting.phrases.all()])
    for phrase in default_phrases:
        if not migrated_meeting.phrases.filter_by(name=phrase.name,
                                                  group=phrase.group).first():
            new_phrase = copy_attributes(models.Phrase(), phrase)
            new_phrase.description = (copy_attributes(
                models.Translation(), phrase.description) if phrase.description
                                      else models.Translation(english=''))
            new_phrase.meeting = migrated_meeting
            new_phrase.sort = last_sort + 1
            db.session.add(new_phrase)
            last_sort += 1
    db.session.commit()
def copy_missing_phrases(default_phrases, migrated_meeting):
    last_sort = max([x.sort for x in migrated_meeting.phrases.all()])
    for phrase in default_phrases:
        if not migrated_meeting.phrases.filter_by(name=phrase.name,
                                                  group=phrase.group).first():
            new_phrase = copy_attributes(models.Phrase(), phrase)
            new_phrase.description = (
                copy_attributes(models.Translation(), phrase.description)
                if phrase.description else models.Translation(english=''))
            new_phrase.meeting = migrated_meeting
            new_phrase.sort = last_sort + 1
            db.session.add(new_phrase)
            last_sort += 1
    db.session.commit()
Beispiel #10
0
    def _save_custom_field(self, meeting):
        add_custom_fields_for_meeting(meeting, form_class=ParticipantDummyForm)
        query = (CustomField.query.filter_by(meeting=meeting).with_entities(
            CustomField.sort).order_by(desc(CustomField.sort)).first())
        last_sort = query[0] + 1

        # Copy default custom fields for meeting type
        for field_default in meeting.meeting_type.default_fields:
            field = copy_attributes(CustomField(), field_default)
            field.label = copy_attributes(Translation(), field_default.label)
            field.sort = last_sort
            last_sort += 1
            field.meeting = meeting
            db.session.add(field)
        db.session.flush()
    def _clone_custom_fields(self, meeting, custom_fields,
                             translation_attrs=[]):
        for custom_field in custom_fields:
            clone = copy_attributes(custom_field.__class__(), custom_field)
            for attr in translation_attrs:
                setattr(clone, attr, copy_attributes(Translation(),
                        getattr(custom_field, attr)))
            clone.meeting = meeting
            db.session.add(clone)

            for choice in custom_field.choices:
                choice_clone = CustomFieldChoice(custom_field=clone)
                setattr(choice_clone, 'value', copy_attributes(Translation(),
                        getattr(choice, 'value')))
                db.session.add(choice_clone)

            db.session.flush()
    def _save_custom_field(self, meeting):
        add_custom_fields_for_meeting(meeting, form_class=ParticipantDummyForm)
        query = (
            CustomField.query.filter_by(meeting=meeting)
            .with_entities(CustomField.sort)
            .order_by(desc(CustomField.sort))
            .first())
        last_sort = query[0] + 1

        # Copy default custom fields for meeting type
        for field_default in meeting.meeting_type.default_fields:
            field = copy_attributes(CustomField(), field_default)
            field.label = copy_attributes(Translation(), field_default.label)
            field.sort = last_sort
            last_sort += 1
            field.meeting = meeting
            db.session.add(field)
        db.session.flush()
 def update(self, source):
     self.default_meeting = Meeting.get_default()
     participant = copy_attributes(self, source, exclude_fk=False,
                                   exclude=self.EXCLUDE_WHEN_COPYING)
     for cfv in source.custom_field_values.all():
         cf_clone = self._clone_custom_field(cfv.custom_field)
         db.session.flush()
         self._clone_custom_field_value(participant, cf_clone, cfv)
     return participant
 def update(self, source):
     self.default_meeting = Meeting.get_default()
     participant = copy_attributes(self, source, exclude_fk=False,
                                   exclude=self.EXCLUDE_WHEN_COPYING)
     for cfv in source.custom_field_values.all():
         cf_clone = self._clone_custom_field(cfv.custom_field)
         db.session.flush()
         self._clone_custom_field_value(participant, cf_clone, cfv)
     return participant
 def _clone_custom_field_value(self, participant, custom_field_clone,
                               custom_field_value):
     cfv = (CustomFieldValue.query.filter_by(
         custom_field=custom_field_clone).filter_by(
             participant=participant).scalar())
     if cfv:
         if custom_field_clone.field_type == CustomField.IMAGE:
             unlink_participant_custom_file(cfv.value)
         cfv = copy_attributes(cfv, custom_field_value)
     else:
         cfv = copy_attributes(CustomFieldValue(), custom_field_value)
         cfv.custom_field_id = custom_field_clone.id
         cfv.participant_id = participant.id
         db.session.add(cfv)
     if custom_field_clone.field_type == CustomField.IMAGE:
         filename = duplicate_uploaded_file(custom_field_value.value,
                                            'custom')
         cfv.value = filename.basename()
     return cfv
 def _clone_custom_field(self, custom_field):
     cf = (CustomField.query.filter_by(
         meeting=self.default_meeting).filter_by(
             slug=custom_field.slug).scalar())
     if not cf:
         cf = copy_attributes(CustomField(), custom_field)
         cf.label = Translation(english=custom_field.label.english)
         cf.meeting = self.default_meeting
         db.session.add(cf)
     return cf
 def _clone_custom_field(self, custom_field):
     cf = (CustomField.query
           .filter_by(meeting=self.default_meeting)
           .filter_by(slug=custom_field.slug)
           .scalar())
     if not cf:
         cf = copy_attributes(CustomField(), custom_field)
         cf.label = Translation(english=custom_field.label.english)
         cf.meeting = self.default_meeting
         db.session.add(cf)
     return cf
Beispiel #18
0
 def _clone_custom_field(self, custom_field):
     cf = (CustomField.query.filter_by(
         meeting_id=self.default_meeting.id).filter_by(
             slug=custom_field.slug).filter_by(
                 custom_field_type=CustomField.PARTICIPANT).first())
     if not cf:
         cf = copy_attributes(CustomField(), custom_field)
         cf.label = Translation(english=custom_field.label.english)
         cf.meeting = self.default_meeting
         db.session.add(cf)
     return cf
 def _clone_custom_field_value(self, participant, custom_field_clone,
                               custom_field_value):
     cfv = (CustomFieldValue.query
            .filter_by(custom_field=custom_field_clone)
            .filter_by(participant=participant)
            .scalar())
     if cfv:
         if custom_field_clone.field_type == CustomField.IMAGE:
             unlink_participant_custom_file(cfv.value)
         cfv = copy_attributes(cfv, custom_field_value)
     else:
         cfv = copy_attributes(CustomFieldValue(), custom_field_value)
         cfv.custom_field_id = custom_field_clone.id
         cfv.participant_id = participant.id
         db.session.add(cfv)
     if custom_field_clone.field_type == CustomField.IMAGE:
         filename = duplicate_uploaded_file(custom_field_value.value,
                                            'custom')
         cfv.value = filename.basename()
     return cfv
    def _clone_custom_fields(self, meeting, custom_fields,
                             translation_attrs=[]):
        for custom_field in custom_fields:

            clone = copy_attributes(custom_field.__class__(), custom_field)
            for attr in translation_attrs:
                setattr(clone, attr, copy_attributes(Translation(),
                                                     getattr(custom_field, attr)))
            clone.meeting = meeting
            db.session.add(clone)

            for choice in custom_field.choices:
                if choice.value.english == 'Nomenclature specialist':
                    continue
                choice_clone = CustomFieldChoice(custom_field=clone)
                setattr(choice_clone, 'value', copy_attributes(Translation(),
                                                               getattr(choice, 'value')))
                db.session.add(choice_clone)

            db.session.flush()
Beispiel #21
0
    def _clone_rules(self, meeting, rules):
        for rule in rules:
            rule_clone = copy_attributes(rule.__class__(),
                                         rule,
                                         exclude_fk=True)
            rule_clone.meeting = meeting
            db.session.add(rule_clone)

            for condition in rule.conditions.all():
                condition_clone = Condition()
                condition_type = condition.field.custom_field_type
                condition_label = condition.field.label.english
                field = meeting.custom_fields.filter(
                    CustomField.label.has(english=condition_label),
                    CustomField.custom_field_type == condition_type).one()
                condition_clone.field = field
                condition_clone.rule = rule_clone
                db.session.add(condition_clone)

                for condition_value in condition.values.all():
                    condition_value_clone = ConditionValue()
                    condition_value_clone.condition = condition_clone
                    value = condition_value.value
                    if condition.field.field_type == CustomField.CATEGORY:
                        title = Category.query.get(int(value)).title.english
                        value = meeting.categories.filter(
                            Category.title.has(english=title)).scalar().id
                    condition_value_clone.value = value
                    db.session.add(condition_value_clone)

            for action in rule.actions.all():
                action_clone = copy_attributes(action.__class__(),
                                               action,
                                               exclude_fk=True)
                action_clone.rule = rule_clone
                field = meeting.custom_fields.filter_by(
                    slug=action.field.slug).one()
                action_clone.field = field
                db.session.add(action_clone)

            db.session.flush()
    def _clone_rules(self, meeting, rules):
        for rule in rules:
            rule_clone = copy_attributes(rule.__class__(), rule,
                                         exclude_fk=True)
            rule_clone.meeting = meeting
            db.session.add(rule_clone)

            for condition in rule.conditions.all():
                condition_clone = Condition()
                condition_type = condition.field.custom_field_type
                condition_label = condition.field.label.english
                field = meeting.custom_fields.filter(
                    CustomField.label.has(english=condition_label),
                    CustomField.custom_field_type == condition_type).one()
                condition_clone.field = field
                condition_clone.rule = rule_clone
                db.session.add(condition_clone)

                for condition_value in condition.values.all():
                    condition_value_clone = ConditionValue()
                    condition_value_clone.condition = condition_clone
                    value = condition_value.value
                    if condition.field.field_type == CustomField.CATEGORY:
                        title = Category.query.get(int(value)).title.english
                        value = meeting.categories.filter(
                            Category.title.has(english=title)).scalar().id
                    condition_value_clone.value = value
                    db.session.add(condition_value_clone)

            for action in rule.actions.all():
                action_clone = copy_attributes(action.__class__(), action,
                                               exclude_fk=True)
                action_clone.rule = rule_clone
                field = meeting.custom_fields.filter_by(
                    slug=action.field.slug).one()
                action_clone.field = field
                db.session.add(action_clone)

            db.session.flush()
 def save(self):
     categories_default = CategoryDefault.query.filter(
         CategoryDefault.id.in_(self.categories.data))
     for category_default in categories_default:
         category = copy_attributes(Category(), category_default,
                                    exclude=('background', ))
         translation = Translation(english=category_default.title.english)
         db.session.add(translation)
         db.session.flush()
         category.title = translation
         category.meeting = g.meeting
         filename = duplicate_uploaded_file(category_default.background,
                                            'backgrounds')
         if filename:
             category.background = filename.basename()
         db.session.add(category)
     db.session.commit()
Beispiel #24
0
 def save(self):
     categories_default = CategoryDefault.query.filter(
         CategoryDefault.id.in_(self.categories.data))
     for category_default in categories_default:
         category = copy_attributes(Category(),
                                    category_default,
                                    exclude=('background', ))
         translation = Translation(english=category_default.title.english)
         db.session.add(translation)
         db.session.flush()
         category.title = translation
         category.tags = category_default.tags
         category.meeting = g.meeting
         filename = duplicate_uploaded_file(category_default.background,
                                            'backgrounds')
         if filename:
             category.background = filename.basename()
         db.session.add(category)
     db.session.commit()
    def clone(self):
        self.default_meeting = Meeting.get_default()
        participant = copy_attributes(
            Participant(), self, exclude_fk=False,
            exclude=self.EXCLUDE_WHEN_COPYING)
        participant.meeting = self.default_meeting
        participant.participant_type = {
            Participant.PARTICIPANT: Participant.DEFAULT,
            Participant.MEDIA: Participant.DEFAULT_MEDIA,
        }.get(self.participant_type.code, Participant.DEFAULT)
        db.session.add(participant)
        db.session.flush()
        # add primary custom fields for default meeting
        self._add_primary_custom_fields_for_default_meeting()

        for cfv in self.custom_field_values.all():
            cf_clone = self._clone_custom_field(cfv.custom_field)
            db.session.flush()
            self._clone_custom_field_value(participant, cf_clone, cfv)
        return participant
    def clone(self):
        self.default_meeting = Meeting.get_default()
        participant = copy_attributes(
            Participant(), self, exclude_fk=False,
            exclude=self.EXCLUDE_WHEN_COPYING)
        participant.meeting = self.default_meeting
        participant.participant_type = {
            Participant.PARTICIPANT: Participant.DEFAULT,
            Participant.MEDIA: Participant.DEFAULT_MEDIA,
        }.get(self.participant_type.code, Participant.DEFAULT)
        db.session.add(participant)
        db.session.flush()
        # add primary custom fields for default meeting
        self._add_primary_custom_fields_for_default_meeting()

        for cfv in self.custom_field_values.all():
            cf_clone = self._clone_custom_field(cfv.custom_field)
            db.session.flush()
            self._clone_custom_field_value(participant, cf_clone, cfv)
        return participant
def migrate_category(category_and_category_meeting, migrated_meeting):
    category, category_meeting = category_and_category_meeting
    try:
        migrated_category = models.Category.query.filter(
            models.Category.title.has(english=category.data['name_E']),
            models.Category.meeting == migrated_meeting,
        ).one()
        return migrated_category
    except NoResultFound:
        pass

    migrated_category = models.Category()
    title = models.Translation(english=category.data['name_E'],
                               french=category.data['name_F'],
                               spanish=category.data['name_S'])
    db.session.add(title)
    db.session.flush()
    migrated_category.title = title

    color = COLORS.get(category.data['badge_color'], DEFAULT_COLOR)
    migrated_category.color = color

    representing = REPRESENTING_TEMPLATES.get(category.data['templates_list'])
    if representing:
        migrated_category.representing = representing

    if category.data['stat'] == 'Media':
        category_type = models.Category.MEDIA
    else:
        category_type = models.Category.PARTICIPANT

    migrated_category.category_type = category_type

    form_type = category_meeting.form_type
    if form_type == 'media':
        migrated_category.group = models.Category.ORGANIZATION
    else:
        migrated_category.group = models.Category.COUNTRY

    try:
        sort = int(category.data['form_sort'])
    except (TypeError, ValueError):
        sort = None
    migrated_category.sort = sort

    if form_type:
        migrated_category.visible_on_registration_form = True
    else:
        migrated_category.visible_on_registration_form = False

    migrated_category.meeting = migrated_meeting

    db.session.add(migrated_category)

    try:
        models.CategoryDefault.query.filter(
            models.CategoryDefault.title.has(english=category.data['name_E'])
        ).one()
    except NoResultFound:
        migrated_category_default = copy_attributes(models.CategoryDefault(),
                                                    migrated_category)
        title = models.Translation(english=category.data['name_E'],
                                   french=category.data['name_F'],
                                   spanish=category.data['name_S'])
        db.session.add(title)
        db.session.flush()
        migrated_category_default.title = title
        db.session.add(migrated_category_default)

    db.session.commit()
    return migrated_category
def migrate_category(category_and_category_meeting, migrated_meeting):
    category, category_meeting = category_and_category_meeting
    try:
        migrated_category = models.Category.query.filter(
            models.Category.title.has(english=category.data['name_E']),
            models.Category.meeting == migrated_meeting,
        ).one()
        return migrated_category
    except NoResultFound:
        pass

    migrated_category = models.Category()
    title = models.Translation(english=category.data['name_E'],
                               french=category.data['name_F'],
                               spanish=category.data['name_S'])
    db.session.add(title)
    db.session.flush()
    migrated_category.title = title

    color = COLORS.get(category.data['badge_color'], DEFAULT_COLOR)
    migrated_category.color = color

    representing = REPRESENTING_TEMPLATES.get(category.data['templates_list'])
    if representing:
        migrated_category.representing = representing

    if category.data['stat'] == 'Media':
        category_type = models.Category.MEDIA
    else:
        category_type = models.Category.PARTICIPANT

    migrated_category.category_type = category_type

    form_type = category_meeting.form_type
    if form_type == 'media':
        migrated_category.group = models.Category.ORGANIZATION
    else:
        migrated_category.group = models.Category.COUNTRY

    try:
        sort = int(category.data['form_sort'])
    except (TypeError, ValueError):
        sort = None
    migrated_category.sort = sort

    if form_type:
        migrated_category.visible_on_registration_form = True
    else:
        migrated_category.visible_on_registration_form = False

    migrated_category.meeting = migrated_meeting

    db.session.add(migrated_category)

    try:
        models.CategoryDefault.query.filter(
            models.CategoryDefault.title.has(
                english=category.data['name_E'])).one()
    except NoResultFound:
        migrated_category_default = copy_attributes(models.CategoryDefault(),
                                                    migrated_category)
        title = models.Translation(english=category.data['name_E'],
                                   french=category.data['name_F'],
                                   spanish=category.data['name_S'])
        db.session.add(title)
        db.session.flush()
        migrated_category_default.title = title
        db.session.add(migrated_category_default)

    db.session.commit()
    return migrated_category