Commit eaebfa84 authored by Nagarjuna's avatar Nagarjuna

basic skeleton for mongodb storage

parent c05b309d
This diff is collapsed.
gstudio
=======
gstudio is a node description framework (NDF) to create knowledge networks. We are recreating gnowsys-studio with mongodb as storage.
gstudio
=======
gstudio_mdb
===========
gstudio is a node description framework (NDF) to create knowledge networks. We are recreating gnowsys-studio with mongodb as storage.
A Django application to recreate gnowsys-studio from scratch using
mongodb as storage. It uses django_mongodb_engine.
This project will eventually metamorphose into an implementation of
http://www.gnu.org/software/gnowsys/ framework to create generic network
networks using Node Description Framework.
The project is released under GNU AGPL v3 license.
Currently Implemented Features
==============================
- create nodes
- comment nodes
To do
=====
- create collections
- create nested collections
- define relation types
- create relations
- define attribute types
- create attributes
- aggregate relations and attributes
- aggregate types
Mailing list
============
Join this list if you are intersted in contributing or have problems
in using this application.
http://gnowledge.org/cgi-bin/mailman/listinfo/gnowsys-dev
gstudio_mdb/forms.py,200
class CommentForm(6,116
def __init__(8,147
def save(15,406
class Meta:Meta21,599
class RelationForm(24,640
def __init__(26,672
def save(33,911
class Meta:Meta39,1105
gstudio_mdb/models.py,303
class Node(10,171
def get_absolute_url(20,605
def __unicode__(23,697
class Meta:Meta26,751
class Comment(30,804
class Relation(35,1010
class RelationType(41,1306
def __unicode__(48,1632
def get_absolute_url(51,1685
def __unicode__(54,1785
class Meta:Meta57,1839
gstudio_mdb/views.py,168
class NodeView(9,248
class NodeDetailView(12,311
def get(15,376
def post(21,628
class NodeRelationsView(33,1027
def get(36,1095
def post(42,1348
gstudio_mdb/templates/gstudio_mdb/base.html,70
GNOWSYS Node Description Framework 5,69
NDF: Node Description15,368
gstudio_mdb/templates/gstudio_mdb/node_detail.html,80
{{ node.title }}5,91
Comments13,264
Add a comment25,581
Add Relations34,804
gstudio_mdb/templates/gstudio_mdb/node_list.html,22
{{ node.title }}5,91
gstudio_mdb/templates/gstudio_mdb/_forms.html,0
gstudio_mdb/admin.py,0
gstudio_mdb/__init__.py,0
gstudio_mdb/settings.py,0
gstudio_mdb/urls.py,0
gstudio_mdb/wsgi.py,0
manage.py,0
Django Implementation of GNOWSYS http://www.gnu.org/software/gnowsys/
Copyright (c) 2011, 2012 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This project incorporates work covered by the following copyright and permission notice:
Copyright (c) 2009, Julien Fache
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the author nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
./manage.py
./gstudio_mdb/wsgi.py
./gstudio_mdb/forms.py
./gstudio_mdb/models.py
./gstudio_mdb/urls.py
./gstudio_mdb/settings.py
./gstudio_mdb/__init__.py
./gstudio_mdb/admin.py
./gstudio_mdb/views.py
./gstudio_mdb/templates/gstudio_mdb/base.html
./gstudio_mdb/templates/gstudio_mdb/node_detail.html
./gstudio_mdb/templates/gstudio_mdb/_forms.html
./gstudio_mdb/templates/gstudio_mdb/node_list.html
from django.contrib import admin
from gstudio_mdb.models import Node
admin.site.register(Node)
from django.forms import ModelForm
from gstudio_mdb.models import Comment
from gstudio_mdb.models import Relation
class CommentForm(ModelForm):
def __init__(self, object, *args, **kwargs):
"""Override the default to store the original document
that comments are embedded in.
"""
self.object = object
return super(CommentForm, self).__init__(*args, **kwargs)
def save(self, *args):
"""Append to the comments list and save the node"""
self.object.comments.append(self.instance)
self.object.save()
return self.object
class Meta:
model = Comment
class RelationForm(ModelForm):
def __init__(self, object, *args, **kwargs):
"""Override the default to store the relations as embedded
list.
"""
self.object = object
return super(RelationForm, self).__init__(*args, **kwargs)
def save(self, *args):
"""Append to the relations list and save the node"""
self.object.relations.append(self.instance)
self.object.save()
return self.object
class Meta:
model = Relation
# Django settings for gstudio_mdb project.
import os.path
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'my_tumble_log'
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.4/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Asia/Kolkata'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '(t2(xg3z$a#@$_(y@c()d4yjtefm%r$6sejzu_%k9z!h4q1p&j'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'gstudio_mdb.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'gstudio_mdb.wsgi.application'
#TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# TEMPLATE_DIRS = (
# os.path.join(os.path.realpath(__file__), '/templates'),
# )
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'gstudio_mdb',
'djangotoolbox',
'django_mongodb_engine',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
<fieldset>
{% for field in form.visible_fields %}
<div class="clearfix {% if field.errors %}error{% endif %}">
{{ field.label_tag }}
<div class="input">
{{ field }}
{% if field.errors or field.help_text %}
<span class="help-inline">
{% if field.errors %}
{{ field.errors|join:' ' }}
{% else %}
{{ field.help_text }}
{% endif %}
</span>
{% endif %}
</div>
</div>
{% endfor %}
{% csrf_token %}
<div style="display:none">{% for h in form.hidden_fields %} {{ h }}{% endfor %}</div>
</fieldset>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GNOWSYS Node Description Framework </title>
<link href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.css" rel="stylesheet">
<style>.content {padding-top: 80px;}</style>
</head>
<body>
<div class="topbar">
<div class="fill">
<div class="container">
<h1><a href="/" class="brand">NDF: Node Description
Framework</a> </h1>
</div>
</div>
</div>
<div class="container">
<div class="content">
{% block page_header %}{% endblock %}
{% block content %}{% endblock %}
</div>
</div>
<hr>
<center>Powered by Python, Django, MongoDB, GNOWSYS</center>
</body>
</html>
{% extends "gstudio_mdb/base.html" %}
{% block page_header %}
<div class="page-header">
<h1>{{ node.title }}</h1>
</div>
{% endblock %}
{% block content %}
<p>{{ node.description }}<p>
<p>created by {{ node.author }} {{ node.created_at }}</p>
<hr>
<h2>Relations</h2>
{% if node.relations %}
{% for relation in node.relations %}
<p><strong>{{ relation.author }}</strong> <small>on {{ relation.created_at }}</small></p>
{{ relation.name }}
{% endfor %}
{% else %}
<p> This node is an orphan. Be the first to link it with other
nodes!</p>
{% endif %}
<h2>Add a relation</h2>
<form action="." method="post">
{% include "gstudio_mdb/_forms.html" %}
<div class="actions">
<input type="submit" class="btn primary" value="relation">
</div>
</form>
{% endblock %}
{% extends "gstudio_mdb/base.html" %}
{% block page_header %}
<div class="page-header">
<h1>{{ node.title }}</h1>
</div>
{% endblock %}
{% block content %}
<p>{{ node.description }}<p>
<p>created by {{ node.author }} {{ node.created_at }}</p>
<hr>
<h2>Comments</h2>
{% if node.comments %}
{% for comment in node.comments %}
<p>by <strong>{{ comment.author }}</strong> <small>on {{ comment.created_at }}</small></p>
<p> {{ comment.body }} </p></br>
{% endfor %}
{% else %}
<p> No comments posted. Be the first to comment!</p>
{% endif %}
<h2>Add a comment</h2>
<form action="." method="post">
{% include "gstudio_mdb/_forms.html" %}
<div class="actions">
<input type="submit" class="btn primary" value="comment">
</div>
</form>
{% endblock %}
{% extends "gstudio_mdb/base.html" %}
{% block content %}
{% for node in node_list %}
<h2><a href="{% url node slug=node.slug %}">{{ node.title }}</a></h2>
<p>{{ node.body|truncatewords:20 }}</p>
<p>
{{ node.created_at }} |
{% with total=node.comments|length %}
{{ total }} comment{{ total|pluralize }}
{% endwith %}
</p>
{% endfor %}
<p> Use <a href="admin">admin</a> link to
create nodes</p>
{% endblock %}
from django.conf.urls.defaults import patterns, include, url
from django.views.generic import ListView, DetailView
from django.views.generic import TemplateView
from gstudio_mdb.models import Node
from gstudio_mdb.views import NodeDetailView, NodeRelationsView
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', ListView.as_view(
queryset=Node.objects.all(),
context_object_name="node_list"),
name="home"
),
url(r'^node/(?P<slug>[a-zA-Z0-9-]+)/$', NodeDetailView.as_view(
queryset=Node.objects.all(),
context_object_name="node"),
name="node"
),
url(r'^admin/', include(admin.site.urls)),
)
# Create your views here.
from django.http import HttpResponseRedirect
from django.views.generic import DetailView
from django.views.generic import TemplateView
from gstudio_mdb.forms import CommentForm
from gstudio_mdb.forms import RelationForm
# class NodeView(TemplateView):
# template_name = "base.html"
class NodeDetailView(DetailView):
methods = ['get', 'post']
def get(self, request, *args, **kwargs):
self.object = self.get_object()
form = CommentForm(object=self.object)
context = self.get_context_data(object=self.object, form=form)
return self.render_to_response(context)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = CommentForm(object=self.object, data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(self.object.get_absolute_url())
context = self.get_context_data(object=self.object, form=form)
return self.render_to_response(context)
class NodeRelationsView(DetailView):
methods = ['get', 'post']
def get(self, request, *args, **kwargs):
self.object = self.get_object()
form = RelationForm(object=self.object)
context = self.get_context_data(object=self.object, form=form)
return self.render_to_response(context)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = RelationForm(object=self.object, data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(self.object.get_absolute_url())
context = self.get_context_data(object=self.object, form=form)
return self.render_to_response(context)
"""
WSGI config for gstudio_mdb project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gstudio_mdb.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gstudio_mdb.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment