Пример #1
0
def preview(request, code=None, api=False, template_name=None):

    ## if the page is being accessed as API, return the clean data
    if api is True:
        if code is None:
            url = request.GET.get('url')
            code = url.rstrip('/').split('/')[-1]
        object_id = SequenceMapper.to_decimal(code)
        try:
            shorturl = ShortURL.objects.get(pk=object_id).url
        except ShortURL.DoesNotExist:
            shorturl = ''
        return _api_response(shorturl, request.GET.get('type'))

    ## get the object id from code
    object_id = SequenceMapper.to_decimal(code)
    template_name = template_name or 'base_shorturl_preview.html'

    info_dict = {
        'queryset': ShortURL.objects,
        'object_id': object_id,
        'template_name': template_name,
    }

    return list_detail.object_detail(request, **info_dict)
Пример #2
0
def preview(request, code=None, api=False, template_name=None):

    ## if the page is being accessed as API, return the clean data
    if api is True:
        if code is None:
            url = request.GET.get('url')
            code = url.rstrip('/').split('/')[-1]
        object_id = SequenceMapper.to_decimal(code)
        try:
            shorturl = ShortURL.objects.get(pk=object_id).url
        except ShortURL.DoesNotExist:
            shorturl = ''
        return _api_response(shorturl, request.GET.get('type'))

    ## get the object id from code
    object_id = SequenceMapper.to_decimal(code)
    template_name = template_name or 'base_shorturl_preview.html'

    info_dict = {
        'queryset': ShortURL.objects,
        'object_id': object_id,
        'template_name': template_name,
    }

    return list_detail.object_detail(request, **info_dict)
Пример #3
0
def redirect(request, code):

    ## get the object id and lookup for the record
    object_id = SequenceMapper.to_decimal(code)
    shorturl = get_object_or_404(ShortURL, pk=object_id)

    ## record found, increment the hits and redirect
    shorturl.count_redirect(request)
    return HttpResponsePermanentRedirect(shorturl.url)
Пример #4
0
def redirect(request, code):

    ## get the object id and lookup for the record
    object_id = SequenceMapper.to_decimal(code)
    shorturl = get_object_or_404(ShortURL, pk=object_id)

    ## record found, increment the hits and redirect
    shorturl.count_redirect(request)
    return HttpResponsePermanentRedirect(shorturl.url)
Пример #5
0
def preview(request, code=None, api=False, template_name=None):

    ## if the page is being accessed as API, return the clean data
    if api is True:
        if code is None:
            url = request.GET.get("url")
            code = url.rstrip("/").split("/")[-1]
        object_id = SequenceMapper.to_decimal(code)
        try:
            shorturl = ShortURL.objects.active().get(pk=object_id).url
        except ShortURL.DoesNotExist:
            shorturl = ""
        return _api_response(shorturl, request.GET.get("type"))

    ## get the object id from code
    object_id = SequenceMapper.to_decimal(code)
    template_name = template_name or "base_shorturl_preview.html"

    info_dict = {"queryset": ShortURL.objects.active(), "object_id": object_id, "template_name": template_name}

    return list_detail.object_detail(request, **info_dict)
Пример #6
0
def redirect(request, code, template_name=None):

    ## get the object id and lookup for the record
    object_id = SequenceMapper.to_decimal(code)
    shorturl = get_object_or_404(ShortURL.objects.active(), pk=object_id)

    ## display the confirmation page
    if shorturl.confirmation and request.GET.get("direct") != "1":
        template_name = template_name or "base_shorturl_redirect.html"
        return render_to_response(template_name, locals(), context_instance=RequestContext(request))

    ## record found, increment the hits and redirect
    shorturl.count_redirect(request)
    return HttpResponsePermanentRedirect(shorturl.url)
Пример #7
0
 def test_sequence_mapping(self):
     for number in xrange(self.test_limit):
         code = SequenceMapper.from_decimal(number)
         number2 = SequenceMapper.to_decimal(code)
         self.assertEqual(number2, number)
Пример #8
0
 def test_sequence_mapping(self):
     for number in xrange(self.test_limit):
         code = SequenceMapper.from_decimal(number)
         number2 = SequenceMapper.to_decimal(code)
         self.assertEqual(number2, number)