Exemplo n.º 1
0
def count_all_selected():
    dsh_django_utils.debug_event('count_all_selected: entered...', 11)
    propagate_selections()
    d = {}
    for tableName,tableInfo in allDbTables.iteritems():
        d[tableName] = count_selected(tableInfo[0])
    return d
Exemplo n.º 2
0
def add_to_tar(fileToAdd, tarFilePath):
    """adds fileToAdd to tarFilePath."""

    tarBin = dsh_django_config.lookup('TAR_PATH')
    mediaDir = dsh_config.lookup('MEDIA_DIR')
    
    try:
        os.chdir(mediaDir)

        if not dsh_utils.is_valid_file(fileToAdd, silent=True):
            message = 'dsh_dump.add_to_tar: invalid file: ' + fileToAdd
            tarMsg = dsh_utils.red_error_break_msg(message)
            dsh_django_utils.error_event(message, errorLevel='ERR')
            return (False, tarMsg)
        
        command = tarBin + ' rf ' + tarFilePath + ' ' + fileToAdd
        dsh_django_utils.debug_event(
            'dsh_dump.add_to_tar: command: ' + command, 8)
        result = dsh_utils.try_execute(command)
        if result == None:
            message = 'dsh_dump.add_to_tar: tar problem: ' + command
            dsh_django_utils.error_event(message, errorLevel='CRT')
            return (False, dsh_utils.red_error_break_msg(message))
        return (True, '')
    
    except:
        message = 'dsh_dump.add_to_tar: unknown tar problem: ' + command
        dsh_django_utils.error_event(message, errorLevel='CRT')
        return (False, dsh_utils.red_error_break_msg(message))
Exemplo n.º 3
0
def propagate_selections():
    #
    # mark parent organizations of selected persons selected.
    # need to do more.
    #
    mark_selected_foreign(dvoice.db.models.Item, 'owner')
    mark_selected_foreign(dvoice.db.models.Item, 'intended_audience',
                          kind='many')
    mark_selected_foreign(dvoice.db.models.Item, 'i05')
    dsh_django_utils.debug_event(
        'propagate_selections: mark event owner...', 11)
    mark_selected_foreign(dvoice.db.models.Event, 'owner')
    mark_selected_foreign(dvoice.db.models.Person, 'organization')
    mark_selected_foreign(dvoice.db.models.Item, 'key_words', kind='many')

    # new foreign markers: 10-06-09
    mark_selected_foreign(dv2.db.models.Organization, 'org_key_word')
    mark_selected_foreign(dv2.db.models.Person, 'person_key_words', kind='many')
    mark_selected_foreign(dv2.db.models.Item, 'i06')
    mark_selected_foreign(dv2.db.models.Item, 'i07')
    mark_selected_foreign(dv2.db.models.Item, 'i08')
    mark_selected_foreign(dv2.db.models.Item, 'i13', kind='many')
    mark_selected_foreign(dv2.db.models.Item, 'i14', kind='many')
    mark_selected_foreign(dv2.db.models.Item, 'i15', kind='many')
    mark_selected_foreign(dv2.db.models.Item, 'i16', kind='many')
Exemplo n.º 4
0
def select_one(request, whatKind, dshUid):
    """this is called by the javascript responding to clicking on
    a selection box.
    the javascript expects to see the string of either
    'True' or 'False'
    if 'True', the javascript changes the icon to a checkmark.
    'whatKind' is like 'item' or 'person'.
    """
    #
    # I'm going to allow non-root to select.
    # they can even show selections.
    # but they can't dump.
    #
    #if dsh_django_request.deny_it(request):
    #    return HttpResponse('False')

    dsh_django_utils.debug_event(
        'views.select_one: entered: ' + whatKind + ' ' + dshUid, 12)

    if not dsh_dump.allDbTables.has_key(whatKind):
        dsh_django_utils.error_event(
            'views.select_one: wrong kind: ' + repr(whatKind),
            errorLevel='CRT')
        return HttpResponse('False')
    
    dbTable = dsh_dump.allDbTables[whatKind][0]
    
    if dsh_dump.select_box(dbTable, dshUid):
        return HttpResponse('True')
    return HttpResponse('False')
Exemplo n.º 5
0
def mark_selected_foreign(thisTable, foreignKeyFieldName,
                          kind='single'):
    """thisTable is something like Person.
    foreignKeyFieldName is 'organization'.
    this function will mark all the parent organizations of the
    selected persons selected as well.
    kind is either 'single' or 'many'.
    'single for single foreign keys.
    'many' for many-to-many relationships.
    """
    
    selectedObjs = thisTable.objects.filter(u17=True)
    if not selectedObjs:
        return
    
    for obj in selectedObjs:
        try:
            fk = getattr(obj, foreignKeyFieldName)
        except:
            dsh_django_utils.error_event(
                'dsh_dump.mark_selected_foreign: getattr failed on: ' + \
                obj.dsh_uid, errorLevel='CRT')
            continue
        if not fk:
            #
            # maybe the foreign key is null, that could be ok sometimes.
            #
            dsh_django_utils.debug_event(
                'dsh_dump.mark_selected_foreign: no fk.', 11)
            continue

        #
        # finally mark the foreign key object(s) selected.
        #
        if kind == 'single':
            if fk.u17:
                continue
            fk.u17 = True
            fk.save()
            dsh_django_utils.debug_event(
                'dsh_dump.mark_selected_foreign: marking active: ' +
                fk.dsh_uid, 11)
            continue
        
        if kind == 'many':
            objs = fk.all()
            for obj in objs:
                if obj.u17:
                    continue
                obj.u17 = True
                obj.save()
            continue
