@login_required
def event_import(request):
    """Read tags from remote URL and return them as JSON.

    This is used to read tags from workshop website and then fill up fields
    on event_create form."""

    # TODO: remove POST support completely
    url = request.POST.get('url', '').strip()
    if not url:
        url = request.GET.get('url', '').strip()
    try:
        # fetch page
        response = requests.get(url)
        response.raise_for_status()  # assert it's 200 OK
        content = response.text

        # find tags
        tags = find_tags_on_event_website(content)

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

            # fetch page
            response = requests.get(index_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(content)

                if tags not in 'slug':
                    tags['slug'] = repository

        # normalize (parse) them
        tags = parse_tags_from_event_website(tags)

        return JsonResponse(tags)

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

    except requests.exceptions.RequestException:
        return HttpResponseBadRequest('Network connection error.')

    except WrongWorkshopURL as e:
        return HttpResponseBadRequest(str(e))

    except KeyError:
        return HttpResponseBadRequest('Missing or wrong "url" parameter.')
dataset/ETHPy150Open swcarpentry/amy/workshops/views.py/event_import/swapped operands of `not in`