Browse Source

[untested] Implements dyncode update in lodelsites

Implements dyncode update for handled sites in lodelsites. solves #260
Yann Weber 8 years ago
parent
commit
816d99adf6

+ 6
- 1
lodel/plugins/lodelsite_datasource/main.py View File

@@ -8,6 +8,7 @@ LodelContext.expose_modules(globals(), {
8 8
     'lodel.settings': 'Settings'})
9 9
 
10 10
 from .fs_utils import *
11
+from .sites_utils import update_dyncode
11 12
 from .specs import check as check_leo
12 13
 from .exceptions import *
13 14
 
@@ -110,7 +111,9 @@ existing site with a new name')
110 111
 
111 112
         for data in datas:
112 113
             if 'em_groups' in upd_datas:
114
+                #groups update, dyncode refresh
113 115
                 groups = upd_datas['em_groups']
116
+                update_dyncode(data['shortname'], upd_datas['em_groups'])
114 117
             else:
115 118
                 groups = data['em_groups']
116 119
             if 'extensions' in upd_datas:
@@ -142,7 +145,9 @@ already exists' % (new_datas['shortname']))
142 145
             new_datas['shortname'],
143 146
             new_datas['em_groups'],
144 147
             new_datas['extensions'])
145
-        return self._child_ds.insert(target, new_datas)
148
+        ret = self._child_ds.insert(target, new_datas)
149
+        update_dyncode(new_datas['shortname'], new_datas['em_groups'])
150
+        return ret
146 151
 
147 152
     ## @brief Inserts a list of records in a given collection
148 153
     #@note Here is a simple implementation : a for loop triggering

+ 42
- 0
lodel/plugins/lodelsite_datasource/sites_utils.py View File

@@ -0,0 +1,42 @@
1
+##
2
+#@note in itself thos method should be implemented as custom methods
3
+#for Lodelsite leobject. The current state of the project do not allow
4
+#to do this easily. So you will found them here for the moment....
5
+
6
+import os.path
7
+from lodel import buildconf #safe even outside any context
8
+
9
+from lodel.context import LodelContext
10
+
11
+
12
+##@brief Update the leapi_dyncode.py file for a given site
13
+#
14
+#Follows expectation of LodelContext :
15
+#The leapi_dyncode.py file will be stored in site's context dir
16
+#@param site_name str : site shortname
17
+#@param em_groups list : list of em groups to enable in the dyncode
18
+#@return Nothing
19
+def update_dyncode(site_name, em_groups):
20
+    _, ctx_path = LodelContext.lodelsites_paths()
21
+    dyncode_path = os.path.join(os.path.join(ctx_path, site_name),
22
+        buildconf.MULTISITE_DYNCODE_MODULENAME+'.py')
23
+    LodelContext.expose_module(globals(), {
24
+        'lodel.logger': 'logger',
25
+        'lodel.settings': ['Settings'],
26
+        'lodel.editorial_model.model': ['EditorialModel'],
27
+        'lodel.leapi.lefactory': 'lefactory'}
28
+    
29
+    EditorialModel._override_settings(False, em_groups)
30
+    model = EditorialModel.load(
31
+        Settings.lodelsites.sites_emtranslator,
32
+        filename = Settings.lodelsites.sites_emfile)
33
+    logger.info('EditorialModel loaded for handled site %s' % site_name)
34
+    dyncode = lefactory.dyncode_from_em(model)
35
+        site_name, em_groups))
36
+    with open(dyncode_path, 'w+') as dfp:
37
+        dfp.write(dyncode)
38
+    EditorialModel._override_settings() #Restoring safe values
39
+    logger.info('Dyncode generated for handled site %s' % site_name)
40
+    logger.debug('Dyncode for %s contains those groups : %s' % (
41
+    
42
+    

Loading…
Cancel
Save