Skip to content

Commit

Permalink
Initial Commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
adieu committed Jul 28, 2012
0 parents commit 4447500
Show file tree
Hide file tree
Showing 19 changed files with 1,419 additions and 0 deletions.
4 changes: 4 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,4 @@
include setup.py MANIFEST.in README.rst
recursive-include bookmarks/templates *
recursive-include bookmarks/site/templates *
recursive-include bokkmarks/site/static *
43 changes: 43 additions & 0 deletions README.rst
@@ -0,0 +1,43 @@
mezzanine-bookmarks
===================

WARNING: mezzanine-bookmarks is under development.

mezzanine-bookmarks is a bookmark service built on Django and Mezzanine designed to be flexible and easy to use.
You could host it as a standalone bookmark service for multiple users. Or you could embed it into an existing mezzanine site.

Here is the feature list:

- Multiple User support
- Single User mode
- Use service from www.diffbot.com to extract main content from web page
- Use service from api.zemanta.com to generate suggested tags
- Store page content for future use

INSTALL
*******

EMBED INSTALL
-------------

mezzanine-bookmarks could be used as a django app.

pip install mezzanine-bookmarks

Then add `'bookmarks',` to INSTALLED_APPS and add `("^bookmarks/", include("bookmarks.urls")),` to `urls.py`.

STANDALONE INSTALL
------------------

mezzanine-bookmarks comes with a standalone mode which you could use run a bookmark service with it very quickly.

virtualenv bookmarks
source bookmarks/bin/activate
pip install mezzanine-bookmarks
pip install django-template-bootstrap
bookmarks init
vim ~/.bookmarks/bookmarks.conf.py # Add your own diffbot and zemanta api keys
bookmarks syncdb
bookmarks migrate
bookmarks runserver

Empty file added bookmarks/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions bookmarks/admin.py
@@ -0,0 +1,28 @@
from copy import deepcopy

from django.contrib import admin

from mezzanine.core.admin import DisplayableAdmin, OwnableAdmin

bookmark_fieldsets = deepcopy(DisplayableAdmin.fieldsets)
bookmark_fieldsets[0][1]["fields"].insert(1, "page")
bookmark_fieldsets[0][1]["fields"].extend(["content",])

from bookmarks.models import Page, Bookmark


class BookmarkAdmin(DisplayableAdmin, OwnableAdmin):
"""
Admin class for bookmarks.
"""
fieldsets = bookmark_fieldsets

def save_form(self, request, form, change):
"""
Super class ordering is important here - user must get saved first.
"""
OwnableAdmin.save_form(self, request, form, change)
return DisplayableAdmin.save_form(self, request, form, change)

admin.site.register(Bookmark, BookmarkAdmin)
admin.site.register(Page)
72 changes: 72 additions & 0 deletions bookmarks/forms.py
@@ -0,0 +1,72 @@
from django import forms
from django.utils.translation import ugettext_lazy as _

from mezzanine.generic.models import Keyword

from bookmarks.models import Bookmark, Page


class BookmarkForm(forms.ModelForm):
url = forms.URLField(label="URL", verify_exists=False, widget=forms.TextInput(attrs={"size": 40}))
title = forms.CharField(max_length=100, widget=forms.TextInput(attrs={"size": 40}))
keywords = forms.CharField(max_length=100, widget=forms.TextInput(attrs={"size": 40}))
content = forms.Textarea()
redirect = forms.BooleanField(label="Redirect", required=False)

def __init__(self, user=None, *args, **kwargs):
self.user = user
super(BookmarkForm, self).__init__(*args, **kwargs)
# hack to order fields
self.fields.keyOrder = ["url", "title", "content", "keywords", "redirect"]

def clean(self):
if not self.cleaned_data.get("url", None):
return self.cleaned_data
if Bookmark.objects.filter(page__url=self.cleaned_data["url"], user=self.user).count() > 0:
raise forms.ValidationError(_("You have already bookmarked this link."))
return self.cleaned_data

def clean_keywords(self):
"""docstring for clean_keywords"""
ids = []
for title in self.cleaned_data['keywords'].split(","):
title = "".join([c for c in title if c.isalnum() or c in "- "])
title = title.strip().lower()
if title:
keyword, created = Keyword.objects.get_or_create(title=title)
id = str(keyword.id)
if id not in ids:
ids.append(id)
return ",".join(ids)

def should_redirect(self):
if self.cleaned_data["redirect"]:
return True
else:
return False

def save(self, commit=True):
try:
page = Page.objects.get(url=self.cleaned_data['url'])
except Page.DoesNotExist:
page = Page.objects.create(url=self.cleaned_data['url'], creator=self.user)

instance = super(BookmarkForm, self).save(False)
instance.page = page
instance.user = self.user

if commit:
instance.save()
self.save_m2m()

return instance

class Meta:
model = Bookmark
fields = [
"url",
"title",
"content",
"redirect",
"keywords",
]
35 changes: 35 additions & 0 deletions bookmarks/models.py
@@ -0,0 +1,35 @@
import datetime

from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _

from mezzanine.core.models import Displayable, Ownable, RichText


class Page(models.Model):

url = models.URLField(unique=True)

creator = models.ForeignKey(User, verbose_name=_("creator"))
create_date = models.DateTimeField(_("create time"), default=datetime.datetime.now)

def __unicode__(self):
return self.url

class Meta:
ordering = ["-create_date", ]


class Bookmark(Displayable, Ownable, RichText):

page = models.ForeignKey(Page, verbose_name=_("page"))

@models.permalink
def get_absolute_url(self):
url_name = "bookmark"
kwargs = {'pk': self.pk}
return (url_name, (), kwargs)

def __unicode__(self):
return self.title
Empty file added bookmarks/site/__init__.py
Empty file.

0 comments on commit 4447500

Please sign in to comment.