Permalink
Browse files

new models prepared

api browser - first attempts
  • Loading branch information...
1 parent 20728c7 commit aaecd63a7e515f62b08d4689caf6e78bdb71886f @zalun zalun committed May 6, 2010
@@ -0,0 +1,18 @@
+# Taken from feincms
+# http://github.com/matthiask/feincms/blob/master/feincms/__init__.py
+
+# Do not use Django settings at module level as recommended
+from django.utils.functional import LazyObject
+
+class LazySettings(LazyObject):
+ def _setup(self):
+ from api import default_settings
+ self._wrapped = Settings(default_settings)
+
+class Settings(object):
+ def __init__(self, settings_module):
+ for setting in dir(settings_module):
+ if setting == setting.upper():
+ setattr(self, setting, getattr(settings_module, setting))
+
+settings = LazySettings()
@@ -0,0 +1,10 @@
+import os
+from django.conf import settings
+
+
+SDKPACKAGESDIR = os.path.join(settings.VIRTUAL_ENV,'src/jetpack-sdk/packages')
+# ------------------------------------------------------------------------
+VIRTUAL_ENV = settings.VIRTUAL_ENV
+VIRTUAL_SITE_PACKAGES = settings.VIRTUAL_SITE_PACKAGES
+FRAMEWORK_PATH = settings.FRAMEWORK_PATH
+DEBUG = settings.DEBUG
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
@@ -0,0 +1,25 @@
+{% extends "base.html" %}
+{% load base_helpers %}
+
+
+{% block app_sidebar %}
+ <section id='module-info'>
+ <h2>{{ module.name }}</h2>
+ </section>
+ <section id='modules'>
+ {% for module in package.modules %}
+ <a href='#'>{{ module.name }}</a>
+ {% endfor %}
+ </section>
+{% endblock %}
+{% block app_content %}
+ {% for module in package.modules %}
+ <h3>{{ module.name }}</h3>
+ <div class='module-info'>
+ <p>{{ module.info|safe }}</p>
+ <a href='#{{ module.name }}'>show Module doc</a>
+ </div>
+ {% endfor %}
+ </dl>
+{% endblock %}
+
@@ -0,0 +1,26 @@
+{% extends "base.html" %}
+{% load base_helpers %}
+
+{% block app_sidebar %}
+ <section id='package-info'>
+ <h2>{{ package.name }}</h2>
+ </section>
+ <section id='modules'>
+ {% for module in package.modules %}
+ <a href='#'>{{ module.name }}</a>
+ {% endfor %}
+ </section>
+{% endblock %}
+
+{% block app_content %}
+ {% for module in package.modules %}
+ <h3>{{ module.name }}</h3>
+ <div class='module-info'>
+ <p>{{ module.info|safe }}</p>
+ <a href='#{{ module.name }}'>show Module doc</a>
+ <pre>{{ module.hunks }}</pre>
+ </div>
+ {% endfor %}
+ </dl>
+{% endblock %}
+
@@ -0,0 +1,21 @@
+"""
+Testing the cuddlefish engine to export API
+"""
+
+import os
+from django.test import TestCase
+from cuddlefish import apiparser
+from api import settings
+
+class CuddleTest(TestCase):
+ def test_basic(self):
+ """
+ exporting hunks
+ """
+ docs_dir = os.path.join(settings.VIRTUAL_ENV,'src/jetpack-sdk/packages/jetpack-core/docs')
+ text = open(os.path.join(docs_dir,'url.md')).read()
+ hunks = list(apiparser.parse_hunks(text))
+ print hunks
+
+
+
@@ -0,0 +1,8 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('api.views',
+ url(r'', 'package', {'package_name': 'jetpack-core'}, name='api_home'),
+ url(r'^package/(?P<package_name>.*)/module/(?P<module_name>.*)/$','module', name='api_module'),
+ url(r'^package/(?P<package_name>.*)/$', 'package', name='api_package'),
+)
+
@@ -0,0 +1,71 @@
+import os
+import sys
+
+from cuddlefish import apiparser
+
+from django.shortcuts import render_to_response, get_object_or_404
+from django.http import Http404, HttpResponseRedirect, HttpResponse, \
+ HttpResponseNotAllowed, HttpResponseServerError
+from django.template import RequestContext#,Template
+from django.utils import simplejson
+
+from base.shortcuts import get_object_or_create, get_object_with_related_or_404, \
+ get_random_string
+
+from api import settings
+
+
+def package(r, package_name):
+ """
+ containing a listing of all modules docs
+ """
+
+ DOC_FILES = os.listdir(os.path.join(settings.SDKPACKAGESDIR,package_name,'docs'))
+
+ package = {'name': package_name, 'modules': []}
+ import pprint
+ for d in DOC_FILES:
+ text = open(os.path.join(settings.SDKPACKAGESDIR,package_name,'docs',d)).read()
+ (doc_name, extension) = os.path.splitext(d)
+ # changing the tuples to dictionaries
+ hunks = list(apiparser.parse_hunks(text))
+ pprint.pprint(hunks)
+ print('-------------------------------------')
+ data = {}
+ for h in hunks:
+ data[h[0]] = h[1]
+ package['modules'].append({
+ 'name': doc_name,
+ 'info': data['markdown'],
+ 'data': data,
+ 'hunks': hunks
+ })
+
+ page = 'api'
+
+ return render_to_response(
+ 'package_doc.html',
+ locals(),
+ context_instance=RequestContext(r))
+
+def module(r, package_name, module_name):
+ doc_file = '.'.join((module_name,'md'))
+ text = open(os.path.join(settings.SDKPACKAGESDIR,package_name,'docs',doc_file,'.rd')).read()
+ # changing the tuples to dictionaries
+ hunks = list(apiparser.parse_hunks(text))
+ data = {}
+ for h in hunks:
+ data[h[0]] = h[1]
+ module = {
+ 'name': doc_name,
+ 'info': data['markdown'],
+ 'data': data,
+ 'hunks': hunks
+ }
+
+ page = 'api'
+
+ return render_to_response(
+ 'module_doc.html',
+ locals(),
+ context_instance=RequestContext(r))
@@ -3,24 +3,7 @@
from django.conf import settings
from django.template import RequestContext#,Template
-from jetpack.models import Jet, Cap
+from jetpack.views import homepage as jetpack_homepage
def homepage(r):
- """
- Display description of the website with a set of fresh stuff
- """
-
- # TODO: filter out items without base version
- jet_limit = settings.HOMEPAGE_ITEMS_LIMIT+1
- jetpacks = Jet.objects.all()[:jet_limit]
- capabilities = Cap.objects.all()[:settings.HOMEPAGE_ITEMS_LIMIT]
-
-
- page = 'homepage'
-
-
- return render_to_response(
- 'homepage.html',
- locals(),
- context_instance=RequestContext(r))
-
+ return jetpack_homepage(r)
@@ -1,6 +1,6 @@
from django.contrib import admin
-from models import Jet, JetVersion, Cap, CapVersion
+from models_old import Jet, JetVersion, Cap, CapVersion
class JetAdmin(admin.ModelAdmin):
pass
@@ -9,3 +9,4 @@
VIRTUAL_SITE_PACKAGES = settings.VIRTUAL_SITE_PACKAGES
FRAMEWORK_PATH = settings.FRAMEWORK_PATH
DEBUG = settings.DEBUG
+HOMEPAGE_ITEMS_LIMIT = settings.HOMEPAGE_ITEMS_LIMIT
@@ -0,0 +1,23 @@
+from django.db import models
+
+class CapVersionManager(models.Manager):
+ def get_base(self, slug):
+ try:
+ return self.select_related().get(capability__slug=slug, is_base=True)
+ except:
+ return None
+
+ def filter_by_slug(self, slug):
+ return self.select_related().filter(capability__slug=slug)
+
+
+class JetVersionManager(models.Manager):
+ def get_base(self, slug):
+ try:
+ return self.select_related().get(jetpack__slug=slug, is_base=True)
+ except:
+ return None
+
+ def filter_by_slug(self, slug):
+ return self.select_related().filter(jetpack__slug=slug)
+
@@ -8,6 +8,7 @@
from jetpack.managers import PackageManager
PERMISSION_CHOICES = (
+ (0, 'private'),
(1, 'view'),
(2, 'edit')
)
@@ -20,31 +21,32 @@ class Package(models.Model):
"""
Holds the meta data shared across all PackageRevisions
"""
- # name of the Package - has to be unique - it's slug is used for identificatio
- name = models.CharField(max_length=255, unique=True)
+ # identification
+ # it can be the same as database id, but if we want to copy the database some day or change
+ # to a document-oriented database it shouldn't rely on database model
+ id_number = models.PositiveIntegerField(unique=True)
+
+ # name of the Package
+ name = models.CharField(max_length=255)
+ # made from the name
+ # it is used to create a directory of Modules
+ slug = models.CharField(max_length=255, blank=True)
# description
description = models.TextField(blank=True)
-
- # unified id made from the name used to identify Packages
- # it is used to create a directory of Modules
- slug = models.CharField(max_length=255, unique=True, blank=True, primary_key=True)
# type - determining ability to specific options
type = models.CharField(max_length=30, choices=TYPE_CHOICES)
- # currently default PackageRevision
- head = models.ForeignKey('PackageRevision', blank=True, null=True, related_name='head')
-
# creator is the first person who created the Package
# TODO: consider ability to change this (UI)
creator = models.ForeignKey(User, related_name='packages_originated')
# group of users who have management rights
- managers = models.ManyToManyField(User, related_name='packages_managed', blank=True)
+ # managers = models.ManyToManyField(User, related_name='packages_managed', blank=True)
# developers is a collected group of all developers who participated in Package development
- developers = models.ManyToManyField(User, related_name='packages_developed', blank=True)
+ # developers = models.ManyToManyField(User, related_name='packages_developed', blank=True)
# is the Package visible for public?
- public_permission = models.IntegerField(choices=PERMISSION_CHOICES, default=2, blank=True)
+ public_permission = models.IntegerField(choices=PERMISSION_CHOICES, default=1, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
last_update = models.DateTimeField(auto_now=True)
@@ -66,22 +68,15 @@ def set_slug(self):
def make_slug(self):
return slugify(self.name)
- def set_head(self, revision):
- self.revision = revision
- self.save()
- if not revision.was_head:
- revision.was_head = True
- revision.save()
-
class PackageRevision(models.Model):
"""
contains data which may be changed and rolled back
"""
package = models.ForeignKey(Package, related_name='revisions')
# public version name
- # WARNING: it's not unique!
- version_name = models.CharField(max_length=250, blank=True, default='alpha 0.01')
+ # this is a tag used to mark important revisions
+ version_name = models.CharField(max_length=250, blank=True, default='initial')
# this makes the revision unique across the same package/user
revision_number = models.IntegerField(blank=True, default=0)
# commit message
@@ -90,9 +85,6 @@ class PackageRevision(models.Model):
# Libraries on which current package depends
libraries = models.ManyToManyField('self', blank=True, null=True, symmetrical=False)
- # was_head - record if it was used as HEAD of the package
- was_head = models.BooleanField(blank=True, default=False)
-
# from which revision this mutation was originated
origin = models.ForeignKey('PackageRevision', related_name='mutations',
blank=True, null=True)
@@ -146,7 +138,7 @@ class Module(models.Model):
author = models.ForeignKey(User, related_name='module revisions')
class Meta:
- unique_together('revision', 'filename')
+ unique_together = ('revision', 'filename')
########################################################################################
Oops, something went wrong.

0 comments on commit aaecd63

Please sign in to comment.