Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
initial checkin from existing source code: http://trac.pylucid.net/br…
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Mar 5, 2010
0 parents commit eef4dc8
Show file tree
Hide file tree
Showing 9 changed files with 860 additions and 0 deletions.
16 changes: 16 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

PRIMARY AUTHORS are and/or have been (alphabetic order):

* Diemer, Jens
Main Developer since the first code line.
ohloh.net profile: <http://www.ohloh.net/accounts/4179/>
Homepage: <http://www.jensdiemer.de/>


CONTRIBUTORS are and/or have been (alphabetic order):
-


last SVN commit info:
$LastChangedDate: 2008-11-14 12:13:00 +0100 (Fr, 14 Nov 2008) $
$Rev: 1796 $
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
All rights reserved.


django-weave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3 or later as published
by the Free Software Foundation.

complete GNU General Public License version 3:
http://www.gnu.org/licenses/gpl-3.0.txt

German translation:
http://www.gnu.de/documents/gpl.de.html


copyleft 2010 by the django-weave team, see AUTHORS for more details.


SVN info:
$LastChangedDate: 2008-06-05 16:33:09 +0200 (Do, 05 Jun 2008) $
$Rev: 1635 $
50 changes: 50 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

=============
description
=============

django-weave is a Django reusable application witch implements a Firefox weave server.

=============
requirement
=============

:django-tools:
http://code.google.com/p/django-tools/

:django-reversion:
http://code.google.com/p/django-reversion/

=========
history
=========

- v0.0.1

- initial checkin

=============
weave links
=============

:Weave homepage:
https://wiki.mozilla.org/Labs/Weave

:reference implementation for a Weave server:
http://hg.mozilla.org/labs/weave/file/tip/tools/scripts/weave_server.py

:Weave server test script:
http://hg.mozilla.org/labs/weave/file/tip/tools/scripts/weave_server_tester.py

====================
django-weave links
====================

:homepage:
http://code.google.com/p/django-weave/

:SVN:
http://django-weave.googlecode.com/svn/trunk/


*(Readme text $Rev$)*
73 changes: 73 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
distutils setup
~~~~~~~~~~~~~~~
Last commit info:
~~~~~~~~~~~~~~~~~
$LastChangedDate$
$Rev$
$Author$
:copyleft: 2010 by the django-weave team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""

import os
import sys

from setuptools import setup, find_packages

from weave import VERSION_STRING


def get_authors():
authors = []
f = file("AUTHORS", "r")
for line in f:
if line.startswith('*'):
authors.append(line[1:].strip())
f.close()
return authors

def get_long_description():
f = file("README", "r")
long_description = f.read()
f.close()
long_description.strip()
return long_description


setup(
name='django-weave',
version=VERSION_STRING,
description='django-weave is a Django reusable application witch implements a Firefox weave server.',
long_description=get_long_description(),
author=get_authors(),
maintainer="Jens Diemer",
url='http://code.google.com/p/django-weave/',
packages=find_packages(),
include_package_data=True, # include package data under svn source control
zip_safe=False,
classifiers=[
"Development Status :: 1 - Planning",
"Development Status :: 2 - Pre-Alpha",
# "Development Status :: 3 - Alpha",
# "Development Status :: 4 - Beta",
# "Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Intended Audience :: Developers",
# "Intended Audience :: Education",
# "Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Programming Language :: Python",
'Framework :: Django',
"Topic :: Database :: Front-Ends",
"Topic :: Documentation",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
"Operating System :: OS Independent",
]
)
50 changes: 50 additions & 0 deletions weave/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# coding: utf-8

"""
Check some external libs with pkg_resources.require()
We only create warnings on VersionConflict and DistributionNotFound exceptions.
See also: ./scripts/requirements/external_apps.txt
See also: ./scripts/requirements/libs.txt
Format info for pkg_resources.require():
http://peak.telecommunity.com/DevCenter/PkgResources#requirement-objects
"""

import warnings
import pkg_resources


__version__ = (0, 0, 1, 'pre-alpha')

# for setuptools
# - Only use . as a separator
# - No spaces: (0, 1, 0, 'beta') -> "0.1.0beta"
# http://peak.telecommunity.com/DevCenter/setuptools#specifying-your-project-s-version
VERSION_STRING = "%s.%s.%s%s" % __version__



def check_require(requirements):
"""
Check a package list.
Display only warnings on VersionConflict and DistributionNotFound exceptions.
"""
for requirement in requirements:
try:
pkg_resources.require(requirement)
except pkg_resources.VersionConflict, err:
warnings.warn("Version conflict: %s" % err)
# except pkg_resources.DistributionNotFound, err:
# warnings.warn("Distribution not found: %s" % err)


requirements = (
# http://code.google.com/p/django-tools/
"django-tools >= 0.6.0beta",

# http://code.google.com/p/django-reversion/
"django-reversion >= 1.1.2",
)

check_require(requirements)
58 changes: 58 additions & 0 deletions weave/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# coding: utf-8

