Commit 226f914055b36393d7aa63e234882093cc747c79

Authored by Luciano Prestes
Committed by Sergio Oliveira
1 parent 6befc78f

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 68 return _object
69 69  
70 70 def fetch_communities(self):
71   - communities = []
72   -
73 71 json_data = self.get_json_data('/api/v1/communities', 1)
74 72  
75 73 json_data = json_data['communities']
76 74 for element in json_data:
77 75 community = NoosferoCommunity()
78 76 self.fill_object_data(element, community)
  77 + community.save()
  78 +
79 79 if element.has_key('categories'):
80 80 for category_json in element["categories"]:
81 81 category = NoosferoCategory.objects.get_or_create(
82 82 id=category_json["id"], name=category_json["name"])[0]
83 83 community.categories.add(category.id)
84   - communities.append(community)
85   -
86   - return communities
87 84  
88 85 def fetch_articles(self):
89   - articles = []
90   -
91 86 json_data = self.get_json_data('/api/v1/articles', 1)
92 87  
93 88 json_data = json_data['articles']
... ... @@ -95,26 +90,19 @@ class NoosferoDataAPI(ProxyDataAPI):
95 90 for element in json_data:
96 91 article = NoosferoArticle()
97 92 self.fill_object_data(element, article)
  93 + article.save()
98 94  
99 95 for category_json in element["categories"]:
100 96 category = NoosferoCategory.objects.get_or_create(
101 97 id=category_json["id"], name=category_json["name"])[0]
102 98 article.categories.add(category.id)
103 99  
104   - articles.append(article)
105   -
106   - return articles
107   -
108 100 def fetch_data(self):
109 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 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 107 @property
120 108 def app_label(self):
... ...