Пример #1
0
def home(request, guid, vsid=None, debug=None):
    now = datetime.now(tz=timezone.utc)
    if vsid is None:
        vsid = "0"
    guid = "{%s}" % uuid.UUID(guid)

    # Providing z=1 as a query parameter enables custom parameters
    enable_custom_queries = request.REQUEST.get("z") == "1"
    expired = False
    user_agent_vs = None
    redirect_url = None

    if debug:
        # On localhost ip will always be empty unless you've got a setup
        # that mirrors production
        debug_content = ["ip=%s" % request.META.get("HTTP_X_FORWARDED_FOR", ""), "GUID=%s" % guid]
        if enable_custom_queries:
            debug_content.append("CustomParameters=%s" % request.META.get("QUERY_STRING"))

    guid_redirect = helpers.get_redirect_or_404(guid=guid)
    cleaned_guid = helpers.clean_guid(guid_redirect.guid).upper()

    analytics = {
        "gu": cleaned_guid.lower(),
        "ve": "1.0",
        "vs": vsid,
        "ia": "uk",
        "ev": "rd",
        "cp": "uk",
        "tm": "r",
        "mo": 0,
        "ua": request.META.get("HTTP_USER_AGENT", ""),
        "ip": request.META.get("HTTP_X_REAL_IP", ""),
    }

    syndication_params = {"request": request, "redirect": guid_redirect, "guid": cleaned_guid, "view_source": vsid}

    original_url = guid_redirect.url

    if debug:
        debug_content.append("RetLink(original)=%s" % guid_redirect.url)
        syndication_params["debug_content"] = debug_content

    response = helpers.get_syndication_redirect(**syndication_params)

    if response is None:
        user_agent_vs, response = helpers.get_opengraph_redirect(request, guid_redirect, cleaned_guid)

    if response is None:
        if vsid == "1604":
            # msccn redirect

            company_name = guid_redirect.company_name
            company_name = helpers.quote_string(company_name)
            redirect_url = "http://us.jobs/msccn-referral.asp?gi=" "%s%s&cp=%s" % (cleaned_guid, vsid, company_name)
        else:
            args = {"request": request, "guid_redirect": guid_redirect, "vsid": vsid, "guid": cleaned_guid}
            if debug:
                args["debug_content"] = debug_content
            returned_dict = helpers.get_redirect_url(**args)
            redirect_url = returned_dict.get("redirect_url", "")
            facebook = returned_dict.get("facebook", False)
            expired = returned_dict.get("expired", False)
            browse_url = returned_dict.get("browse_url", "")
        if not redirect_url:
            redirect_url = guid_redirect.url
            params = {"request": request, "url": redirect_url, "exclude": True}
            if debug:
                debug_content.append("ManipulatedLink(No Manipulation)=%s" % redirect_url)
                params["debug_content"] = debug_content
            if enable_custom_queries:
                redirect_url = helpers.add_custom_queries(**params)
        redirect_url = helpers.get_hosted_state_url(guid_redirect, redirect_url)

        if debug:
            debug_content.append("RetLink=%s" % redirect_url)

        if expired:
            err = "&jcnlx.err=XIN"
            data = {"job": guid_redirect, "expired_url": original_url, "view_source": vsid}
            if guid_redirect.buid in [1228, 5480] or 2650 <= guid_redirect.buid <= 2703:
                if guid_redirect.buid in [1228, 5480]:
                    err = "&jcnlx.err=XJC"
                else:
                    err = "&jcnlx.err=XST"

            if vsid != "99":
                if browse_url:
                    data["browse_url"] = browse_url
                else:
                    data["browse_url"] = "http://www.my.jobs/%s/careers/" % text.slugify(guid_redirect.company_name)
                response = HttpResponseGone(render_to_string("redirect/expired.html", data))

        if response is None:
            response = HttpResponsePermanentRedirect(redirect_url)

        aguid = request.COOKIES.get("aguid") or uuid.uuid4().hex
        if "%" in aguid:
            aguid = uuid.UUID(unquote(aguid)).hex
        myguid = request.COOKIES.get("myguid", "")
        analytics.update({"aguid": aguid, "myguid": myguid})
        buid = helpers.get_Post_a_Job_buid(guid_redirect)
        qs = "jcnlx.ref=%s&jcnlx.url=%s&jcnlx.buid=%s&jcnlx.vsid=%s&jcnlx.aguid=%s&jcnlx.myguid=%s"
        qs %= (
            helpers.quote_string(request.META.get("HTTP_REFERER", "")),
            helpers.quote_string(redirect_url),
            buid,
            vsid,
            aguid,
            myguid,
        )
        if expired:
            d_seconds = (now - guid_redirect.expired_date).total_seconds()
            d_hours = int(d_seconds / 60 / 60)
            qs += "%s&jcnlx.xhr=%s" % (err, d_hours)

        response["X-REDIRECT"] = qs

        response = helpers.set_aguid_cookie(response, request.get_host(), aguid)

        if vsid == "99" or not expired:
            # If expired has a value, we're staying on the my.jobs domain and
            # showing an expired job page. If not, we're probably going
            # to an external site.
            parsed = urlparse(redirect_url)
            pn = parsed.path
            pr = parsed.scheme + ":"
            hn = parsed.netloc
            se = parsed.query
            if se:
                se = "?" + se
        else:
            hn = request.get_host()
            pr = "https:" if request.is_secure() else "http:"
            pn = request.path
            se = request.META.get("QUERY_STRING", "")
            if se:
                se = "?" + se

        # Python doesn't have a method of easily creating a timestamp with
        # Zulu at the end. Remove the timezone and append "Z".
        now_iso = now.replace(tzinfo=None).isoformat() + "Z"

        nv = request.COOKIES.get("de_nv") or now_iso
        response.set_cookie("de_nv", nv, expires=30 * 60, domain=request.get_host())
        referrer = request.META.get("HTTP_REFERER", "")
        analytics.update(
            {
                # Python tacks microseconds onto the end while JavaScript does
                # milliseconds. JS can handle parsing both, as can python-dateutil.
                "time": now_iso,
                "to": now_iso,
                "re": referrer,
                "pn": pn,
                "pr": pr,
                "hn": hn,
                "se": se,
                "nv": nv,
            }
        )

        response["X-JSON-Header"] = json.dumps(analytics)

    if debug and not user_agent_vs:
        data = {"debug_content": debug_content}
        response = render_to_response("redirect/debug.html", data, context_instance=RequestContext(request))

    return response
