Commit 226f914055b36393d7aa63e234882093cc747c79
Committed by
Sergio Oliveira
1 parent
6befc78f
Exists in
master
and in
31 other branches
Change location of save model of noosfero import data
- The models was saved in fetch_data method, but now, the models are saved in fetch_communities and fetch_articles methods Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com>
Showing
1 changed file
with
5 additions
and
17 deletions
Show diff stats
colab/plugins/noosfero/data_api.py
@@ -68,26 +68,21 @@ class NoosferoDataAPI(ProxyDataAPI): | @@ -68,26 +68,21 @@ class NoosferoDataAPI(ProxyDataAPI): | ||
68 | return _object | 68 | return _object |
69 | 69 | ||
70 | def fetch_communities(self): | 70 | def fetch_communities(self): |
71 | - communities = [] | ||
72 | - | ||
73 | json_data = self.get_json_data('/api/v1/communities', 1) | 71 | json_data = self.get_json_data('/api/v1/communities', 1) |
74 | 72 | ||
75 | json_data = json_data['communities'] | 73 | json_data = json_data['communities'] |
76 | for element in json_data: | 74 | for element in json_data: |
77 | community = NoosferoCommunity() | 75 | community = NoosferoCommunity() |
78 | self.fill_object_data(element, community) | 76 | self.fill_object_data(element, community) |
77 | + community.save() | ||
78 | + | ||
79 | if element.has_key('categories'): | 79 | if element.has_key('categories'): |
80 | for category_json in element["categories"]: | 80 | for category_json in element["categories"]: |
81 | category = NoosferoCategory.objects.get_or_create( | 81 | category = NoosferoCategory.objects.get_or_create( |
82 | id=category_json["id"], name=category_json["name"])[0] | 82 | id=category_json["id"], name=category_json["name"])[0] |
83 | community.categories.add(category.id) | 83 | community.categories.add(category.id) |
84 | - communities.append(community) | ||
85 | - | ||
86 | - return communities | ||
87 | 84 | ||
88 | def fetch_articles(self): | 85 | def fetch_articles(self): |
89 | - articles = [] | ||
90 | - | ||
91 | json_data = self.get_json_data('/api/v1/articles', 1) | 86 | json_data = self.get_json_data('/api/v1/articles', 1) |
92 | 87 | ||
93 | json_data = json_data['articles'] | 88 | json_data = json_data['articles'] |
@@ -95,26 +90,19 @@ class NoosferoDataAPI(ProxyDataAPI): | @@ -95,26 +90,19 @@ class NoosferoDataAPI(ProxyDataAPI): | ||
95 | for element in json_data: | 90 | for element in json_data: |
96 | article = NoosferoArticle() | 91 | article = NoosferoArticle() |
97 | self.fill_object_data(element, article) | 92 | self.fill_object_data(element, article) |
93 | + article.save() | ||
98 | 94 | ||
99 | for category_json in element["categories"]: | 95 | for category_json in element["categories"]: |
100 | category = NoosferoCategory.objects.get_or_create( | 96 | category = NoosferoCategory.objects.get_or_create( |
101 | id=category_json["id"], name=category_json["name"])[0] | 97 | id=category_json["id"], name=category_json["name"])[0] |
102 | article.categories.add(category.id) | 98 | article.categories.add(category.id) |
103 | 99 | ||
104 | - articles.append(article) | ||
105 | - | ||
106 | - return articles | ||
107 | - | ||
108 | def fetch_data(self): | 100 | def fetch_data(self): |
109 | LOGGER.info("Importing Communities") | 101 | LOGGER.info("Importing Communities") |
110 | - communities = self.fetch_communities() | ||
111 | - for datum in communities: | ||
112 | - datum.save() | 102 | + self.fetch_communities() |
113 | 103 | ||
114 | LOGGER.info("Importing Articles") | 104 | LOGGER.info("Importing Articles") |
115 | - articles = self.fetch_articles() | ||
116 | - for datum in articles: | ||
117 | - datum.save() | 105 | + self.fetch_articles() |
118 | 106 | ||
119 | @property | 107 | @property |
120 | def app_label(self): | 108 | def app_label(self): |