<commit_before>import urlparse
import furl
from modularodm.exceptions import NoResultsFound
from modularodm import Q
from rest_framework.exceptions import NotFound
from rest_framework.reverse import reverse
from django.utils.http import urlencode

from website import settings as website_settings
from website import util as website_util # noqa


def absolute_reverse(view_name, query_kwargs=None, args=None, kwargs=None):
    """Like django's `reverse`, except returns an absolute URL. Also add query parameters."""
    relative_url = reverse(view_name, kwargs=kwargs)

    if query_kwargs:
        relative_url = '{}?{}'.format(relative_url, urlencode(query_kwargs))

    domain = website_settings.API_DOMAIN
    return urlparse.urljoin(domain, relative_url)


def get_object_or_404(model_cls, query_or_pk):
    if isinstance(query_or_pk, basestring):
        query = Q('_id', 'eq', query_or_pk)
    else:
        query = query_or_pk<commit_msg>Use api_v2_url for absolute_reverse.<commit_after># -*- coding: utf-8 -*-

import furl

from rest_framework.exceptions import NotFound
from rest_framework.reverse import reverse
from modularodm.exceptions import NoResultsFound
from modularodm import Q

from api.base import settings as api_settings
from website import settings as website_settings
from website import util as website_util  # noqa


def absolute_reverse(view_name, query_kwargs=None, args=None, kwargs=None):
    """Like django's `reverse`, except returns an absolute URL. Also add query parameters."""
    relative_url = reverse(view_name, kwargs=kwargs)

    url = website_util.api_v2_url(relative_url, params=query_kwargs,
                                  base_prefix=api_settings.API_PATH)
    return url


def get_object_or_404(model_cls, query_or_pk):
    if isinstance(query_or_pk, basestring):
        query = Q('_id', 'eq', query_or_pk)
    else:
        query = query_or_pk
{'fraction_non_alphanumeric': 0.07749077490774908, 'fraction_numerical': 0.004744333157617291, 'mean_word_length': 4.58235294117647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '302124', 'n_tokens_mistral': 568, 'n_tokens_neox': 553, 'n_words': 161}