Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius')
-rw-r--r--tutorius/vault.py65
1 files changed, 50 insertions, 15 deletions
diff --git a/tutorius/vault.py b/tutorius/vault.py
index fbe9e75..a3b84a4 100644
--- a/tutorius/vault.py
+++ b/tutorius/vault.py
@@ -56,6 +56,7 @@ INI_GUID_PROPERTY = "guid"
INI_NAME_PROPERTY = "name"
INI_XML_FSM_PROPERTY = "fsm_filename"
INI_VERSION_PROPERTY = 'version'
+INI_CATEGORY_PROPERTY = 'category'
INI_FILENAME = "meta.ini"
TUTORIAL_FILENAME = "tutorial.xml"
RESOURCES_FOLDER = 'resources'
@@ -196,7 +197,6 @@ class Vault(object):
@returns a list of Tutorial meta-data (TutorialID, Description,
Rating, Category, PublishState, etc...)
- TODO : Search for tuto caracterised by the entry : OR between [], and between each
The returned dictionnary is of this format : key = property name, value = property value
The dictionnary also contain one dictionnary element whose key is the string 'activities'
@@ -204,25 +204,25 @@ class Vault(object):
value = related activity version number
"""
- # Temp solution for returning all tutorials metadata
-
tutorial_list = []
tuto_guid_list = []
ini_file = SafeConfigParser()
- if keyword == [] and relatedActivityNames == [] and category == []:
- # get all tutorials tuples (name:guid) for all activities and version
- tuto_dict = Vault.list_available_tutorials()
- for id in tuto_dict.keys():
- tuto_guid_list.append(id)
+ # get all tutorials tuples (name:guid) for all activities and version
+ tuto_dict = Vault.list_available_tutorials()
+ for id in tuto_dict.keys():
+ tuto_guid_list.append(id)
- # Find .ini metadata files with the guid list
+ # Find .ini metadata files with the guid list
# Get the guid from the tuto tuples
for guid in tuto_guid_list:
+ addition_flag = True
# Create a dictionnary containing the metadata and also
- # another dictionnary containing the tutorial Related Acttivities,
+ # another dictionnary containing the tutorial Related Activities,
# and add it to a list
+ ini_file = SafeConfigParser()
+
# Create a TutorialBundler object from the guid
bundler = TutorialBundler(guid)
# Find the .ini file path for this guid
@@ -233,6 +233,7 @@ class Vault(object):
metadata_dictionnary = {}
related_act_dictionnary = {}
metadata_list = ini_file.options(INI_METADATA_SECTION)
+
for metadata_name in metadata_list:
# Create a dictionnary of tutorial metadata
metadata_dictionnary[metadata_name] = ini_file.get(INI_METADATA_SECTION, metadata_name)
@@ -245,8 +246,45 @@ class Vault(object):
# Add Related Activities dictionnary to metadata dictionnary
metadata_dictionnary['activities'] = related_act_dictionnary
- # Add this dictionnary to tutorial list
- tutorial_list.append(metadata_dictionnary)
+ # Filter tutorials for keyword (full or partial)
+ if keyword != []:
+ addition_flag = False
+ # Check if at least one keyword of the list is present
+ for key in keyword:
+ for value in metadata_dictionnary.values():
+ if isinstance(value, str) == True:
+ if value.lower().count(key.lower()) > 0:
+ addition_flag = True
+ else:
+ # Check one layer of depth in the metadata to find the keyword
+ # (for exemple, related activites are a dictionnary stocked
+ # in a value of the main dictionnary)
+ if isinstance(value, dict) == True:
+ for inner_key, inner_value in value.items():
+ if isinstance(inner_value, str) == True and isinstance(inner_key, str) == True:
+ if inner_value.lower().count(key.lower()) > 0 or inner_key.count(key.lower()) > 0:
+ addition_flag = True
+
+ # Filter tutorials for related activities
+ if relatedActivityNames != []:
+ addition_flag = False
+ # Check if at least one element of the list is present
+ for related in relatedActivityNames:
+ if related.lower() in related_act_dictionnary.keys():
+ addition_flag = True
+
+ # Filter tutorials for categories
+ if category != []:
+ addition_flag = False
+ # Check if at least one element of the list is present
+ for cat in category:
+ if metadata_dictionnary.has_key(INI_CATEGORY_PROPERTY):
+ if metadata_dictionnary[INI_CATEGORY_PROPERTY].lower() == cat.lower():
+ addition_flag = True
+
+ # Add this dictionnary to tutorial list if it has not been filtered
+ if addition_flag == True:
+ tutorial_list.append(metadata_dictionnary)
# Return tutorial list
return tutorial_list
@@ -319,9 +357,6 @@ class Vault(object):
else:
# Error, tutorial already exist
return False
-
- # TODO : wait for Ben input on how to unpublish tuto before coding this function
- # For now, no unpublishing will occur.
@staticmethod