Ejemplo n.º 1
0
 def test_change_themecolor_should_change_partnername(self):
     self.set_up()
     assert configuration_provider.get_configuration(
         'AUSGESCHLOSSENE_KATEGORIEN') == ''
     configuration.index(
         PostRequest({
             'action': 'set_ausgeschlossene_kategorien',
             'ausgeschlossene_kategorien': 'Alkohol'
         }))
     assert configuration_provider.get_configuration(
         'AUSGESCHLOSSENE_KATEGORIEN') == 'Alkohol'
Ejemplo n.º 2
0
 def test_change_themecolor_should_change_partnername(self):
     self.set_up()
     assert configuration_provider.get_configuration(
         'THEME_COLOR') == '#00acd6'
     configuration.index(
         PostRequest({
             'action': 'change_themecolor',
             'themecolor': '#000000'
         }))
     assert configuration_provider.get_configuration(
         'THEME_COLOR') == '#000000'
Ejemplo n.º 3
0
def database_instance():
    '''
    returns the actual database instance
    '''
    if not viewcore.DATABASES:
        viewcore.DATABASES = configuration_provider.get_configuration(
            'DATABASES').split(',')

    if viewcore.DATABASE_INSTANCE is None:
        ausgeschlossene_kategorien = set(
            configuration_provider.get_configuration(
                'AUSGESCHLOSSENE_KATEGORIEN').split(','))
        viewcore.DATABASE_INSTANCE = DBManager.read(
            viewcore.DATABASES[0],
            ausgeschlossene_kategorien=ausgeschlossene_kategorien)
    return DATABASE_INSTANCE
