Skip to content

Commit

Permalink
Closed #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia committed Jul 18, 2014
1 parent d577ab8 commit b0d5736
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 59 deletions.
9 changes: 3 additions & 6 deletions core/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
32 changes: 16 additions & 16 deletions core/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']):
Expand Down Expand Up @@ -188,19 +188,19 @@ 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):
key = 'url_%s' % i
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
Expand All @@ -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)

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion core/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
""" """
Expand Down
2 changes: 1 addition & 1 deletion core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

16 changes: 16 additions & 0 deletions model/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions routes/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<three>/', methods=['POST', 'GET'])
@content.route('/api/1.0/<three>/<four>', methods=['POST', 'GET'])
Expand Down
42 changes: 21 additions & 21 deletions static/js/admin/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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": []
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions templates/admin/languages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2>{{ g.languages.name }}</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
{% if my.rank == 15 %}
{% if my.rank < 15 %}
<th style="width:5%;"></th>
{% endif %}
<th style="width:15%;">{{ g.languages.code }}</th>
Expand All @@ -27,7 +27,7 @@ <h2>{{ g.languages.name }}</h2>
<tbody>
{% for i, language in enumerate(languages_list) %}
<tr>
{% if my.rank == 15 %}
{% if my.rank < 15 %}
<td>
<input type="checkbox" name="{{ language['code'] }}"
{% if language['code'] == lan %} disabled="disabled" {% endif %}
Expand All @@ -41,7 +41,7 @@ <h2>{{ g.languages.name }}</h2>
{% endfor %}
</tbody>
</table>
{% if my.rank == 15 %}
{% if my.rank < 15 %}
<div>
<button tabindex="20" type="submit" class="button button-submit"> {{ g.admin['save'] }}</button>
</div>
Expand Down

0 comments on commit b0d5736

Please sign in to comment.