1. jgsogo
  2. django-url-shortener

Commits

jgsogo  committed f87c5c0 Draft

no chimp here

  • Participants
  • Parent commits 7c31e2d
  • Branches default

Comments (0)

Files changed (4)

File shortener/admin.py

View file
 from django.contrib import admin
 
-from chimp_shortener.models import Link
+from shortener.models import Link
 
 class LinkAdmin(admin.ModelAdmin):
     list_display = ('_hash','url', 'created')

File shortener/models.py

View file
 from django.core.validators import URLValidator
 from django.core.exceptions import ValidationError
 
-from chimp_shortener.settings import LINK_UNIQUENESS, HASH_SEED_LENGTH, SITE_BASE_URL, HASH_STRATEGY
-from chimp_shortener.baseconv import base62
+from shortener.settings import LINK_UNIQUENESS, HASH_SEED_LENGTH, SITE_BASE_URL, HASH_STRATEGY
+from shortener.baseconv import base62
 
-log = logging.getLogger('chimppunch')
+log = logging.getLogger(__name__)
 
 class Link(models.Model):
     _hash = models.CharField(max_length=8) # n-char unique random string
             return cls.create(url)
 
     @classmethod
-    def create(cls, url):
+    def create(cls, url, commit=True):
         log.debug("Link::create(url='%s')" % url)
         if not cls.url_is_valid(url):
             raise ValueError('Invalid URL')
         instance._hash = cls.generate_unique_hash(instance)
         instance.url = url
 
-        instance.save()
+        if commit:
+            instance.save()
         return instance
 
     @classmethod

File shortener/urls.py

View file
 from django.conf.urls import patterns, include, url
 
-from chimp_shortener.settings import WORKING_MODE
-from chimp_shortener import MODES
+from shortener.settings import WORKING_MODE
+from shortener import MODES
 
 if WORKING_MODE is MODES.redirects:
-    from chimp_shortener.views import follow
+    from shortener.views import follow
     urlpatterns = patterns('',
         url(r'^(?P<base62>\w+)$', follow, name='short_link'),
         )

File shortener/views.py

View file
 from django.shortcuts import get_object_or_404
 from django.http import HttpResponsePermanentRedirect, HttpResponseRedirect
 
-from chimp_shortener.models import Link
-from chimp_shortener.signals import link_followed
+from shortener.models import Link
+from shortener.signals import link_followed
 
 log = logging.getLogger(__name__)