# Path: webapp/apps/bookmark/models.py
# class Bookmark(models.Model):
#     owner = models.ForeignKey(User, verbose_name=_(u'Owner'), related_name='owner_bookmarks')
#     url = models.URLField(verbose_name=_(u'URL'))
#     title = models.CharField(verbose_name=_(u'Title'), blank=True, max_length=100,
#         help_text=_(u'Limit of 100 characters'))
#     tags = TaggableManager(verbose_name=_(u'Tags'), blank=True,
#         help_text=_(u'A comma-separated list of tags. At most 3.'))
#     public = models.BooleanField(verbose_name=_(u'Public this bookmark'), blank=True, default=True)
#     screen_shot = models.ImageField(verbose_name=_(u'Screen shot'), upload_to='bookmark', blank=True)
#     create_time = models.DateTimeField(verbose_name=_(u'Create time'), auto_now_add=True)
#     last_modified_time = models.DateTimeField(verbose_name=_(u'Last modified time'), auto_now=True)
# 
#     def __unicode__(self):
#         return self.url
# 
#     def get_absolute_url(self):
#         return self.url
# 
#     class Meta:
#         ordering = ['-create_time']


import threading
import urllib2
import uuid
import os
import BeautifulSoup
from django.core.files.base import ContentFile
from webapp.apps.bookmark.models import Bookmark
            pass

    return bookmarks

#print parse_firefox_bookmark(open('bookmarks.html', 'r'))

class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
    def http_error_301(self, req, fp, code, msg, headers):
        result = urllib2.HTTPRedirectHandler.http_error_301(
            self, req, fp, code, msg, headers)
        result.status = code
        return result

    def http_error_302(self, req, fp, code, msg, headers):
        result = urllib2.HTTPRedirectHandler.http_error_302(
            self, req, fp, code, msg, headers)
        result.status = code
        return result

def update_bk_screen_shot(bookmark):
    image = get_image_by_url(bookmark.url)
    if image:
        image_file_name = str(uuid.uuid1()) + ".png"
        try:
            os.remove(bookmark.screen_shot.path)
        except:
            pass
        bookmark_id = bookmark.id
        # Retreve the bookmark again make sure the bookmark others data is correct
        try:

# Path: webapp/apps/bookmark/models.py
# class Bookmark(models.Model):
#     owner = models.ForeignKey(User, verbose_name=_(u'Owner'), related_name='owner_bookmarks')
#     url = models.URLField(verbose_name=_(u'URL'))
#     title = models.CharField(verbose_name=_(u'Title'), blank=True, max_length=100,
#         help_text=_(u'Limit of 100 characters'))
#     tags = TaggableManager(verbose_name=_(u'Tags'), blank=True,
#         help_text=_(u'A comma-separated list of tags. At most 3.'))
#     public = models.BooleanField(verbose_name=_(u'Public this bookmark'), blank=True, default=True)
#     screen_shot = models.ImageField(verbose_name=_(u'Screen shot'), upload_to='bookmark', blank=True)
#     create_time = models.DateTimeField(verbose_name=_(u'Create time'), auto_now_add=True)
#     last_modified_time = models.DateTimeField(verbose_name=_(u'Last modified time'), auto_now=True)
# 
#     def __unicode__(self):
#         return self.url
# 
#     def get_absolute_url(self):
#         return self.url
# 
#     class Meta:
#         ordering = ['-create_time']


# Path: webapp/apps/bookmark/utils.py
import threading
import urllib2
import uuid
import os
import BeautifulSoup
from django.core.files.base import ContentFile
from webapp.apps.bookmark.models import Bookmark

            pass

    return bookmarks

#print parse_firefox_bookmark(open('bookmarks.html', 'r'))

class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
    def http_error_301(self, req, fp, code, msg, headers):
        result = urllib2.HTTPRedirectHandler.http_error_301(
            self, req, fp, code, msg, headers)
        result.status = code
        return result

    def http_error_302(self, req, fp, code, msg, headers):
        result = urllib2.HTTPRedirectHandler.http_error_302(
            self, req, fp, code, msg, headers)
        result.status = code
        return result

def update_bk_screen_shot(bookmark):
    image = get_image_by_url(bookmark.url)
    if image:
        image_file_name = str(uuid.uuid1()) + ".png"
        try:
            os.remove(bookmark.screen_shot.path)
        except:
            pass
        bookmark_id = bookmark.id
        # Retreve the bookmark again make sure the bookmark others data is correct
        try:

            bookmark = Bookmark.objects.get(id=bookmark_id)