@login_required
def validate_event(request, event_ident):
    '''Check the event's home page *or* the specified URL (for testing).'''
    try:
        event = Event.get_by_ident(event_ident)
    except Event.DoesNotExist:
        raise Http404('Event matching query does not exist.')

    page_url = request.GET.get('url', None)  # for manual override
    if page_url is None:
        page_url = event.url

    page_url = page_url.strip()

    error_messages = []

    try:
        # fetch page
        response = requests.get(page_url)
        response.raise_for_status()  # assert it's 200 OK
        content = response.text

        # find tags
        tags = find_tags_on_event_website(content)

        if tags not in 'slug':
            # there are no HTML tags, so let's try the old method
            page_url, _ = generate_url_to_event_index(page_url)

            # fetch page
            response = requests.get(page_url)

            if response.status_code == 200:
                # don't throw errors for pages we fall back to
                content = response.text
                tags = find_tags_on_event_index(page_url)

        # validate them
        error_messages = validate_tags_from_event_website(tags)

    except WrongWorkshopURL as e:
        error_messages.append(str(e))

    except requests.exceptions.HTTPError as e:
        error_messages.append(
            'Request for "{0}" returned status code {1}'
            .format(page_url, e.response.status_code)
        )

    except (requests.exceptions.ConnectionError,
            requests.exceptions.Timeout):
        error_messages.append("Network connection error.")

    context = {
        'title': 'Validate Event {0}'.format(event),
        'event': event,
        'page': page_url,
        'error_messages': error_messages,
    }
    return render(request, 'workshops/validate_event.html', context)
dataset/ETHPy150Open swcarpentry/amy/workshops/views.py/validate_event/swapped operands of `not in`