diff --git a/core/languages.py b/core/languages.py index c3f97fa..c665061 100755 --- a/core/languages.py +++ b/core/languages.py @@ -114,18 +114,15 @@ def all_lang_by_tuple(self): return [ (x , y) for x, y in sorted(names['value'].iteritems())] def update(self): - """ Saves which languages to use in web application """ + """Saves which languages to use in web application.""" for code in LIST_LANGUAGES: if code != g.lang: if code in request.form and 'on' == request.form[code]: check = True else: check = False - # Update the permissions of the languages - # and prepares the message of operation success - set_update = {'$set' : { 'check' : check } } - model.languages.update(code=code, - lanugage=set_update) + language = model.languages.find(code=code, only_one=True) + model.languages.update(language_id=language['_id'], check=check) self.message = g.languages_msg('success_update') self.status = 'msg msg-success' diff --git a/core/pages.py b/core/pages.py index a9be816..f862c93 100755 --- a/core/pages.py +++ b/core/pages.py @@ -132,12 +132,12 @@ def remove(self): def __request_first_block(self): """ """ - form = self.params - old_name = self.page['name'] - self.page['name'] = form['name'] - self.page['from'] = form['from'] + form = self.params + old_name = self.page['name'] + self.page['name'] = form['name'] + self.page['from'] = form['from'] self.page['import'] = form['import'] - self.page['file'] = form['file'] + self.page['file'] = form['file'] # Check that the name field is not empty if not len(form['name']): @@ -188,10 +188,10 @@ def __request_first_block(self): def __request_second_block(self): """ """ - form = self.params - old_url = self.page['url'] - self.page['url'] = {} - self.page['title'] = {} + form = self.params + old_url = self.page['url'] + self.page['url'] = {} + self.page['title'] = {} self.page['description'] = {} for i in range(10): @@ -199,8 +199,8 @@ def __request_second_block(self): if key in self.page: del(self.page[key]) - self.page['url'] = form['url'] - self.page['title'] = form['title'] + self.page['url'] = form['url'] + self.page['title'] = form['title'] self.page['description'] = form['description'] # Get URL, Title and Description in any languages @@ -210,7 +210,7 @@ def __request_second_block(self): error_in = ' ( ' + code + ' )' # If the url is changed - if old_url[code] != self.page['url'][code]: + if old_url.get(code) != self.page['url'].get(code): url_list = self.__get_url_list(code) num_urls = len(url_list) @@ -265,11 +265,11 @@ def __request_values(self): def __get_url_list(self, code): """ """ - url_list = self.page['url'][code].split('/') + url = self.page['url'].get(code, '') + url_list = url.split('/') # Convert list with strings all to lowercase map(lambda x:x.lower(),url_list) # Save the url without slash in the end ( '/' ) - if len(self.page['url'][code]): - if self.page['url'][code][-1] == '/': - url_list.pop() + if len(url) and url[-1] == '/': + url_list.pop() return url_list diff --git a/core/utils/decorators.py b/core/utils/decorators.py index f328da1..977f23f 100644 --- a/core/utils/decorators.py +++ b/core/utils/decorators.py @@ -19,7 +19,7 @@ def get_hash_map(module, lan): if module_map is None: current_app.logger.critical("Important, you have to restore last database!") return None - return { x : y[lan] for x, y in module_map['value'].iteritems() } + return { x : y.get(lan, '') for x, y in module_map['value'].iteritems() } class GetValue(object): """ """ diff --git a/core/utils/utils.py b/core/utils/utils.py index e07c645..ec2a64a 100644 --- a/core/utils/utils.py +++ b/core/utils/utils.py @@ -95,6 +95,6 @@ def get_content_dict(page, code): The key id the name label, and the value is get by the language code used in that moment on the page. """ - content = { x[0]["name"]: x[1]["value"][code] for x in zip(page['labels'], page['content']) } + content = { x[0]["name"]: x[1]["value"].get(code, '') for x in zip(page['labels'], page['content']) } return content diff --git a/model/languages.py b/model/languages.py index df55327..d5f4d5d 100644 --- a/model/languages.py +++ b/model/languages.py @@ -32,6 +32,7 @@ # Imports inside Bombolone from shared import db from model_engine import db_engine +from core.utils import ensure_objectid def find(name=None, code=None, @@ -53,3 +54,18 @@ def find(name=None, only_one=only_one, sorted_by=sorted_by) +def update(language_id=None, value=None, check=None): + """ + """ + if language_id is None: + return False + dict_set = {} + if value: + dict_set["value"] = value + if check: + dict_set["check"] = check + set_language = { + '$set': dict_set + } + db.languages.update({'_id': ensure_objectid(language_id)}, set_language) + return language_id diff --git a/readme.md b/readme.md index 69a71d3..3373abc 100755 --- a/readme.md +++ b/readme.md @@ -65,23 +65,23 @@ but configurable to allow multiple levels of access depending on rank. ## Core Modules -#### Users #### +** Users ** Allows user administration: * Administrators : can create, modify or delete users. * Users : can only read the account list by default. -#### Rank #### +** Rank ** The rank module allows you to see what ranks are available. -#### Pages #### +** Pages ** Allows you to quickly create dynamic and static pages. * Administrators : can create, edit, modify or delete pages. * Users : can edit any content pages by default. -#### Languages #### +** Languages ** From here you can decide which languages you want the site to use. -#### HashTable #### +** HashTable ** With the HashTable module you can create different hashmap be used inside modules or the site. * Administrators : can create, edit, modify or delete hash map. * Users : can edit any content of hash map by default. @@ -149,13 +149,13 @@ fab write_db_in_config ## Tests -#### Python #### +** Python** Run python test ```shell python unit_test.py ``` -#### Js Unit/Integration Tests #### +** Js Unit/Integration Tests ** Before run the test, you need install some dependecies. ```shell # Install Nvm diff --git a/routes/content.py b/routes/content.py index c96c242..b6203f5 100755 --- a/routes/content.py +++ b/routes/content.py @@ -106,15 +106,16 @@ def render_content_page(num_of_path, path): # 2) static page # =============================================================== - title = page_document['title'][code] - description = page_document['description'][code] - content = {} + title = page_document['title'].get(code, '') + description = page_document['description'].get(code, '') + content = {} if page_document['content']: content = get_content_dict(page_document, code) # For every page you must specify the file where you want # to use the contents stored in the database. - return render_template('pages/'+page_document['file']+'.html', **locals()) + template_file = 'pages/{0}.html'.format(page_document['file']) + return render_template(template_file, **locals()) @content.route('/api/1.0//', methods=['POST', 'GET']) @content.route('/api/1.0//', methods=['POST', 'GET']) diff --git a/static/js/admin/pages.js b/static/js/admin/pages.js index 746c254..9e563dd 100644 --- a/static/js/admin/pages.js +++ b/static/js/admin/pages.js @@ -7,7 +7,22 @@ angular.module('bombolone.controllers.pages', []) "$rootScope", "api", function($scope, $resource, $rootScope, api) { - var page_list, page_new, page_view, page_update, params; + var LANGUAGES, page_list, page_new, page_view, page_update, params; + LANGUAGES = { + "ru" : "", + "fr" : "", + "en" : "", + "cn" : "", + "pt" : "", + "no" : "", + "jp" : "", + "de" : "", + "tr" : "", + "it" : "", + "ar" : "", + "es" : "", + "gr" : "" + } $rootScope.admin_module = "pages"; page_new = path.match(/^\/admin\/pages\/new\/?$/i); page_update = path.match(/^\/admin\/pages\/update\/([^\/]+)\/?$/i); @@ -50,18 +65,9 @@ angular.module('bombolone.controllers.pages', []) "name": "", "from": "", "import": "", - "url": { - "it": "", - "en": "" - }, - "title": { - "it": "", - "en": "" - }, - "description": { - "it": "", - "en": "" - }, + "url": LANGUAGES, + "title": LANGUAGES, + "description": LANGUAGES, "content": [], "file": "", "labels": [] @@ -85,14 +91,8 @@ angular.module('bombolone.controllers.pages', []) "type": "text" }; content_item = { - "alias": { - "it": "", - "en": "" - }, - "value": { - "it": "", - "en": "" - } + "alias": LANGUAGES, + "value": LANGUAGES }; $scope.page.labels.push(label_item); $scope.page.content.push(content_item); diff --git a/templates/admin/languages/index.html b/templates/admin/languages/index.html index 557754c..023932e 100755 --- a/templates/admin/languages/index.html +++ b/templates/admin/languages/index.html @@ -11,7 +11,7 @@

{{ g.languages.name }}

- {% if my.rank == 15 %} + {% if my.rank < 15 %} {% endif %} @@ -27,7 +27,7 @@

{{ g.languages.name }}

{% for i, language in enumerate(languages_list) %} - {% if my.rank == 15 %} + {% if my.rank < 15 %}
{{ g.languages.code }}
{{ g.languages.name }} {% endfor %}
- {% if my.rank == 15 %} + {% if my.rank < 15 %}