Ejemplo n.º 4
0
def handle_request(request, import_prefix='', gemeinsam=False):
    print(request)
    imported_values = pandas.DataFrame([],
                                       columns=('Datum', 'Kategorie', 'Name',
                                                'Wert', ''))
    if request.method == "POST":
        if post_action_is(request, 'load_online_transactions'):
            serverurl = request.values['server']

            serverurl = _add_protokoll_if_needed(serverurl)
            _save_server_creds(serverurl, request.values['email'])

            r = requests.post(serverurl + '/getabrechnung.php',
                              data={
                                  'email': request.values['email'],
                                  'password': request.values['password']
                              })
            print(r.content)

            response = handle_request(PostRequest(
                {'import': r.content.decode("utf-8")}),
                                      import_prefix='Internet')
            r = requests.post(serverurl + '/deleteitems.php',
                              data={
                                  'email': request.values['email'],
                                  'password': request.values['password']
                              })
            return response

        if post_action_is(request, 'load_online_gemeinsame_transactions'):
            serverurl = request.values['server']
            serverurl = _add_protokoll_if_needed(serverurl)
            _save_server_creds(serverurl, request.values['email'])
            print(serverurl)

            online_username = requester.instance().post(
                serverurl + '/getusername.php',
                data={
                    'email': request.values['email'],
                    'password': request.values['password']
                })
            print('online username: '******'/getgemeinsam.php',
                data={
                    'email': request.values['email'],
                    'password': request.values['password']
                })
            print(online_content)

            table = _parse_table(online_content)
            print('table before person mapping', table)
            table.Person = table.Person.map(
                lambda x: viewcore.database_instance().name
                if x == online_username else configuration_provider.
                get_configuration('PARTNERNAME'))
            online_content = "#######MaschinenimportStart\n"
            online_content = online_content + table.to_csv(index=False)
            online_content = online_content + "#######MaschinenimportEnd\n"

            response = handle_request(PostRequest({'import': online_content}),
                                      import_prefix='Internet_Gemeinsam',
                                      gemeinsam=True)

            requester.instance().post(serverurl + '/deletegemeinsam.php',
                                      data={
                                          'email': request.values['email'],
                                          'password':
                                          request.values['password']
                                      })
            return response

        elif post_action_is(request, 'set_kategorien'):
            kategorien = ','.join(
                sorted(viewcore.database_instance().einzelbuchungen.
                       get_kategorien_ausgaben(
                           hide_ausgeschlossene_kategorien=True)))
            serverurl = request.values['server']

            serverurl = _add_protokoll_if_needed(serverurl)
            _save_server_creds(serverurl, request.values['email'])

            serverurl = serverurl + '/setkategorien.php'

            requester.instance().post(serverurl,
                                      data={
                                          'email': request.values['email'],
                                          'password':
                                          request.values['password'],
                                          'kategorien': kategorien
                                      })
        else:
            print(request.values)
            content = request.values['import'].replace('\r', '')
            FileSystem.instance().write(
                '../Import/' + import_prefix + 'Import_' + str(datetime.now()),
                content)

            imported_values = _parse_table(content)
            datenbank_kategorien = set(viewcore.database_instance().
                                       einzelbuchungen.get_alle_kategorien())
            nicht_passende_kategorien = []
            for imported_kategorie in set(imported_values.Kategorie):
                if imported_kategorie not in datenbank_kategorien:
                    nicht_passende_kategorien.append(imported_kategorie)

            if 'Person' in imported_values.columns:
                gemeinsam = True

            if not nicht_passende_kategorien:
                print('keine unpassenden kategorien gefunden')
                print('beginne mit dem direkten import')
                _import(imported_values, gemeinsam)

                context = viewcore.generate_base_context('import')
                last_elements = []
                for row_index, row in imported_values.iterrows():
                    last_elements.append((row_index, row.Datum, row.Name,
                                          row.Kategorie, row.Wert))
                context['ausgaben'] = last_elements
                return 'import.html', context

            elif _mapping_passt(request.values, nicht_passende_kategorien):
                print(
                    'import kann durchgeführt werden, weil mapping vorhanden')
                imported_values = _map_kategorien(imported_values,
                                                  nicht_passende_kategorien,
                                                  request.values)
                _import(imported_values, gemeinsam)

                context = viewcore.generate_base_context('import')
                last_elements = []
                for row_index, row in imported_values.iterrows():
                    last_elements.append((row_index, row.Datum, row.Name,
                                          row.Kategorie, row.Wert))
                context['ausgaben'] = last_elements

                return 'import.html', context

            print("Nicht passende Kategorien: ", nicht_passende_kategorien)
            options = ['neue Kategorie anlegen']
            for kategorie_option in datenbank_kategorien:
                options.append('als ' + str(kategorie_option) + ' importieren')
            options = sorted(options)
            options.insert(0, 'neue Kategorie anlegen')
            context = viewcore.generate_base_context('import')
            context['element_titel'] = 'Kategorien zuweisen'
            context['unpassende_kategorien'] = nicht_passende_kategorien
            context['optionen'] = options
            context['import'] = request.values['import']
            context['transaction_id'] = 'requested'
            return 'import_mapping.html', context

    context = viewcore.generate_base_context('import')
    context[
        'ONLINE_DEFAULT_SERVER'] = configuration_provider.get_configuration(
            'ONLINE_DEFAULT_SERVER')
    context['ONLINE_DEFAULT_USER'] = configuration_provider.get_configuration(
        'ONLINE_DEFAULT_USER')
    return 'import.html', context
Ejemplo n.º 5
0
def switch_database_instance(database_name):
    ausgeschlossene_kategorien = set(
        configuration_provider.get_configuration(
            'AUSGESCHLOSSENE_KATEGORIEN').split(','))
    viewcore.DATABASE_INSTANCE = DBManager.read(
        database_name, ausgeschlossene_kategorien=ausgeschlossene_kategorien)
Ejemplo n.º 6
0
def design_colors():
    return configuration_provider.get_configuration('DESIGN_COLORS').split(',')
Ejemplo n.º 7
0
def name_of_partner():
    return configuration_provider.get_configuration('PARTNERNAME')
Ejemplo n.º 8
0
def index(request):
    return Response(THEMECSS.replace(
        'THEME_COLOR',
        configuration_provider.get_configuration('THEME_COLOR')),
                    mimetype='text/css')