def parse(self, **kwargs): data = self.raw_data keyword = self.input_data.get('keyword') for status in data['items']: id = status.get('id') link = status.get('htmlLink', id) name = status.get('name', id) title = status.get('summary', name) description = status.get('description', title) #extract_dates(description) item = Item() item.label = name item.related_link = link item.slug = id item.username = name item.label = keyword item.title = status.get('summary') item.description = description self.items.append(item) return self.items
def parse(self, **kwargs): """ Parse obtained data dict """ 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() item.pk = item.id = get_new_uuid() item.parent = self.node item.slug = str(status.id) item.label = 'Message' item.title = status.text item.username = '******'+status.user.name item.email = '' item.status = 'imported' item.locale = 'fr' item.akey = self.user_profile.akey item.path = self.node.related_url item.action = 'related' #item.save() print item.pk self.items.append(item) return self.items
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 process_upload(self, request, user_profile, input_data, template_args, noajax=False, **kwargs): """ Main Multiuploader module. Parses data from jQuery plugin and makes database changes. """ if request.method == 'POST': log.info('received POST to main multiuploader view') if request.FILES is None: response_data = [{"error": _('Must have files attached!')}] return HttpResponse(json.dumps(response_data)) if not u'form_type' in request.POST: response_data = [{"error": _("Error when detecting form type, form_type is missing")}] return HttpResponse(json.dumps(response_data)) signer = Signer() try: form_type = signer.unsign(request.POST.get(u"form_type")) except BadSignature: response_data = [{"error": _("Tampering detected!")}] return HttpResponse(json.dumps(response_data)) form = MultiUploadForm(request.POST, request.FILES, form_type=form_type) if not form.is_valid(): error = _("Unknown error") if "file" in form._errors and len(form._errors["file"]) > 0: error = form._errors["file"][0] response_data = [{"error": error}] return HttpResponse(json.dumps(response_data)) rfile = request.FILES[u'file'] wrapped_file = UploadedFile(rfile) filename = wrapped_file.name file_size = wrapped_file.file.size fname, ext = os.path.splitext(filename) as_image = False if ext.lower() in ('.jpg', '.jpeg', '.png', '.gif'): as_image = True log.info('Got file: "%s"' % filename) itemModel = template_args.get('currentNode') fl = Item(id=get_new_uuid()) fl.action = 'upload' fl.path = itemModel.get_url() fl.akey = user_profile.akey fl.email = user_profile.email fl.username = user_profile.username fl.validated = user_profile.validated fl.slug = slugify(filename) fl.title = filename fl.parent = itemModel fl.file = rfile if as_image == True: fl.behavior = 'image' fl.label = input_data.get('label', 'Image') fl.order = input_data.get('order', 0) fl.image = rfile else: # TODO fl.behavior = 'upload' fl.label = input_data.get('label', 'Fichier') fl.order = input_data.get('order', 0) # set screenshot of document or icon #fl.image = rfile fl.status = 'uploaded' fl.locale = get_language() fl.subject = 'Fichier ajoute' fl.message = 'Le fichier '+filename+' a ete ajoute' fl.save() thumb_url = "" #get_thumbnail(fl.file, "80x80", quality=50) file_link_url = "" #reverse('multiuploader_file_link', args=[fl.pk]), delete_url = "" #reverse('multiuploader_delete', args=[fl.pk]) #generating json response array result = [{"id": str(fl.id), "name": filename, "size": file_size, "url": file_link_url, "thumbnail_url": thumb_url, "delete_url": delete_url, "delete_type": "POST", }] response_data = json.dumps(result) #checking for json data type #big thanks to Guy Shapiro if noajax: if request.META['HTTP_REFERER']: redirect(request.META['HTTP_REFERER']) if "application/json" in request.META['HTTP_ACCEPT_ENCODING']: mimetype = 'application/json' else: mimetype = 'text/plain' return HttpResponse(response_data, content_type=mimetype) else: # GET template_args['multiuploader_form'] = MultiUploadForm(form_type='default') return self.manage_item_pipe(request, user_profile, input_data, template_args, **kwargs) return self.render(request, template_args, **kwargs)
def parse(self, **kwargs): token = 'CAACEdEose0cBAPemNCRC53fdEpBFWzVyCDBHWunsePzgZAW6U7xZAflPwmWW1GMixFpDSyhOLKdUR9GAV2BA3qqWdFBL2UoQDDRsvqFQ9n6sC1izct94BkKfakJZBrODfFB0NdZAxNrUyolxeojnWN829rvcX4gyLpkZBwcQJdnxeBBPpcZC4ojO1l00ZAbFESDx0vlcZCGSuzAHxPe13QfL' keyword = self.input_data.get('keyword') for status in self.raw_data: type = status.get('type') if type == 'event': event_id = status.get('object_id') elif type == 'status': event_id = status.get('id').split('_')[1] else: event_id = None # skip non event stuff if event_id: # get the event data graph_url = 'https://graph.facebook.com/'+event_id+'?access_token='+self.token r = requests.get(graph_url) event_data = r.json() # text label = status.get('name', id) title = event_data.get('name', id) description = event_data.get('description', title) content = '' link = status.get('link', id) # time timezone = event_data.get('timezone') start = event_data.get('start_time') end = event_data.get('end_time', start) # location location = event_data.get('location') event_venue = event_data.get('venue',{}) address = ', '.join((event_venue.get('street', ''), event_venue.get('zip', ''), event_venue.get('city', ''), event_venue.get('country', ''),)) latitude = event_venue.get('latitude', None) longitude = event_venue.get('longitude', None) # picture = status.get('link', id) else: print status # text link = status.get('link', None) label = status.get('name', id) title = status.get('name', id) description = status.get('message', title) start = end = now() location = '' address = '' latitude = None longitude = None # if description: item = Item() item.slug = id item.related_url = link item.start = start item.end = end item.location = location item.address = address item.latitude = latitude item.longitude = longitude item.slug = id item.label = keyword item.title = title item.description = description item.content = content item.parent = self.node self.items.append(item) return self.items