Beispiel #1
0
    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
Beispiel #2
0
 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
Beispiel #3
0
 def load_items(self):
     
     # get parking address list of active vehicles
     logger.debug('\nStart parsing items ...')
     
     kwargs= {}
     kwargs['pipe'] = {'locale':get_language(),
                       'akey':get_new_uuid(),
                       'action':'import',
                       'status':'imported',
                       'path':'/localhost'
                       }
     
     items = Item.objects.filter(visible=True,).order_by('parent')
     
     for item in items:
         print item.get_url()
         self.index_item(item)
     
     if settings.DEBUG:
         logger.debug('\nParsed '+str(len(items))+' items in '+str()+' seconds\n')
         return
         try:
             self.data_map.print_stats()
         except:
             pass
Beispiel #4
0
    def process_invite(self, request, user_profile, input_data, template_args, **kwargs):
        """
        invite a group of user to join the commenting
        """
        akey = self.get_session_user_keys(request)
        action_data = kwargs['pipe']
        action = kwargs.get('action')
        emails = input_data.get('emails')
       

        # establish a list of invitation
        invitationList = {}
        # from email list
        if emails:
            for email in emails.split(','):
                invitationList[email] = None
        
        origin, = self.get_forms_instances(action, user_profile, kwargs)
        
        #
        for iemail in invitationList:
            invitation = Moderation()
            invitation.origin = origin
            invitation.related_id = template_args['currentNode'].id
            invitation.action = 'invite'
            invitation.locale = get_language()
            invitation.path = kwargs['node'].get_url()
            invitation.status = 'invited'
            invitation.email = iemail
            invitation.akey = get_new_uuid()
            invitation.subject = 'Invitation lancee !'
            invitation.message = input_data.get('message', 'Vous etes invite a consulter ce document')
            invitation.save()
        
        template_args['action_forms'] = self.get_validated_forms(
                                                 self.get_forms_instances(action, user_profile, kwargs),
                                                 input_data,
                                                 action,
                                                 save_forms=False,
                                                 bound_forms=False
                                                 )

        return self.render(request, template_args, **kwargs)
Beispiel #5
0
 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)
Beispiel #6
0
    def process_push(self, request, user_profile, input_data, template_args, **kwargs):
        """
        Set the notebook to articles
        """
        node = kwargs['node']
        nb = get_or_create_notebook(node)
        
        i = 0
        # if not, create one
        for cell in nb.cells:
            # check for item corresponding
            try:
                cell_id = cell.metadata.gid
            except:
                cell.metadata.gid = get_new_uuid()
                cell_id = cell.metadata.gid
            
            try:
                cell_node = Item.objects.get(id=cell_id)
            except ObjectDoesNotExist:
                cell_node = Item(id=cell_id, parent=node, **kwargs['pipe'])
            
            if cell.cell_type == 'code':
                #
                content = u''
                for output in cell.outputs:
                    if output.output_type == 'stream' and 'stream' == 'stdout':
                        content += output.get('text', u'')
                cell_node.content = content
                
                #if cell_node.content:
                #    cell_node.visible = True
                #else:
                cell_node.visible = False
                
                #if not cell_node.title:
                #    cell_node.title = 'Code'
                
                #if not cell_node.label:
                #    cell_node.label = cell_node.title
                
            elif cell.cell_type == 'markdown':
                
                #cell_node.behavior = 'view'
                #cell_node.content = '<i>markdown rendered html</i>'
                
                cell_node.visible = True
                
                cell = markdown_to_item(cell_node, ''.join(cell.source))

            cell_node.status = 'pushed'
            cell_node.order = i
            cell_node.save()
            i += 1

        save_notebook(nb, node)
        
        #
        if not node.file:
            node.file = 'resource/'+node.id+'.ipynb'
            node.save()
        
        return HttpResponseRedirect(node.get_url()+'view/')

        return self.manage_item_pipe(request, user_profile, input_data, template_args, **kwargs)
Beispiel #7
0
 def load_items(self):
     
     # get parking address list of active vehicles
     if settings.DEBUG:
         print '\nStart parsing items ...'
     
     kwargs= {}
     kwargs['pipe'] = {'locale':get_language(),
                       'akey':get_new_uuid(),
                       'action':'import',
                       'status':'imported',
                       'path':'/localhost'
                       }
     
     #item = Item.objects.get_or_create_url('//localhost/', **kwargs)
     #self.add_item_data(item.id, item.get_path(), item.label, item.latitude, item.longitude, item.admin0, item.admin1, item.admin2, item.admin3)
     
     if not settings.DEBUG:
         return
     
     #return
     items = Item.objects.filter(visible=True,).order_by('parent')
     #.exclude(parent=None)
     # add each vehicle to the cache structure
     max_key_modified = 0
     
     for item in items:
         # unidex key if already exists
         if self.has_object('item', item.id):
             self.remove_object('item', item.id)
         
         keywords = []
         
         #
         if item.label:
             sentence = fr.parse(item.label)
             for word in sentence.split()[0]:
                 if word[1] == 'NN' and len(word[0]) > 2:
                     if not word[0] in keywords:
                         keywords.append(slugify(word[0]))
         
         if item.title:
             sentence = fr.parse(item.title)
             for word in sentence.split()[0]:
                 if word[1] == 'NN' and len(word[0]) > 2:
                     if not word[0] in keywords:
                         keywords.append(slugify(word[0]))
         
         if item.description:
             sentence = fr.parse(item.description)
             for word in sentence.split()[0]:
                 if word[1] == 'NN' and len(word[0]) > 2:
                     if not word[0] in keywords:
                         keywords.append(slugify(word[0]))
         
         keywords.append(item.label)
         #print keywords
         self.add_item_data(item.id, item.get_path(), item.label, keywords, item.latitude, item.longitude)
         print '.',
         #print 'added '+item.get_path()
     
     if settings.DEBUG:
         
         print '\nParsed '+str(len(items))+' items in '+str()+' seconds\n'
         return
         try:
             self.data_map.print_stats()
         except:
             pass