Пример #2
0
def home(request, guid, vsid=None, debug=None):
    if vsid is None:
        vsid = '0'
    guid = '{%s}' % uuid.UUID(guid)

    # Providing z=1 as a query parameter enables custom parameters
    enable_custom_queries = request.REQUEST.get('z') == '1'
    expired = False
    user_agent_vs = None

    if debug:
        # On localhost ip will always be empty unless you've got a setup
        # that mirrors production
        debug_content = ['ip=%s' % request.META.get('HTTP_X_FORWARDED_FOR', ''),
                         'GUID=%s' % guid]
        if enable_custom_queries:
            debug_content.append('CustomParameters=%s' %
                                 request.META.get('QUERY_STRING'))

    guid_redirect = helpers.get_redirect_or_404(guid=guid)
    cleaned_guid = helpers.clean_guid(guid_redirect.guid).upper()

    syndication_params = {'request': request, 'redirect': guid_redirect,
                          'guid': cleaned_guid, 'view_source': vsid}

    original_url = guid_redirect.url

    if debug:
        debug_content.append('RetLink(original)=%s' % guid_redirect.url)
        syndication_params['debug_content'] = debug_content

    response = helpers.get_syndication_redirect(**syndication_params)

    if response is None:
        user_agent_vs, response = helpers.get_opengraph_redirect(
            request, guid_redirect, cleaned_guid)

    if response is None:
        if vsid == '1604':
            # msccn redirect

            company_name = guid_redirect.company_name
            company_name = helpers.quote_string(company_name)
            redirect_url = ('http://us.jobs/msccn-referral.asp?gi='
                            '%s%s&cp=%s' %
                            (cleaned_guid,
                             vsid,
                             company_name))
        else:
            args = {'request': request, 'guid_redirect': guid_redirect,
                    'vsid': vsid, 'guid': cleaned_guid}
            if debug:
                args['debug_content'] = debug_content
            returned_dict = helpers.get_redirect_url(**args)
            redirect_url = returned_dict.get('redirect_url', '')
            facebook = returned_dict.get('facebook', False)
            expired = returned_dict.get('expired', False)
            browse_url = returned_dict.get('browse_url', '')
        if not redirect_url:
            redirect_url = guid_redirect.url
            params = {'request': request, 'url': redirect_url,
                      'exclude': True}
            if debug:
                debug_content.append(
                    'ManipulatedLink(No Manipulation)=%s' % redirect_url)
                params['debug_content'] = debug_content
            if enable_custom_queries:
                redirect_url = helpers.add_custom_queries(**params)
        redirect_url = helpers.get_hosted_state_url(guid_redirect,
                                                    redirect_url)

        if debug:
            debug_content.append('RetLink=%s' % redirect_url)

        if expired:
            err = '&jcnlx.err=XIN'
            data = {'job': guid_redirect,
                    'expired_url': original_url,
                    'view_source': vsid}
            if (guid_redirect.buid in [1228, 5480] or
                    2650 <= guid_redirect.buid <= 2703):
                if guid_redirect.buid in [1228, 5480]:
                    err = '&jcnlx.err=XJC'
                else:
                    err = '&jcnlx.err=XST'

            if browse_url:
                data['browse_url'] = browse_url
            else:
                data['browse_url'] = 'http://www.my.jobs/%s/careers/' % \
                    text.slugify(guid_redirect.company_name)
            response = HttpResponseGone(
                render_to_string('redirect/expired.html', data))
        else:
            response = HttpResponsePermanentRedirect(redirect_url)

        aguid = request.COOKIES.get('aguid') or \
            uuid.uuid4().hex
        if '%' in aguid:
            aguid = uuid.UUID(unquote(aguid)).hex
        myguid = request.COOKIES.get('myguid', '')
        buid = helpers.get_Post_a_Job_buid(guid_redirect)
        qs = 'jcnlx.ref=%s&jcnlx.url=%s&jcnlx.buid=%s&jcnlx.vsid=%s&jcnlx.aguid=%s&jcnlx.myguid=%s'
        qs %= (helpers.quote_string(request.META.get('HTTP_REFERER', '')),
               helpers.quote_string(redirect_url),
               buid,
               vsid,
               aguid,
               myguid)
        if expired:
            now = datetime.now(tz=timezone.utc)
            d_seconds = (now - guid_redirect.expired_date).total_seconds()
            d_hours = int(d_seconds / 60 / 60)
            qs += '%s&jcnlx.xhr=%s' % (err, d_hours)
        response['X-REDIRECT'] = qs

        response = helpers.set_aguid_cookie(response,
                                            request.get_host(),
                                            aguid)

    if debug and not user_agent_vs:
        data = {'debug_content': debug_content}
        return render_to_response('redirect/debug.html',
                                  data,
                                  context_instance=RequestContext(request))
    else:
        return response
