0xGA: Check-in [054e202cac]

Yet another PHP framework, but made for org-mode and geeks.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:abstract sqlite management
Timelines: family | ancestors | descendants | both | narv
Files: files | file ages | folders
SHA1:054e202cac7258d7ba7ddd71cd01ee07e5406455
User & Date: milouse 2014-05-10 16:16:18
Context
2014-05-14
23:00
More complete blog example (with atom feed support, only in french for now...) check-in: 4f674ae9ec user: milouse tags: narv
2014-05-10
16:16
abstract sqlite management check-in: 054e202cac user: milouse tags: narv
15:42
End Sqlite ORM feature check-in: 19b06bb418 user: milouse tags: narv
Changes

Changes to narv.py.

21
22
23
24
25
26
27
28

29
30
31
32
33










34
35

36
37
38
39
40
41
42
...
241
242
243
244
245
246
247
248
249











250
251
252
253
254
255
256
from socketserver import ThreadingMixIn
from configparser import ConfigParser


class DataObject:

    def __init__(self, appname, data=None):
        self.db_model()

        self.appname = appname
        self.errors = []
        self.rowid = 'new'
        self.db_path = 'var/db/{0}.db'.format(self.appname)











        if not os.path.isfile(self.db_path):
            self.db_install()


        if data != None:
            if type(data).__name__ == 'dict':
                if 'rowid' in data:
                    self.rowid = data['rowid']

                for name in self.data_attr:
................................................................................
        return total == 1


    def db_model(self):
        pass


    def db_install(self):
        pass














class ResourceHelper:
    """ Utility to extract and expose various information on resources served """

    content_types = {







|
>





>
>
>
>
>
>
>
>
>
>
|
|
>







 







|
|
>
>
>
>
>
>
>
>
>
>
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
...
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
from socketserver import ThreadingMixIn
from configparser import ConfigParser


class DataObject:

    def __init__(self, appname, data=None):
        self.data_attr = {}

        self.appname = appname
        self.errors = []
        self.rowid = 'new'
        self.db_path = 'var/db/{0}.db'.format(self.appname)

        model = self.db_model()
        if 'table' in model:
            self.tablename = model['table']
        else:
            self.tablename = type(self).__name__.lower()

        if 'model' in model:
            for field in model['model']:
                self.data_attr[field] = None

            if not os.path.isfile(self.db_path):
                self.db_install(model['model'])


        if data != None:
            if type(data).__name__ == 'dict':
                if 'rowid' in data:
                    self.rowid = data['rowid']

                for name in self.data_attr:
................................................................................
        return total == 1


    def db_model(self):
        pass


    def db_install(self, model):
        field_str = ''
        for field in model:
            field_str += '{0} {1}, '.format(field, model[field])

        field_str = field_str[:-2]

        request = 'create table {0} ({1})'.format(self.tablename, field_str)

        logging.debug('[DataObject] Create request: "{0}"'.format(request))

        with sqlite3.connect(self.db_path) as db:
            db.execute(request)



class ResourceHelper:
    """ Utility to extract and expose various information on resources served """

    content_types = {