diff options
author | shefali shetty <sshefali44@gmail.com> | 2012-05-03 12:20:58 +0530 |
---|---|---|
committer | shefali shetty <sshefali44@gmail.com> | 2012-05-03 12:20:58 +0530 |
commit | 974f2f6221459cde5187fa0f60132224a8963b80 (patch) | |
tree | 3acee0ad0e7ea5d12f6e10668989d6d2f7bbe89c /gstudio | |
parent | 7f9656341b47f6e1aeba7c650217f5c654a80005 (diff) | |
parent | c59a5bea01179051d337262751f04a166ae33114 (diff) | |
download | gnowsys-974f2f6221459cde5187fa0f60132224a8963b80.tar.gz |
Merge remote branch 'gn/master'
Diffstat (limited to 'gstudio')
-rw-r--r-- | gstudio/admin/__init__.py | 5 | ||||
-rw-r--r-- | gstudio/admin/attribute.py | 10 | ||||
-rw-r--r-- | gstudio/admin/forms.py | 16 | ||||
-rw-r--r-- | gstudio/admin/relation.py | 15 | ||||
-rw-r--r-- | gstudio/management/commands/peers.py | 23 | ||||
-rw-r--r-- | gstudio/management/commands/register-peer.py | 52 | ||||
-rw-r--r-- | gstudio/models.py | 198 | ||||
-rw-r--r-- | gstudio/views/ajaxviews.py | 23 |
8 files changed, 318 insertions, 24 deletions
diff --git a/gstudio/admin/__init__.py b/gstudio/admin/__init__.py index 030e056..159fcf2 100644 --- a/gstudio/admin/__init__.py +++ b/gstudio/admin/__init__.py @@ -36,6 +36,8 @@ from gstudio.models import AttributeFilePathField from gstudio.models import AttributeImageField from gstudio.models import AttributeURLField from gstudio.models import AttributeIPAddressField +from gstudio.models import Peer + #Admin imports @@ -79,6 +81,7 @@ from gstudio.admin.attribute_ipaddressfield import AttributeIPAddressFieldAdmin + admin.site.register(Objecttype, ObjecttypeAdmin) admin.site.register(Metatype, MetatypeAdmin) admin.site.register(Relationtype, RelationtypeAdmin) @@ -95,6 +98,8 @@ admin.site.register(Union, UnionAdmin) admin.site.register(Complement, ComplementAdmin) admin.site.register(Intersection, IntersectionAdmin) admin.site.register(Expression, ExpressionAdmin) +admin.site.register(Peer) + admin.site.register(AttributeCharField, AttributeCharFieldAdmin) admin.site.register(AttributeTextField, AttributeTextFieldAdmin) diff --git a/gstudio/admin/attribute.py b/gstudio/admin/attribute.py index 336509e..7a34cb8 100644 --- a/gstudio/admin/attribute.py +++ b/gstudio/admin/attribute.py @@ -6,15 +6,23 @@ from django.utils.html import escape from gstudio.admin.forms import AttributeAdminForm from gstudio.models import * import reversion +from django.template.defaultfilters import slugify class AttributeAdmin(reversion.VersionAdmin): + fieldsets=((_('Attribute'),{'fields': ('subject','subject_scope','attributetype','attributetype_scope','svalue','value_scope','last_update','creation_date')}), + +) + + class Media: js = ("gstudio/js/gstudiojs.js",) def save_model(self, request, attribute, form, change): - attribute.title = attribute.composed_attribution + attribute.title = attribute.composed_sentence + attribute.slug = slugify(attribute.title) attribute.save() + diff --git a/gstudio/admin/forms.py b/gstudio/admin/forms.py index 37b578c..a2415c1 100644 --- a/gstudio/admin/forms.py +++ b/gstudio/admin/forms.py @@ -154,7 +154,7 @@ class RelationtypeAdminForm(forms.ModelForm): super(RelationtypeAdminForm, self).__init__(*args, **kwargs) prior = ManyToManyRel(Nodetype, 'id') post = ManyToManyRel(Nodetype, 'id') - + self.fields['priornodes'].widget = RelatedFieldWidgetWrapper( @@ -207,18 +207,6 @@ class RelationAdminForm(forms.ModelForm): AppNodeList = AppNode.objects.all() return AppNodeList - - - - - - - - - - - - class Meta: @@ -289,7 +277,7 @@ class AttributetypeAdminForm(forms.ModelForm): super(AttributetypeAdminForm, self).__init__(*args, **kwargs) prior = ManyToManyRel(Nodetype, 'id') post = ManyToManyRel(Nodetype, 'id') - + self.fields['sites'].initial = [Site.objects.get_current()] self.fields['priornodes'].widget = RelatedFieldWidgetWrapper( self.fields['priornodes'].widget, prior, self.admin_site) diff --git a/gstudio/admin/relation.py b/gstudio/admin/relation.py index 688ad6e..8f112ef 100644 --- a/gstudio/admin/relation.py +++ b/gstudio/admin/relation.py @@ -5,12 +5,25 @@ from django.utils.translation import ugettext_lazy as _ from gstudio.admin.forms import RelationAdminForm import reversion +from django.template.defaultfilters import slugify class RelationAdmin(reversion.VersionAdmin): - fieldsets=((_('Relation'),{'fields': ('title','last_update','creation_date','relationtype_scope','relationtype','left_subject_scope','left_subject' ,'right_subject_scope','right_subject')}), + fieldsets=((_('Relation'),{'fields': ('relationtype','relationtype_scope','left_subject' ,'left_subject_scope','right_subject','right_subject_scope')}), ) + + def get_title(self, edge): + """Return the title with word count and number of comments""" + title = _('%(title)s (%(word_count)i words)') % \ + {'title': nodetype.title, 'word_count': nodetype.word_count} + comments = nodetype.comments.count() + if comments: + return _('%(title)s (%(comments)i comments)') % \ + {'title': title, 'comments': comments} + return title + get_title.short_description = _('title') def save_model(self, request, relation, form, change): relation.title = relation.composed_sentence + relation.slug = slugify(relation.title) relation.save() diff --git a/gstudio/management/commands/peers.py b/gstudio/management/commands/peers.py new file mode 100644 index 0000000..cb79991 --- /dev/null +++ b/gstudio/management/commands/peers.py @@ -0,0 +1,23 @@ +# Copyright (c) 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/>. + +from django.core.management.base import NoArgsCommand +import sys +from gstudio.models import Peer + +class Command(NoArgsCommand): + """Custom manage.py command to show all peers""" + def handle_noargs(self, **options): + sys.stdout.write("{0}\n".format(Peer.objects.all())) diff --git a/gstudio/management/commands/register-peer.py b/gstudio/management/commands/register-peer.py new file mode 100644 index 0000000..a068b2f --- /dev/null +++ b/gstudio/management/commands/register-peer.py @@ -0,0 +1,52 @@ +# Copyright (c) 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/>. + +from django.core.management.base import BaseCommand +from optparse import make_option +import sys +from gstudio.models import Peer + +class Command(BaseCommand): + """Custom manage.py command to register a peer""" + option_list = BaseCommand.option_list + ( + make_option("--ip", action="store", type="string", + dest="ip", help="Specify an IP"), + make_option("--pkey", action="store", type="string", + dest="pkey", help="Specify a public-key")) + + def handle(self, *args, **options): + try: + ip = options["ip"] + pkey = options["pkey"] + + if not ip: + sys.stderr.write("Please specify an IP\n") + sys.exit(2) + + if not pkey: + sys.stderr.write("Please specify a public-key\n") + sys.exit(2) + + pkey = open(options["pkey"]).readline().rstrip() + + except (IOError, TypeError): + sys.stderr.write("Please specify a correct public-key\n") + sys.exit(2) + + ip = Peer(ip="{0}".format(ip)) + ip.save() + + pkey = Peer(pkey="{0}".format(pkey)) + pkey.save() diff --git a/gstudio/models.py b/gstudio/models.py index 8952bde..65262cc 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -106,6 +106,7 @@ import json import reversion from reversion.models import Version from django.core import serializers +from reversion.models import * NODETYPE_CHOICES = ( ('ND', 'Nodes'), @@ -323,6 +324,11 @@ class Node(NID): class Meta: abstract=False + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Node, self).save(*args, **kwargs) # Call the "real" save() method. + + class Edge(NID): @@ -331,6 +337,11 @@ class Edge(NID): class Meta: abstract=False + @reversion.create_revision() + # Save for edge + def save(self, *args, **kwargs): + super(Edge, self).save(*args, **kwargs) # Call the "real" save() method. + class Metatype(Node): @@ -512,6 +523,12 @@ class Metatype(Node): verbose_name = _('metatype') verbose_name_plural = _('metatypes') + # Save for metatype + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. + + @@ -1140,6 +1157,12 @@ class Nodetype(Node): verbose_name_plural = _('node types') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + + # Save for nodetype + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Nodetype, self).save(*args, **kwargs) # Call the "real" save() method. + class Objecttype(Nodetype): @@ -1319,6 +1342,12 @@ class Objecttype(Nodetype): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # Save for Objecttype + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. + + @@ -1328,10 +1357,10 @@ class Relationtype(Nodetype): ''' inverse = models.CharField(_('inverse name'), help_text=_('when subjecttypes are interchanged, what should be the name of the relation type? This is mandatory field. If the relation is symmetric, same name will do.'), max_length=255,db_index=True ) left_subjecttype = models.ForeignKey(NID,related_name="left_subjecttype_of", verbose_name='left role') - left_applicable_nodetypes = models.CharField(max_length=2,choices=NODETYPE_CHOICES,default='OT', verbose_name='Node types for left role') + left_applicable_nodetypes = models.CharField(max_length=2,choices=NODETYPE_CHOICES,default='OT', verbose_name='Applicable node types for left role') left_cardinality = models.IntegerField(null=True, blank=True, verbose_name='cardinality for the left role') right_subjecttype = models.ForeignKey(NID,related_name="right_subjecttype_of", verbose_name='right role') - right_applicable_nodetypes = models.CharField(max_length=2,choices=NODETYPE_CHOICES,default='OT', verbose_name='Node types for right role') + right_applicable_nodetypes = models.CharField(max_length=2,choices=NODETYPE_CHOICES,default='OT', verbose_name='Applicable node types for right role') right_cardinality = models.IntegerField(null=True, blank=True, verbose_name='cardinality for the right role') is_symmetrical = models.NullBooleanField(verbose_name='Is symmetrical?') is_reflexive = models.NullBooleanField(verbose_name='Is reflexive?') @@ -1360,6 +1389,12 @@ class Relationtype(Nodetype): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # Save for Relationtype + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Relationtype, self).save(*args, **kwargs) # Call the "real" save() method. + + class Attributetype(Nodetype): ''' @@ -1403,6 +1438,12 @@ class Attributetype(Nodetype): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + # Save for Attributetype + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method. + + class Relation(Edge): @@ -1493,6 +1534,13 @@ class Relation(Edge): function that composes the right_subject and relation name, as in "x as a friend", "y as a sibling" ''' return '%s as a %s' % (self.right_subject, self.relationtype) + + + # Save for Relation + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Relation, self).save(*args, **kwargs) # Call the "real" save() method. + class Attribute(Edge): @@ -1569,6 +1617,12 @@ class Attribute(Edge): for each in Objecttype.objects.all(): if attr.subjecttype.id == each.id: return each.get_members + + # Save for Attribute + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Attribute, self).save(*args, **kwargs) # Call the "real" save() method. + @@ -1579,12 +1633,23 @@ class AttributeCharField(Attribute): def __unicode__(self): return self.title + + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeCharField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeTextField(Attribute): value = models.TextField(verbose_name='text') def __unicode__(self): return self.title + + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeTextField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeIntegerField(Attribute): value = models.IntegerField(max_length=100, verbose_name='Integer') @@ -1592,6 +1657,12 @@ class AttributeIntegerField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + + + class AttributeCommaSeparatedIntegerField(Attribute): value = models.CommaSeparatedIntegerField(max_length=100, verbose_name='integers separated by comma') @@ -1599,6 +1670,10 @@ class AttributeCommaSeparatedIntegerField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeCommaSeparatedIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeBigIntegerField(Attribute): value = models.BigIntegerField(max_length=100, verbose_name='big integer') @@ -1613,12 +1688,19 @@ class AttributePositiveIntegerField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributePositiveIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeDecimalField(Attribute): value = models.DecimalField(max_digits=3, decimal_places=2, verbose_name='decimal') def __unicode__(self): return self.title + def save(self, *args, **kwargs): + super(AttributeDecimalField, self).save(*args, **kwargs) # Call the "real" save() method. class AttributeFloatField(Attribute): @@ -1627,12 +1709,20 @@ class AttributeFloatField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeFloatField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeBooleanField(Attribute): value = models.BooleanField(verbose_name='boolean') def __unicode__(self): return self.title + def save(self, *args, **kwargs): + super(AttributeBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeNullBooleanField(Attribute): @@ -1641,6 +1731,11 @@ class AttributeNullBooleanField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeNullBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeDateField(Attribute): value = models.DateField(max_length=100, verbose_name='date') @@ -1648,12 +1743,22 @@ class AttributeDateField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeDateField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeDateTimeField(Attribute): value = models.DateTimeField(max_length=100, verbose_name='date time') def __unicode__(self): return self.title + + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeDateTimeField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeTimeField(Attribute): @@ -1662,6 +1767,11 @@ class AttributeTimeField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeTimeField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeEmailField(Attribute): value = models.CharField(max_length=100,verbose_name='value') @@ -1669,6 +1779,11 @@ class AttributeEmailField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeEmailField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeFileField(Attribute): value = models.FileField(upload_to='/media', verbose_name='file') @@ -1676,6 +1791,11 @@ class AttributeFileField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeFileField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeFilePathField(Attribute): value = models.FilePathField(verbose_name='path of file') @@ -1683,6 +1803,11 @@ class AttributeFilePathField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeFilePathField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeImageField(Attribute): value = models.ImageField(upload_to='/media', verbose_name='image') @@ -1690,6 +1815,11 @@ class AttributeImageField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeImageField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeURLField(Attribute): value = models.URLField(max_length=100, verbose_name='url') @@ -1697,6 +1827,11 @@ class AttributeURLField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeURLField, self).save(*args, **kwargs) # Call the "real" save() method. + + class AttributeIPAddressField(Attribute): value = models.IPAddressField(max_length=100, verbose_name='ip address') @@ -1704,6 +1839,11 @@ class AttributeIPAddressField(Attribute): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeIPAddressField, self).save(*args, **kwargs) # Call the "real" save() method. + + class Processtype(Nodetype): @@ -1727,6 +1867,10 @@ class Processtype(Nodetype): verbose_name_plural = _('process types') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Processtype, self).save(*args, **kwargs) # Call the "real" save() method. + @@ -1758,6 +1902,11 @@ class Systemtype(Nodetype): verbose_name_plural = _('system types') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Systemtype, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeSpecification(Node): @@ -1791,6 +1940,12 @@ class AttributeSpecification(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + @reversion.create_revision() + def save(self, *args, **kwargs): + super(AttributeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + + + class RelationSpecification(Node): """ @@ -1814,11 +1969,17 @@ class RelationSpecification(Node): return self.composed_subject + class Meta: verbose_name = _('relation specification') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + @reversion.create_revision() + def save(self, *args, **kwargs): + super(RelationSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + + class NodeSpecification(Node): """ @@ -1850,6 +2011,12 @@ class NodeSpecification(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + @reversion.create_revision() + def save(self, *args, **kwargs): + super(NodeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + + + class Expression(Node): """ @@ -1877,6 +2044,11 @@ class Expression(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Expression, self).save(*args, **kwargs) # Call the "real" save() method. + + class Union(Node): @@ -1888,6 +2060,11 @@ class Union(Node): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Union, self).save(*args, **kwargs) # Call the "real" save() method. + + class Complement(Node): @@ -1899,6 +2076,11 @@ class Complement(Node): def __unicode__(self): return self.title + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Complement, self).save(*args, **kwargs) # Call the "real" save() method. + + class Intersection(Node): """ Intersection of classes @@ -1907,6 +2089,11 @@ class Intersection(Node): def __unicode__(self): return self.title + + @reversion.create_revision() + def save(self, *args, **kwargs): + super(Intersection, self).save(*args, **kwargs) # Call the "real" save() method. + reversion.register(NID) @@ -1959,5 +2146,10 @@ post_save.connect(ping_directories_handler, sender=Nodetype, post_save.connect(ping_external_urls_handler, sender=Nodetype, dispatch_uid='gstudio.nodetype.post_save.ping_external_urls') +class Peer(User): + """Subclass for non-human users""" + def __unicode__(self): + return self.ip - + ip = models.IPAddressField("Peer's IP address") + pkey = models.CharField(("Peer's public-key"), max_length=255) diff --git a/gstudio/views/ajaxviews.py b/gstudio/views/ajaxviews.py index a909db2..3991a89 100644 --- a/gstudio/views/ajaxviews.py +++ b/gstudio/views/ajaxviews.py @@ -76,22 +76,37 @@ def additemdict(sdict,itemtoadd): sdict[itemtoadd.id]=itemtoadd.title return sdict def selectionlist_OT(obj): + # Basically the filter must filter out the OT, their members, the children and members of the children + global rlist # Return all OTs and members of subtypes of OT obs=Objecttype.objects.filter(title=obj) # Get all members of subtypes of each OT if obs: + # Add the items first + for each in obs: + rlist=additemdict(rlist,each) obs=Objecttype.objects.get(title=obj) + # Add the objects first + # for each in obs: + # rlist = additemdict(rlist,each) memobs=obs.get_members if memobs: for each in memobs: rlist=additemdict(rlist,each) childrenots=obs.get_children() + # Add children first + for each in childrenots: + rlist=additemdict(rlist,each) + # Add memebers of each child if childrenots: for eachchild in childrenots: membs=eachchild.ref.get_members for each in membs: rlist=additemdict(rlist,each) + + + return rlist def selectionlist_MT(obj): @@ -308,12 +323,10 @@ def selectionlist_UP(obj): membs=eachchild.objecttypes.all() def selectionlist_OB(obj): global rlist - - obs=Gbobject.objects.filter(title=obj) + obs=Objecttype.objects.get(title=obj) #Get all members of OB - if obs: - obs=Gbobject.objects.get(title=obj) - rlist=additemdict(rlist,obs) + for each in obs.member_objects.all(): + rlist=additemdict(rlist,each) return rlist |