Exemplo n.º 6
0
def propagate_selections():
    #
    # mark parent organizations of selected persons selected.
    # need to do more.
    #
    mark_selected_foreign(dvoice.db.models.Item, 'owner')
    mark_selected_foreign(dvoice.db.models.Item, 'intended_audience',
                          kind='many')
    mark_selected_foreign(dvoice.db.models.Item, 'i05')
    dsh_django_utils.debug_event(
        'propagate_selections: mark event owner...', 11)
    mark_selected_foreign(dvoice.db.models.Event, 'owner')
    mark_selected_foreign(dvoice.db.models.Person, 'organization')
    mark_selected_foreign(dvoice.db.models.Item, 'key_words', kind='many')
Exemplo n.º 7
0
def dump_one(obj, define, tarPath):
    """called by dump_selected() below, dumps one django object into a
    dump file.
    obj is an object retrieved from django db.
    each dumped object is a dictionary.  of the form:
    FieldName: [FieldType, FieldValue],
    'define' is the object definition coming from dsh_dump_models.py.
    it's a dictionary, of the form:
    FieldName: [FieldType],
    """

    errorMsg = ''
    ans = '{\n'
    for fieldName,specs in define.iteritems():
        fieldType = specs[0]

        errorMsg += dsh_utils.black_break_msg_debug(
            'loop iteration: ' + fieldName + ' - ' + fieldType, 124)
        
        try:
            value = getattr(obj, fieldName)
        except:
            message = 'dsh_dump.dump_one: exception: ' + fieldName + '.  '
            dsh_django_utils.error_event(message, errorLevel='CRT')
            errorMsg += dsh_utils.red_error_break_msg(message)
            continue

        if fieldType == 'StrType':
            if not value:
                continue
            #
            # escape the double quote character.
            #
            value = value.replace('"', '\\"')
            oneField = "    '%s': ['%s', \"\"\"%s\"\"\"],\n" % \
                       (fieldName, fieldType, value)
            ans += oneField
            continue
            
        if fieldType == 'BoolType':
            oneField = "    '%s': ['%s', %s],\n" % \
                       (fieldName, fieldType, repr(value))
            ans += oneField
            continue

        if fieldType == 'IntType':
            oneField = "    '%s': ['%s', %s],\n" % \
                       (fieldName, fieldType, str(value))
            ans += oneField
            continue

        if fieldType == 'DateType':
            if not value:
                continue
            oneField = "    '%s': ['%s', %s],\n" % \
                       (fieldName, fieldType, repr(value))
            ans += oneField
            continue

        if fieldType == 'FileType':
            if not value:
                continue
            dumpFileName = dsh_agi.abs_url_to_relative(value.url)
            dsh_django_utils.debug_event(
                'dsh_dump.dump_one: url: ' + dumpFileName, 8)
            dsh_django_utils.debug_event(
                'dsh_dump.dump_one: tarPath: ' + tarPath, 8)

            success,tarMsg = add_to_tar(dumpFileName, tarPath)
            errorMsg += tarMsg
            if success:
                errorMsg += dsh_utils.black_break_msg(
                    'tar: ' + tarPath + \
                    '   «   ' + \
                    dumpFileName)
            else:
                errorMsg += dsh_utils.red_error_break_msg(
                    'tar command failed on: ' + dumpFileName)
                continue
            
            oneField = "    '%s': ['%s', \"\"\"%s\"\"\"],\n" % \
                       (fieldName, fieldType, dumpFileName)
            ans += oneField
            continue

        if fieldType == 'RequiredForeignOrgType' or \
               fieldType == 'RequiredForeignPersonType':
            if not value:
                errorMsg += dsh_utils.red_error_break_msg(
                    'missing required foreign org. or person.')
                continue
            foreignDshUid = value.dsh_uid

            oneField = "    '%s': ['%s', \"\"\"%s\"\"\"],\n" % \
                       (fieldName, fieldType, foreignDshUid)
            ans += oneField
            continue

        if fieldType == 'OptionalFollowUpsType' or \
               fieldType == 'OptionalOwnerType':
            #
            # like the above, except it's optional.
            # so if it's blank, we don't freak out.
            #
            if not value:
                continue
            foreignDshUid = value.dsh_uid

            oneField = "    '%s': ['%s', \"\"\"%s\"\"\"],\n" % \
                       (fieldName, fieldType, foreignDshUid)
            ans += oneField
            continue

        if fieldType == 'OptionalKeyWordsType' or \
           fieldType == 'OptionalPersonsType':
            #
            # the intended_audience field can be dealt with like this too.
            #
            if not value:
                continue
            dshUidList = get_dsh_uid_list(value)
            if not dshUidList:
                continue
            oneField = "    '%s': ['%s', %s],\n" % \
                       (fieldName, fieldType, repr(dshUidList))
            ans += oneField
            continue

        errorMsg += dsh_utils.red_error_break_msg(
            'unknown field type: ' + fieldType)
        

    ans += '}'
    return (ans, errorMsg)