"""
PyLucid.admin
~~~~~~~~~~~~~~
Register all PyLucid model in django admin interface.
Last commit info:
~~~~~~~~~~~~~~~~~
$LastChangedDate$
$Rev$
$Author$
:copyleft: 2008-2009 by the PyLucid team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""


from django.contrib import admin
from django.conf import settings
from django.contrib.auth.models import User, Permission
from django.contrib.auth.admin import UserAdmin

from reversion.admin import VersionAdmin

from weave.models import Wbo, Collection


class WboAdmin(VersionAdmin):
def payload_cutout(self, obj):
MAX = 100
payload = obj.payload
if len(payload) > MAX:
payload = payload[:MAX] + "..."
return payload
payload_cutout.short_description = "Payload cutout"
# view_on_site_link.allow_tags = True

list_display = ("id", "lastupdatetime", "user", "wboid", "parentid", "sortindex", "lastupdateby", "payload_cutout")
list_display_links = ("wboid",)
list_filter = ("user", "collection")
date_hierarchy = 'lastupdatetime'
# search_fields = ("headline", "content")

admin.site.register(Wbo, WboAdmin)


class CollectionAdmin(VersionAdmin):
"""
"""
list_display = ("id", "lastupdatetime", "user", "name", "lastupdateby")
list_display_links = ("name",)
list_filter = ("user", "createby", "lastupdateby",)
date_hierarchy = 'lastupdatetime'
# search_fields = ("headline", "content")

admin.site.register(Collection, CollectionAdmin)
105 changes: 105 additions & 0 deletions weave/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# coding:utf-8

from django.conf import settings
from django.contrib.auth.models import User
from django.db import models

# http://code.google.com/p/django-tools/
from django_tools.middlewares import ThreadLocal


class BaseModel(models.Model):
createtime = models.DateTimeField(auto_now_add=True, help_text="Create time")
lastupdatetime = models.DateTimeField(auto_now=True, help_text="Time of the last change.")

createby = models.ForeignKey(User, editable=False, related_name="%(class)s_createby",
null=True, blank=True, # <- If the model used outsite a real request (e.g. unittest, db shell)
help_text="User how create this entry.")
lastupdateby = models.ForeignKey(User, editable=False, related_name="%(class)s_lastupdateby",
null=True, blank=True, # <- If the model used outsite a real request (e.g. unittest, db shell)
help_text="User as last edit this entry.")

def save(self, *args, **kwargs):
"""
Automatic update createby and lastupdateby attributes with the request object witch must be
the first argument.
"""
current_user = ThreadLocal.get_current_user()

if current_user and isinstance(current_user, User):
if self.pk == None or kwargs.get("force_insert", False): # New model entry
self.createby = current_user
self.lastupdateby = current_user

return super(BaseModel, self).save(*args, **kwargs)

class Meta:
abstract = True


class Collection(BaseModel):
"""
https://wiki.mozilla.org/Labs/Weave/Sync/1.0/Setup
inherited from BaseModel:
createtime -> datetime of creation
lastupdatetime -> datetime of the last change
createby -> ForeignKey to user who creaded this entry
lastupdateby -> ForeignKey to user who has edited this entry
"""
user = models.ForeignKey(User)
name = models.CharField(max_length=96)

sites = models.ManyToManyField(Site, default=[settings.SITE_ID])
on_site = CurrentSiteManager('sites')

def site_info(self):
""" for admin.ModelAdmin list_display """
sites = self.sites.all()
return ", ".join([site.name for site in sites])
site_info.short_description = _('Exists on site')
site_info.allow_tags = False

def __unicode__(self):
return u"weave collection %r for user %r" % (self.name, self.user.username)

class Meta:
ordering = ("-lastupdatetime",)


class Wbo(BaseModel):
"""
https://wiki.mozilla.org/Labs/Weave/Sync/1.0/API
https://wiki.mozilla.org/Labs/Weave/Sync/1.0/Setup
inherited from BaseModel:
createtime -> datetime of creation
lastupdatetime -> datetime of the last change
createby -> ForeignKey to user who creaded this entry
lastupdateby -> ForeignKey to user who has edited this entry
"""
collection = models.ForeignKey(Collection, blank=True, null=True)
user = models.ForeignKey(User)
wboid = models.CharField(max_length=64, blank=True,
help_text="wbo identifying string"
)
parentid = models.CharField(max_length=64, blank=True, null=True,
help_text="wbo parent identifying string"
)
sortindex = models.IntegerField(null=True, blank=True,
help_text="An integer indicting the relative importance of this item in the collection.",
)
payload = models.TextField(blank=True,
help_text=(
"A string containing a JSON structure encapsulating the data of the record."
" This structure is defined separately for each WBO type. Parts of the"
" structure may be encrypted, in which case the structure should also"
" specify a record for decryption."
)
)

def __unicode__(self):
return u"weave wbo %r (%r)" % (self.wboid, self.collection)

class Meta:
ordering = ("-lastupdatetime",)
Loading

0 comments on commit eef4dc8

Please sign in to comment.