Пример #1
0
def get_short_url(request):
    url = request.POST.get('url', None)
    from libs.vavag import VavagRequest, VavagException
    try:
        from django.conf import settings as __web_settings # parche hasta conseguir que se cachee variable global
        client = VavagRequest(__web_settings.SHORTENER_ACCESS['user'], __web_settings.SHORTENER_ACCESS['key'])
        response =  client.set_pack(url)
        return HttpResponse(simplejson.dumps(response['results']['packUrl']),
                            mimetype='application/json')
    except VavagException, e:
        return HttpResponseBadRequest(simplejson.dumps(e.msg),
                                      mimetype='application/json')
Пример #2
0
 def _get_short_url(self):
     from libs.vavag import VavagRequest
     from os import environ
     try:
         # parche hasta conseguir que se cachee variable global
         client = VavagRequest(settings.SHORTENER_ACCESS['user'], settings.SHORTENER_ACCESS['key'])
         response =  client.set_pack('http://%s%s' % (environ['HTTP_HOST'], self.get_absolute_url()))
         self._short_url = response['packUrl']
     except Exception, e:
         import logging
         logging.error('ERROR EN VAVAG: %s' % e.message)
         self._short_url = None
Пример #3
0
def get_short_url(request):
    url = request.POST.get('url', None)
    from libs.vavag import VavagRequest, VavagException
    try:
        from django.conf import settings as __web_settings  # parche hasta conseguir que se cachee variable global
        client = VavagRequest(__web_settings.SHORTENER_ACCESS['user'],
                              __web_settings.SHORTENER_ACCESS['key'])
        response = client.set_pack(url)
        return HttpResponse(simplejson.dumps(response['results']['packUrl']),
                            mimetype='application/json')
    except VavagException, e:
        return HttpResponseBadRequest(simplejson.dumps(e.msg),
                                      mimetype='application/json')
Пример #4
0
 def short_url(self):
     if self._short_url == '':
         from django.contrib.sites.models import Site
         from libs.vavag import VavagRequest
         
         try:
             current_site = Site.objects.get_current()
             client = VavagRequest(settings.VAVAG_PASSWORD['user'], settings.VAVAG_PASSWORD['key'])
             response = client.set_pack('http://%s%s' % (current_site.domain, self.get_absolute_url()))
             self._short_url = response['packUrl']
             self.save()
         except Exception:
             self._short_url = ''
             return 'http://%s%s' % (current_site.domain, self.get_absolute_url())
     return self._short_url