Пример #1
0
    def handle(self, *app_labels, **options):
        from dockit.schema.loading import get_documents
        format = options.get('format','json')
        indent = options.get('indent',None)
        show_traceback = options.get('traceback', False)

        

        # Check that the serialization format exists; this is a shortcut to
        # avoid collating all the objects and _then_ failing.
        if format not in serializers.get_public_serializer_formats():
            raise CommandError("Unknown serialization format: %s" % format)

        try:
            serializers.get_serializer(format)
        except KeyError:
            raise CommandError("Unknown serialization format: %s" % format)

        # Now collate the objects to be serialized.
        objects = []
        excluded_documents = []
        for document in get_documents():
            if document in excluded_documents:
                continue
            if app_labels and document._meta.app_label not in app_labels:
                continue
            objects.extend(document.objects.all())

        try:
            return serializers.serialize(format, objects, indent=indent)
        except Exception, e:
            if show_traceback:
                raise
            raise CommandError("Unable to serialize database: %s" % e)
Пример #2
0
 def load_from_command_line(cls, arglist, instream=None):
     '''
     usage::
     
         manage.py datatap Document [<app label>, ...] [<collection name>, ...]
     '''
     parser = OptionParser(option_list=cls.command_option_list)
     options, args = parser.parse_args(arglist)
     document_sources = list()
     for arg in args: #list of apps and collection names
         if '.' in arg:
             document_sources.append(get_document(*arg.rsplit(".", 1)))
         else:
             #get docs from appname
             document_sources.extend(get_documents(arg))
     return cls(instream=document_sources, **options.__dict__)
 def load_from_command_line(cls, arglist, instream=None):
     '''
     usage::
     
         manage.py datatap Document [<app label>, ...] [<collection name>, ...]
     '''
     parser = OptionParser(option_list=cls.command_option_list)
     options, args = parser.parse_args(arglist)
     document_sources = list()
     for arg in args:  #list of apps and collection names
         if '.' in arg:
             document_sources.append(get_document(*arg.rsplit(".", 1)))
         else:
             #get docs from appname
             document_sources.extend(get_documents(arg))
     return cls(instream=document_sources, **options.__dict__)
Пример #4
0
    # a list of the ones we're going to create.
    all_perms = set(auth_app.Permission.objects.filter(
        content_type=ctype,
    ).values_list(
        "codename", flat=True
    ))
    
    for codename, name in searched_perms:
        # If the permissions exists, move on.
        if codename in all_perms:
            continue
        p = auth_app.Permission.objects.create(
            codename=codename,
            name=name,
            content_type=ctype
        )
        if verbosity >= 2:
            print "Adding permission '%s'" % p

def on_document_registered(document, **kwargs):
    create_permissions([document], 1)
document_registered.connect(on_document_registered)

try:
    #wrap with commit_on_success as to try to not poison a higher transaction
    commit_on_success(create_permissions)(get_documents(), 1)
except DatabaseError:
    pass


    # Find all the Permissions that have a context_type for a model we're
    # looking for.  We don't need to check for codenames since we already have
    # a list of the ones we're going to create.
    all_perms = set(
        auth_app.Permission.objects.filter(content_type=ctype, ).values_list(
            "codename", flat=True))

    for codename, name in searched_perms:
        # If the permissions exists, move on.
        if codename in all_perms:
            continue
        p = auth_app.Permission.objects.create(codename=codename,
                                               name=name,
                                               content_type=ctype)
        if verbosity >= 2:
            print "Adding permission '%s'" % p


def on_document_registered(document, **kwargs):
    create_permissions([document], 1)


document_registered.connect(on_document_registered)

try:
    #wrap with commit_on_success as to try to not poison a higher transaction
    commit_on_success(create_permissions)(get_documents(), 1)
except DatabaseError:
    pass
Пример #6
0
    # looking for.  We don't need to check for codenames since we already have
    # a list of the ones we're going to create.
    all_perms = set(auth_app.Permission.objects.filter(
        content_type=ctype,
    ).values_list(
        "codename", flat=True
    ))
    
    for codename, name in searched_perms:
        # If the permissions exists, move on.
        if codename in all_perms:
            continue
        p = auth_app.Permission.objects.create(
            codename=codename,
            name=name,
            content_type=ctype
        )
        if verbosity >= 2:
            print "Adding permission '%s'" % p

def on_document_registered(document, **kwargs):
    create_permissions([document], 1)
document_registered.connect(on_document_registered)

try:
    create_permissions(get_documents(), 1)
except DatabaseError:
    pass