def parse(self, **kwargs): """ Parse obtained data dict """ items = [] for status in self.raw_data: try: item = Item.objects.filter(slug=status.id, parent=self.node).order_by("-ref_time")[0] except: item = Item() itrans = item.get_translation() item.pk = item.id = get_new_uuid() item.parent = self.node itrans.slug = str(status.id) item.username = "******" + status.user.name item.email = "" item.status = "imported" item.locale = "fr" # item.akey = ge item.path = self.node.related_url item.action = "related" item.label = self.input_data["keyword"] itrans.title = status.text # item.related_id = item.id if self.input_data.get("save"): item.save() print item.pk items.append(item) self.items = item return items
def get_forms_instances(self, action, user_profile, kwargs): if action in UIView.class_actions: if action in ('translate', 'redirect', 'code', 'rename'): # load a new translation cloning the existing one trans_data = model_to_dict(kwargs['node']) user_data = model_to_dict(user_profile) trans_data.update(user_data) for key in trans_data.keys(): if not key in Item.__localizable__: del trans_data[key] trans_data['locale'] = get_language() trans_data['path'] = kwargs['node'].path trans_data['akey'] = user_profile.akey trans_data['username'] = user_profile.username trans_data['email'] = user_profile.email trans_data['validated'] = user_profile.validated trans_data['related_id'] = kwargs['node'].id trans_data['action'] = kwargs['action'] trans_data['status'] = 'changed' trans_data['subject'] = 'Changed texts' trans_data['message'] = 'Text have been changed' trans_data['visible'] = True translation = Translation(**trans_data) return (translation,) elif action in ('add',): parentNode = kwargs['node'] item = Item() item.parent = parentNode item.locale = get_language() item.get_translation() item.akey=user_profile.akey item.username=user_profile.username item.email=user_profile.email item.validated=user_profile.validated item.action='add' item.status='added' item.subject='Ajout' item.message='Nouvel element ajoute' item.path = parentNode.get_path() item.related_id = item.id return (item,) else: return (kwargs['node'],) #kwargs['node'].get_url() #return (Item.objects.get(id=kwargs['node'].id),) else: return super(UIView, self).get_forms_instances(action, user_profile, kwargs)