Exemplo n.º 1
0
def create_first_shorturl(sender, **kwargs):

    if not kwargs.get('interactive'):
        return

    ## check if the database contains some URL
    if ShortURL.objects.count() > 0:
        return

    ## check if the user wants to configure the site
    prompt = 'Would you like to create a first short URL pointing to this site? (yes/no): '
    option = ''
    while option.lower() != 'yes':
        option = raw_input(prompt)
        if option.lower() == 'no':
            return

    ## create the first url
    current_site = sender.Site.objects.get_current()
    scheme = getattr(settings, 'SHORTIM_SITE_SCHEME', 'http')
    url = scheme.lower() + '://' + current_site.domain \
            + reverse('shortim_create')

    shorturl = ShortURL(url=url, remote_user='******')
    shorturl.save()
    print 'First short URL created: %s\n' % shorturl.get_absolute_full_url()
Exemplo n.º 2
0
def create_first_shorturl(sender, **kwargs):
    from models import ShortURL

    if not kwargs.get('interactive'):
        return

    ## check if the database contains some URL
    if ShortURL.objects.count() > 0:
        return

    ## check if the user wants to configure the site
    prompt = 'Would you like to create a first short URL pointing to this site? (yes/no): '
    option = ''
    while option.lower() != 'yes':
        option = raw_input(prompt)
        if option.lower() == 'no':
            return

    ## create the first url
    current_site = sender.Site.objects.get_current()
    scheme = getattr(settings, 'SHORTIM_SITE_SCHEME', 'http')
    url = scheme.lower() + '://' + current_site.domain \
            + reverse('shortim_create')

    shorturl = ShortURL(url=url, remote_user='******')
    shorturl.save()
    print 'First short URL created: %s\n' % shorturl.get_absolute_full_url()