Пример #3
0
def home(request, guid, vsid=None, debug=None):
    now = datetime.now(tz=timezone.utc)
    if vsid is None:
        vsid = '0'
    guid = '{%s}' % uuid.UUID(guid)

    # Providing z=1 as a query parameter enables custom parameters
    enable_custom_queries = request.REQUEST.get('z') == '1'
    expired = False
    user_agent_vs = None
    redirect_url = None

    if debug:
        # On localhost ip will always be empty unless you've got a setup
        # that mirrors production
        debug_content = [
            'ip=%s' % request.META.get('HTTP_X_FORWARDED_FOR', ''),
            'GUID=%s' % guid
        ]
        if enable_custom_queries:
            debug_content.append('CustomParameters=%s' %
                                 request.META.get('QUERY_STRING'))

    guid_redirect = helpers.get_redirect_or_404(guid=guid)
    cleaned_guid = helpers.clean_guid(guid_redirect.guid).upper()

    analytics = {
        'gu': cleaned_guid.lower(),
        've': '1.0',
        'vs': vsid,
        'ia': 'uk',
        'ev': 'rd',
        'cp': 'uk',
        'tm': 'r',
        'mo': 0,
        'ua': request.META.get('HTTP_USER_AGENT', ''),
        'ip': request.META.get('HTTP_X_REAL_IP', '')
    }

    syndication_params = {
        'request': request,
        'redirect': guid_redirect,
        'guid': cleaned_guid,
        'view_source': vsid
    }

    original_url = guid_redirect.url

    if debug:
        debug_content.append('RetLink(original)=%s' % guid_redirect.url)
        syndication_params['debug_content'] = debug_content

    response = helpers.get_syndication_redirect(**syndication_params)

    if response is None:
        user_agent_vs, response = helpers.get_opengraph_redirect(
            request, guid_redirect, cleaned_guid)

    if response is None:
        if vsid == '1604':
            # msccn redirect

            company_name = guid_redirect.company_name
            company_name = helpers.quote_string(company_name)
            redirect_url = ('http://us.jobs/msccn-referral.asp?gi='
                            '%s%s&cp=%s' % (cleaned_guid, vsid, company_name))
        else:
            args = {
                'request': request,
                'guid_redirect': guid_redirect,
                'vsid': vsid,
                'guid': cleaned_guid
            }
            if debug:
                args['debug_content'] = debug_content
            returned_dict = helpers.get_redirect_url(**args)
            redirect_url = returned_dict.get('redirect_url', '')
            facebook = returned_dict.get('facebook', False)
            expired = returned_dict.get('expired', False)
            browse_url = returned_dict.get('browse_url', '')
        if not redirect_url:
            redirect_url = guid_redirect.url
            params = {'request': request, 'url': redirect_url, 'exclude': True}
            if debug:
                debug_content.append('ManipulatedLink(No Manipulation)=%s' %
                                     redirect_url)
                params['debug_content'] = debug_content
            if enable_custom_queries:
                redirect_url = helpers.add_custom_queries(**params)
        redirect_url = helpers.get_hosted_state_url(guid_redirect,
                                                    redirect_url)

        if debug:
            debug_content.append('RetLink=%s' % redirect_url)

        if expired:
            err = '&jcnlx.err=XIN'
            data = {
                'job': guid_redirect,
                'expired_url': original_url,
                'view_source': vsid
            }
            if (guid_redirect.buid in [1228, 5480]
                    or 2650 <= guid_redirect.buid <= 2703):
                if guid_redirect.buid in [1228, 5480]:
                    err = '&jcnlx.err=XJC'
                else:
                    err = '&jcnlx.err=XST'

            if vsid != '99':
                if browse_url:
                    data['browse_url'] = browse_url
                else:
                    data['browse_url'] = 'http://www.my.jobs/%s/careers/' % \
                        text.slugify(guid_redirect.company_name)
                response = HttpResponseGone(
                    render_to_string('redirect/expired.html', data))

        if response is None:
            response = HttpResponsePermanentRedirect(redirect_url)

        aguid = request.COOKIES.get('aguid') or \
            uuid.uuid4().hex
        if '%' in aguid:
            aguid = uuid.UUID(unquote(aguid)).hex
        myguid = request.COOKIES.get('myguid', '')
        analytics.update({'aguid': aguid, 'myguid': myguid})
        buid = helpers.get_Post_a_Job_buid(guid_redirect)
        qs = 'jcnlx.ref=%s&jcnlx.url=%s&jcnlx.buid=%s&jcnlx.vsid=%s&jcnlx.aguid=%s&jcnlx.myguid=%s'
        qs %= (helpers.quote_string(request.META.get('HTTP_REFERER', '')),
               helpers.quote_string(redirect_url), buid, vsid, aguid, myguid)
        if expired:
            d_seconds = (now - guid_redirect.expired_date).total_seconds()
            d_hours = int(d_seconds / 60 / 60)
            qs += '%s&jcnlx.xhr=%s' % (err, d_hours)

        response['X-REDIRECT'] = qs

        response = helpers.set_aguid_cookie(response, request.get_host(),
                                            aguid)

        if vsid == '99' or not expired:
            # If expired has a value, we're staying on the my.jobs domain and
            # showing an expired job page. If not, we're probably going
            # to an external site.
            parsed = urlparse(redirect_url)
            pn = parsed.path
            pr = parsed.scheme + ':'
            hn = parsed.netloc
            se = parsed.query
            if se:
                se = '?' + se
        else:
            hn = request.get_host()
            pr = "https:" if request.is_secure() else "http:"
            pn = request.path
            se = request.META.get('QUERY_STRING', '')
            if se:
                se = '?' + se

        # Python doesn't have a method of easily creating a timestamp with
        # Zulu at the end. Remove the timezone and append "Z".
        now_iso = now.replace(tzinfo=None).isoformat() + 'Z'

        nv = request.COOKIES.get('de_nv') or now_iso
        response.set_cookie('de_nv',
                            nv,
                            expires=30 * 60,
                            domain=request.get_host())
        referrer = request.META.get('HTTP_REFERER', '')
        analytics.update({
            # Python tacks microseconds onto the end while JavaScript does
            # milliseconds. JS can handle parsing both, as can python-dateutil.
            'time': now_iso,
            'to': now_iso,
            're': referrer,
            'pn': pn,
            'pr': pr,
            'hn': hn,
            'se': se,
            'nv': nv
        })

        response['X-JSON-Header'] = json.dumps(analytics)

    if debug and not user_agent_vs:
        data = {'debug_content': debug_content}
        response = render_to_response('redirect/debug.html',
                                      data,
                                      context_instance=RequestContext(request))

    return response