예제 #1
0
    def validate_english(self, field):
        custom_field = CustomField.query.filter(
            CustomField.slug == slugify(field.data),
            CustomField.meeting == None,
            CustomField.custom_field_type == self.custom_field_type).first()

        if custom_field and self.obj != custom_field.label:
            raise ValidationError(self.duplicate_message)
def generate_slug(mapper, connection, target):
    if target.slug:
        return
    slug = slugify(target.label.english)
    if slug in dir(Participant):
        rand = ''.join(random.choice(string.ascii_letters) for i in range(4))
        slug += '_%s' % rand
    target.slug = slug
예제 #3
0
    def validate_english(self, field):
        custom_field = CustomField.query.filter(
            CustomField.slug == slugify(field.data),
            CustomField.meeting == None,
            CustomField.custom_field_type == self.custom_field_type).first()

        if custom_field and self.obj != custom_field.label:
            raise ValidationError(self.duplicate_message)
예제 #4
0
 def _create_slug(self):
     if self.slug:
         return self.slug
     slug = slugify(self.label.english)
     if slug in dir(Participant):
         rand = ''.join(random.choice(string.ascii_letters)
                        for i in range(4))
         slug += '_%s' % rand
     return slug
예제 #5
0
def test_distribution_of_documents_printout(app, user):
    category_default = MeetingCategoryFactory(title__english='Default')
    meeting = category_default.meeting
    category_observer = MeetingCategoryFactory(meeting=meeting,
                                               title__english='Observer')
    category_staff = MeetingCategoryFactory(meeting=meeting,
                                            title__english='Staff')
    categories = [category_default, category_observer, category_staff]

    for lang in ['English', 'French', 'Spanish']:
        ParticipantFactory.create_batch(5,
                                        meeting=meeting,
                                        category=category_default,
                                        language=unicode(lang))
        ParticipantFactory.create_batch(5,
                                        meeting=meeting,
                                        category=category_default,
                                        language=unicode(lang),
                                        represented_region=u'Africa')
        ParticipantFactory.create_batch(5,
                                        meeting=meeting,
                                        category=category_staff,
                                        language=unicode(lang))
        ParticipantFactory.create_batch(5,
                                        meeting=meeting,
                                        category=category_staff,
                                        language=unicode(lang),
                                        represented_region=u'Africa')
        ParticipantFactory.create_batch(5,
                                        meeting=meeting,
                                        category=category_observer,
                                        language=unicode(lang))
        ParticipantFactory.create_batch(5,
                                        meeting=meeting,
                                        category=category_observer,
                                        language=unicode(lang),
                                        represented_region=u'Africa')

    client = app.test_client()

    with app.test_request_context():
        with client.session_transaction() as sess:
            sess['user_id'] = user.id

        resp = client.get(
            url_for('meetings.printouts_document_distribution',
                    meeting_id=meeting.id))
        assert resp.status_code == 200
        html = PyQuery(resp.data)

        # Test each part
        for lang in ['english', 'french', 'spanish']:
            assert len(html('#english-container tbody tr')) == 9

            representings = [
                x.attrib['data-id'] for x in html(
                    '#english-container tbody tr td#representing-name')
            ]
            assert representings.count('africa') is 3
            assert representings.count('asia') is 3

            category_ids = [
                x.attrib['data-id']
                for x in html('#%s-container tbody tr th#category-name' % lang)
            ]
            # Test that categories order on the page respects categories
            # alphabetical order
            assert slugify(categories[0].title.english) == category_ids[0] and \
                slugify(categories[1].title.english) == category_ids[1] and \
                slugify(categories[2].title.english) == category_ids[2]
            for category in categories:
                assert slugify(category.title.english) in category_ids

            assert len(category_ids) is len(categories)
예제 #6
0
def sync_cites_meetings(ctx):
    app = ctx.obj['app']
    cites_meetings_urls = {
        'english': 'https://cites.org/ws/meetings-mrt',
        'french': 'https://cites.org/fra/ws/meetings-mrt',
        'spanish': 'https://cites.org/esp/ws/meetings-mrt',
    }

    retrieved_meetings = defaultdict(dict)
    headers = {'Accept': 'application/json'}

    for language in cites_meetings_urls:
        response = requests.get(cites_meetings_urls[language], headers=headers)
        response.raise_for_status()

        for meeting in response.json():
            unique_id = meeting.get('id', '')
            meeting_dict = retrieved_meetings[unique_id]

            meeting_dict['{}_title'.format(language)] = meeting.get(
                'title', '')
            meeting_dict['{}_city'.format(language)] = meeting.get('city', '')
            meeting_dict['description'] = meeting.get('description', '')
            meeting_dict['meeting_type'] = meeting.get('type', '')
            meeting_dict['start'] = meeting.get('start', '')
            meeting_dict['end'] = meeting.get('end', '')
            meeting_dict['location'] = meeting.get('location', '')
            meeting_dict['country'] = meeting.get('country', '')
            meeting_dict['country_code2'] = meeting.get('country_code2', '')
            meeting_dict['country_code3'] = meeting.get('country_code3', '')
            meeting_dict['meeting_number'] = meeting.get('meeting_number', '')
            meeting_dict['link'] = meeting.get('link', '')
            meeting_dict['acronym'] = meeting_dict[
                'meeting_type'] + meeting_dict['meeting_number']

    with app.test_request_context():
        for meeting in retrieved_meetings:
            meeting_dict = retrieved_meetings[meeting]

            if Meeting.query.filter_by(
                    acronym=meeting_dict['acronym']).count():
                # Meeting already exists
                continue
            else:
                curr_meeting_type = MeetingType.query.filter_by(
                    label=meeting_dict['meeting_type']).first()
                if not curr_meeting_type:
                    curr_meeting_type = MeetingType(
                        label=meeting_dict['meeting_type'],
                        slug=slugify(meeting_dict['meeting_type']))
                    db.session.add(curr_meeting_type)

                date_start = datetime.strptime(
                    re.sub(re.compile('<.*?>'), '', meeting_dict['start']),
                    '%d/%m/%Y')
                date_end = datetime.strptime(
                    re.sub(re.compile('<.*?>'), '', meeting_dict['end']),
                    '%d/%m/%Y')

                curr_meeting = Meeting(acronym=meeting_dict['acronym'],
                                       date_start=date_start,
                                       date_end=date_end)
                curr_meeting.meeting_type = curr_meeting_type
                curr_meeting.venue_country = meeting_dict['country_code2']
                curr_meeting.venue_city = Translation(
                    english=meeting_dict['english_city'],
                    french=meeting_dict['french_city'],
                    spanish=meeting_dict['spanish_city'])
                curr_meeting.title = Translation(
                    english=meeting_dict['english_title'],
                    french=meeting_dict['french_title'],
                    spanish=meeting_dict['spanish_title'])
                db.session.add(curr_meeting)
        db.session.commit()