diff options
Diffstat (limited to 'gstudio')
-rw-r--r-- | gstudio/management/commands/sync-instances.py | 112 | ||||
-rw-r--r-- | gstudio/models.py | 253 | ||||
-rw-r--r-- | gstudio/xmlrpc/__init__.py | 13 | ||||
-rw-r--r-- | gstudio/xmlrpc/metaweblog.py | 116 |
4 files changed, 476 insertions, 18 deletions
diff --git a/gstudio/management/commands/sync-instances.py b/gstudio/management/commands/sync-instances.py new file mode 100644 index 00000000..632e9ef2 --- /dev/null +++ b/gstudio/management/commands/sync-instances.py @@ -0,0 +1,112 @@ +# 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 re +import sys +from datetime import datetime + +from objectapp.models import Gbobject +from objectapp.models import Objecttype +from objectapp.models import Attributetype +from objectapp.models import Relationtype +from objectapp.models import ObjectDoesNotExist + +# from gstudio.xmlrpc.metaweblog import class_checker +from gstudio import models as gstmodels +from objectapp import models as objmodels +import inspect + +from xmlrpclib import DateTime +from xmlrpclib import ServerProxy + +from django.db.utils import IntegrityError + +class Command(BaseCommand): + """Gets all Gbobjects from a specified server""" + option_list = BaseCommand.option_list + ( + make_option("--server", action="store", type="string", + dest="server", help="Specify an ip"),) + + def handle(self, *args, **options): + def class_checker(m): + """Returns a dict which contains all classes of the m module""" + res = {} + for name, obj in inspect.getmembers(m): + if inspect.isclass(obj) and obj.__module__ == m.__name__: + res[name] = obj + return res + + def parse(module=None, instance=None, id=None): + """Parses and saves instances""" + try: + instances = srv.metaWeblog.show_instance(module, instance, id) + + if module == "objectapp.models": + module = objmodels + + if module == "gstudio.models": + module = gstmodels + + for i in instances: + pattern = "^(\d{4})(\d{2})(\d{2}).(\d{2}).(\d{2}).(\d{2})$" + + if "_tags_cache" in i: + del i["_tags_cache"] + + if "_state" in i: + del i["_state"] + + if "_altnames_cache" in i: + del i["_altnames_cache"] + + if "_mptt_cached_fields" in i: + del i["_mptt_cached_fields"] + + def group(value): + return value.group(1, 2, 3, 4, 5, 6) + + def str_to_int(string): + return [int(x) for x in string] + + for key in i.keys(): + # Weird check for DateTime objects + if "make_comparable" in dir(i[key]): + dt = DateTime().make_comparable(i[key])[1] + dt = str_to_int(group(re.search(pattern, dt))) + + i[key] = datetime(*dt) + + class_checker(module)[instance](**i).save() + + except (ObjectDoesNotExist, IntegrityError): + sys.stderr.write("Object matching query does not exist\n") + + except ValueError: + sys.stderr.write("Object already exists\n") + + server = options["server"] + srv = ServerProxy(server, allow_none=True) + + objcc = class_checker(objmodels) + gstcc = class_checker(gstmodels) + + for i in objcc.keys(): + parse("objectapp.models", i) + + for i in gstcc.keys(): + parse("gstudio.models", i) diff --git a/gstudio/models.py b/gstudio/models.py index e7085389..17fa459c 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -166,6 +166,12 @@ attr_counter = -1 class Author(User): """Proxy Model around User""" + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Author", + help_text=("class' id"), + max_length=255) + objects = models.Manager() published = AuthorPublishedManager() @@ -192,6 +198,12 @@ class NID(models.Model): the network, including edges. Edges are also first class citizens in the gnowledge base. """ + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="NID", + help_text=("class' id"), + max_length=255) + title = models.CharField(_('title'), help_text=_('give a name to the node'), max_length=255) last_update = models.DateTimeField(_('last update'), default=datetime.now) creation_date = models.DateTimeField(_('creation date'), @@ -421,6 +433,12 @@ class Node(NID): Super class """ + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Node", + help_text=("class' id"), + max_length=255) + altnames = TagField(_('alternate names'), help_text=_('alternate names if any'), blank=True, null=True) plural = models.CharField(_('plural name'), help_text=_('plural form of the node name if any'), max_length=255, blank=True, null=True) rating = RatingField(range=5, can_change_vote = True, help_text=_('your rating'), blank=True, null=True) @@ -457,6 +475,11 @@ class Metatype(Node): Metatype object for Nodetype """ + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Metatype", + help_text=("class' id"), + max_length=255) description = models.TextField(_('description'), blank=True, null=True) parent = models.ForeignKey('self', null=True, blank=True, verbose_name=_('parent metatype'), related_name='children') @@ -658,7 +681,13 @@ class Metatype(Node): super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. class Edge(NID): - + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Edge", + help_text=("class' id"), + max_length=255) + metatypes = models.ManyToManyField(Metatype, verbose_name=_('member of metatypes'), related_name='member_edges', blank=True, null=True) @@ -684,7 +713,11 @@ class Nodetype(Node): Model design for publishing nodetypes. Other nodetypes inherit this class. """ - + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Nodetype", + help_text=("class' id"), + max_length=255) STATUS_CHOICES = ((DRAFT, _('draft')), (HIDDEN, _('hidden')), @@ -1335,6 +1368,12 @@ class Objecttype(Nodetype): Object class ''' + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Objecttype", + help_text=("class' id"), + max_length=255) + def __unicode__(self): displayname="OT: "+self.title return displayname @@ -1663,6 +1702,13 @@ class Relationtype(Nodetype): ''' Properties with left and right subjects (Binary relations) are defined in this class. ''' + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Relationtype", + help_text=("class' id"), + max_length=255) + 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='Applicable node types for left role') @@ -1881,6 +1927,13 @@ class Attributetype(Nodetype): The rest of the fields may be required depending on what type of field is selected for datatype. ''' + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Attributetype", + help_text=("class' id"), + max_length=255) + subjecttype = models.ForeignKey(NID, related_name="subjecttype_of", verbose_name='subject type name') applicable_nodetypes = models.CharField(max_length=2,choices=NODETYPE_CHOICES,default='OT', verbose_name='applicable nodetypes') dataType = models.CharField(max_length=2, choices=FIELD_TYPE_CHOICES,default='01', verbose_name='data type of value') @@ -2081,6 +2134,12 @@ class Relation(Edge): Relations, instances of relationtypes ''' + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Relation", + help_text=("class' id"), + max_length=255) + left_subject_scope = models.CharField(max_length=50, verbose_name='subject scope or qualification', null=True, blank=True) left_subject = models.ForeignKey(NID, related_name="left_subject_of", verbose_name='subject name') relationtype_scope = models.CharField(max_length=50, verbose_name='relation scope or qualification', null=True, blank=True) @@ -2191,6 +2250,12 @@ class Attribute(Edge): nodetypes. ''' + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Attribute", + help_text=("class' id"), + max_length=255) + subject_scope = models.CharField(max_length=50, verbose_name='subject scope or qualification', null=True, blank=True) subject = models.ForeignKey(NID, related_name="subject_of", verbose_name='subject name') attributetype_scope = models.CharField(max_length=50, verbose_name='property scope or qualification', null=True, blank=True) @@ -2278,6 +2343,12 @@ class Attribute(Edge): class AttributeCharField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeCharField", + help_text=("class' id"), + max_length=255) + value = models.CharField(max_length=100, verbose_name='string') def __unicode__(self): @@ -2300,6 +2371,12 @@ class AttributeCharField(Attribute): class AttributeTextField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeTextField", + help_text=("class' id"), + max_length=255) + value = models.TextField(verbose_name='text') def __unicode__(self): @@ -2319,6 +2396,13 @@ class AttributeTextField(Attribute): class AttributeIntegerField(Attribute): + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeIntegerField", + help_text=("class' id"), + max_length=255) + value = models.IntegerField(max_length=100, verbose_name='Integer') def __unicode__(self): @@ -2340,6 +2424,13 @@ class AttributeIntegerField(Attribute): class AttributeCommaSeparatedIntegerField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeComma" + + "SeparatedIntegerField", + help_text=("class' id"), + max_length=255) + value = models.CommaSeparatedIntegerField(max_length=100, verbose_name='integers separated by comma') def __unicode__(self): @@ -2360,6 +2451,12 @@ class AttributeCommaSeparatedIntegerField(Attribute): class AttributeBigIntegerField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeBigIntegerField", + help_text=("class' id"), + max_length=255) + value = models.BigIntegerField(max_length=100, verbose_name='big integer') def __unicode__(self): @@ -2381,6 +2478,13 @@ class AttributeBigIntegerField(Attribute): class AttributePositiveIntegerField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributePositive" + + "IntegerField", + help_text=("class' id"), + max_length=255) + value = models.PositiveIntegerField(max_length=100, verbose_name='positive integer') def __unicode__(self): @@ -2402,6 +2506,12 @@ class AttributePositiveIntegerField(Attribute): class AttributeDecimalField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeDecimalField", + help_text=("class' id"), + max_length=255) + value = models.DecimalField(max_digits=3, decimal_places=2, verbose_name='decimal') def __unicode__(self): @@ -2420,6 +2530,12 @@ class AttributeDecimalField(Attribute): class AttributeFloatField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeFloatField", + help_text=("class' id"), + max_length=255) + value = models.FloatField(max_length=100, verbose_name='number as float') def __unicode__(self): @@ -2441,6 +2557,12 @@ class AttributeFloatField(Attribute): class AttributeBooleanField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeBooleanField", + help_text=("class' id"), + max_length=255) + value = models.BooleanField(verbose_name='boolean') def __unicode__(self): @@ -2460,6 +2582,12 @@ class AttributeBooleanField(Attribute): class AttributeNullBooleanField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeNullBooleanField", + help_text=("class' id"), + max_length=255) + value = models.NullBooleanField(verbose_name='true false or unknown') def __unicode__(self): @@ -2481,6 +2609,12 @@ class AttributeNullBooleanField(Attribute): class AttributeDateField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeDateField", + help_text=("class' id"), + max_length=255) + value = models.DateField(max_length=100, verbose_name='date') def __unicode__(self): @@ -2502,6 +2636,12 @@ class AttributeDateField(Attribute): class AttributeDateTimeField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeDateTimeField", + help_text=("class' id"), + max_length=255) + value = models.DateTimeField(max_length=100, verbose_name='date time') def __unicode__(self): @@ -2523,6 +2663,12 @@ class AttributeDateTimeField(Attribute): class AttributeTimeField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeTimeField", + help_text=("class' id"), + max_length=255) + value = models.TimeField(max_length=100, verbose_name='time') def __unicode__(self): @@ -2544,6 +2690,12 @@ class AttributeTimeField(Attribute): class AttributeEmailField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeEmailField", + help_text=("class' id"), + max_length=255) + value = models.EmailField(max_length=100,verbose_name='value') def __unicode__(self): @@ -2565,6 +2717,12 @@ class AttributeEmailField(Attribute): class AttributeFileField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeFileField", + help_text=("class' id"), + max_length=255) + value = models.FileField(upload_to='media/'+UPLOAD_TO, verbose_name='file') def __unicode__(self): @@ -2586,6 +2744,12 @@ class AttributeFileField(Attribute): class AttributeFilePathField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeFilePathField", + help_text=("class' id"), + max_length=255) + value = models.FilePathField(verbose_name='path of file') def __unicode__(self): @@ -2607,6 +2771,12 @@ class AttributeFilePathField(Attribute): class AttributeImageField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeImageField", + help_text=("class' id"), + max_length=255) + value = models.ImageField(upload_to = UPLOAD_TO, verbose_name='image') def __unicode__(self): @@ -2628,6 +2798,12 @@ class AttributeImageField(Attribute): class AttributeURLField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeURLField", + help_text=("class' id"), + max_length=255) + value = models.URLField(max_length=100, verbose_name='url') def __unicode__(self): @@ -2649,6 +2825,12 @@ class AttributeURLField(Attribute): class AttributeIPAddressField(Attribute): + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeIPAddressField", + help_text=("class' id"), + max_length=255) + value = models.IPAddressField(max_length=100, verbose_name='ip address') def __unicode__(self): @@ -2675,6 +2857,13 @@ class Processtype(Nodetype): A kind of nodetype for defining processes or events or temporal objects involving change. """ + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Processtype", + help_text=("class' id"), + max_length=255) + changing_attributetype_set = models.ManyToManyField(Attributetype, null=True, blank=True, verbose_name=_('attribute set involved in the process'), related_name=' changing_attributetype_set_of') @@ -2714,6 +2903,11 @@ class Systemtype(Nodetype): class to organize Systems """ + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Systemtype", + help_text=("class' id"), + max_length=255) nodetype_set = models.ManyToManyField(Nodetype, related_name="nodetype_set_of", verbose_name='Possible edges in the system', blank=True, null=False) @@ -2759,6 +2953,13 @@ class AttributeSpecification(Node): proposition but a description, which can be used as a subject in another sentence. """ + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="AttributeSpecification", + help_text=("class' id"), + max_length=255) + attributetype = models.ForeignKey(Attributetype, verbose_name='property name') subjects = models.ManyToManyField(NID, related_name="subjects_attrspec_of", verbose_name='subjects') metatypes=models.ManyToManyField(Metatype,verbose_name=_('member of metatypes'), @@ -2804,6 +3005,13 @@ class RelationSpecification(Node): """ specifying a relation with a subject """ + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="RelationSpecification", + help_text=("class' id"), + max_length=255) + relationtype = models.ForeignKey(Relationtype, verbose_name='relation name') subjects = models.ManyToManyField(NID, related_name="subjects_in_relspec", verbose_name='subjects') metatypes=models.ManyToManyField(Metatype,verbose_name=_('member of metatypes'), @@ -2847,6 +3055,13 @@ class NodeSpecification(Node): """ A node specified (described) by its relations or attributes or both. """ + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="NodeSpecification", + help_text=("class' id"), + max_length=255) + subject = models.ForeignKey(Node, related_name="subject_nodespec", verbose_name='subject name') relations = models.ManyToManyField(Relation, related_name="relations_in_nodespec", verbose_name='relations used to specify the domain') attributes = models.ManyToManyField(Attribute, related_name="attributes_in_nodespec", verbose_name='attributes used to specify the domain') @@ -2895,6 +3110,12 @@ class Expression(Node): Expression constructor """ + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Expression", + help_text=("class' id"), + max_length=255) + left_term = models.ForeignKey(NID, related_name="left_term_of", verbose_name='left term name') relationtype = models.ForeignKey(Relationtype, verbose_name='relation name') right_term = models.ForeignKey(NID, related_name="right_term_of", verbose_name='right term name') @@ -2937,6 +3158,13 @@ class Union(Node): """ union of two classes """ + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Union", + help_text=("class' id"), + max_length=255) + nodetypes = models.ManyToManyField(Nodetype, related_name = 'union_of', verbose_name='node types for union') metatypes=models.ManyToManyField(Metatype,verbose_name=_('member of metatypes'), related_name='member_unions', @@ -2969,6 +3197,13 @@ class Complement(Node): """ complement of a class """ + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Complement", + help_text=("class' id"), + max_length=255) + nodetypes = models.ManyToManyField(Nodetype, related_name = 'complement_of', verbose_name='complementary nodes') metatypes=models.ManyToManyField(Metatype,related_name='meta_complement',verbose_name=_('Metanodes'), blank=True, null= True) @@ -3001,6 +3236,13 @@ class Intersection(Node): """ Intersection of classes """ + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Intersection", + help_text=("class' id"), + max_length=255) + nodetypes = models.ManyToManyField(Nodetype, related_name = 'intersection_of', verbose_name='intersection of classes') metatypes=models.ManyToManyField(Metatype,verbose_name=_('member of metatypes'), related_name='member_intersectn', @@ -3079,6 +3321,13 @@ post_save.connect(ping_external_urls_handler, sender=Nodetype, class Peer(User): """Subclass for non-human users""" + + def __init__(self): + self.identifier = models.CharField(("identifier"), + default="Peer", + help_text=("class' id"), + max_length=255) + def __unicode__(self): return self.ip diff --git a/gstudio/xmlrpc/__init__.py b/gstudio/xmlrpc/__init__.py index 9b91635d..351ca471 100644 --- a/gstudio/xmlrpc/__init__.py +++ b/gstudio/xmlrpc/__init__.py @@ -126,10 +126,13 @@ GSTUDIO_XMLRPC_METAWEBLOG = [ 'metaWeblog.setRelation'), ('gstudio.xmlrpc.metaweblog.get_gbobject_neighbourhood', 'metaWeblog.getGbobjectNeighbourhood'), - ('gstudio.xmlrpc.metaweblog.list_id', - 'metaWeblog.list_id'), - ('gstudio.xmlrpc.metaweblog.dict_id', - 'metaWeblog.dict_id')] - + # ('gstudio.xmlrpc.metaweblog.list_id', + # 'metaWeblog.list_id'), + # ('gstudio.xmlrpc.metaweblog.dict_id', + # 'metaWeblog.dict_id'), + ('gstudio.xmlrpc.metaweblog.show_id', + 'metaWeblog.show_id'), + ('gstudio.xmlrpc.metaweblog.show_instance', + 'metaWeblog.show_instance')] GSTUDIO_XMLRPC_METHODS = GSTUDIO_XMLRPC_PINGBACK + GSTUDIO_XMLRPC_METAWEBLOG diff --git a/gstudio/xmlrpc/metaweblog.py b/gstudio/xmlrpc/metaweblog.py index a77ab82a..91d9edad 100644 --- a/gstudio/xmlrpc/metaweblog.py +++ b/gstudio/xmlrpc/metaweblog.py @@ -47,6 +47,7 @@ # OF THE POSSIBILITY OF SUCH DAMAGE. """XML-RPC methods of Gstudio metaWeblog API""" import os +import sys from datetime import datetime from xmlrpclib import Fault from xmlrpclib import DateTime @@ -74,7 +75,10 @@ from django.utils.datastructures import SortedDict from gstudio.models import * from django.contrib.auth.models import User - +import inspect +from gstudio import models as gstmodels +from objectapp import models as objmodels +from objectapp.models import ObjectDoesNotExist # http://docs.nucleuscms.org/blog/12#errorcodes LOGIN_ERROR = 801 @@ -833,15 +837,105 @@ def set_relation(d,obj1,obj2) : except Relationtype.DoesNotExist : return "Relationtype Does Not Exist" -@xmlrpc_func(returns='list') -def list_id(): - """Get a list of Gbobjects' ids""" - return [id.id for id in Gbobject.objects.all()] +# Previous version of the following methods + +# @xmlrpc_func(returns='list') +# def list_id(): +# """Get a list of Gbobjects' ids""" +# return [id.id for id in Gbobject.objects.all()] + +# @xmlrpc_func(returns='struct', args=['string']) +# def dict_id(id=None): +# """Get a Gbobject as a dict or as a list of dicts""" +# if id: +# return Gbobject.objects.get(id="{0}".format(id)) +# else: +# return [dict_id(id) for id in list_id()] + +def class_checker(m): + """Returns a dict which contains all classes of the m module""" + res = {} + for name, obj in inspect.getmembers(m): + if inspect.isclass(obj) and obj.__module__ == m.__name__: + res[name] = obj + return res + +def instance_checker(m, instance, option, id=None): + cc = class_checker(m) + for i in cc.keys(): + if i == instance: + if option == "get": + return cc[i].objects.get(id="{0}".format(id)) + + if option == "all": + return [id.id for id in cc[i].objects.all()] + else: + # http://www.gnu.org/prep/standards/html_node/Errors.html#Errors + sys.stderr.write("metaweblog.py:line872: Wrong arguments\n") + +@xmlrpc_func(returns="struct", args=["string", "string"]) +def show_id(module=None, instance=None): + if (module == "objectapp.models" or module == objmodels) and instance: + return instance_checker(objmodels, instance, "all") + + if (module == "gstudio.models" or module == gstmodels) and instance: + return instance_checker(gstmodels, instance, "all") + + if module == None and instance == None: + def show_all(m): + res = {} + for i in class_checker(m).keys(): + res[i] = show_id(m, i) + return res + + gstres = show_all(gstmodels) + objres = show_all(objmodels) + return gstres, objres -@xmlrpc_func(returns='struct', args=['string']) -def dict_id(id=None): - """Get a Gbobject as a dict or as a list of dicts""" - if id: - return Gbobject.objects.get(id="{0}".format(id)) else: - return [dict_id(id) for id in list_id()] + sys.stderr.write("metaweblog.py:line870: Wrong arguments\n") + +@xmlrpc_func(returns="struct", args=["string", "string", "string"]) +def show_instance(module=None, instance=None, id=None): + try: + if ((module == "objectapp.models" or module == objmodels) and + instance and id): + return instance_checker(objmodels, instance, "get", id) + + if ((module == "gstudio.models" or module == gstmodels) and + instance and id): + return instance_checker(gstmodels, instance, "get", id) + + if ((module == "objectapp.models" or module == objmodels) and + instance): + res = [] + for i in show_id(objmodels, instance): + res.append(instance_checker(objmodels, instance, "get", i)) + return res + + if ((module == "gstudio.models" or module == gstmodels) and + instance): + res = [] + for i in show_id(gstmodels, instance): + res.append(instance_checker(gstmodels, instance, "get", i)) + return res + + if module == None and instance == None and id == None: + def show_all(m, index): + res = [] + for k in show_id()[index].keys(): + for v in show_id()[index][k]: + res.append(show_instance(m, k, v)) + return res + + res = [] + res.append(show_all(gstmodels, 0)) + res.append(show_all(objmodels, 1)) + return res + + else: + sys.stderr.write("metaweblog.py:line898: Wrong arguments\n") + + except ObjectDoesNotExist: + sys.stderr.write("metaweblog.py:line901: " + + "Object matching query does not exist\n") |