Ejemplo n.º 1
0
def save_entry(item, request_user):
    try:
        entries = Event.objects.filter(owner=request_user,
                                       start=item['start'],
                                       type=item['type'],
                                       entityid=item['entityid'],
                                       entitytype=item['entitytype'],
                                       client=item['client'])
        if entries.count() == 0:
            entry = Event()
            entry.owner = request_user
            entry.start = item['start']
            entry.type = item['type']
            entry.entityid = item['entityid']
            entry.entitytype = item['entitytype']
            entry.client = item['client']
        else:
            entry = entries[0]

        # yooz dont indent these - disgruntled python user
        entry.end = item['end']
        entry.entitydata = item.get('entitydata', "")
        entry.save()

        return item['start']
    except StandardError, error:
        print "Error with entry %s item %s " % (repr(error), repr(item))
        pass
Ejemplo n.º 2
0
def save_entry(item, request_user):
        try:
            entries = Event.objects.filter(owner=request_user,
                                         start=item['start'],
                                         type=item['type'],
                                         entityid=item['entityid'],
                                         entitytype=item['entitytype'],
                                         client=item['client'])
            if entries.count() == 0 : 
                entry = Event();
                entry.owner = request_user
                entry.start = item['start']
                entry.type = item['type']
                entry.entityid = item['entityid']
                entry.entitytype = item['entitytype']
                entry.client = item['client']
            else:
                entry = entries[0]
                
            # yooz dont indent these - disgruntled python user
            entry.end = item['end']
            entry.entitydata = item.get('entitydata',"")
            entry.save()

            return item['start']
        except StandardError, error:
            print "Error with entry %s item %s " % (repr(error),repr(item))
            pass
Ejemplo n.º 3
0
    def create(self,request):
        """
        lets the user post new event in a giant single array of event log elements
        """
        request_user = authenticate_user(request);
        if not request_user:
            return self.responder.error(request, 401, ErrorDict({"autherror":"Incorrect user/password combination"}))

        #clientid = self._get_client(request) ## note to emax: this does not work!
        clientid = None
        maxwhen,count = self._get_max_helper(request_user,clientid)

        dupes = 0
        committed = [];
        decoded = JSONDecoder().decode(request.raw_post_data)
        print "event received ",request_user,len(decoded)
        for item in decoded:
            try:
                matches = Event.objects.filter(owner=request_user, start=item['start'],  entityid=item["entityid"])
                if matches.count() > 0:
                    dupes = dupes + 1
                    entry = matches[0]
                else:
                    entry = Event()
                entry.owner = request_user
                entry.start = item['start']
                entry.end = item['end']
                entry.type = item['type']
                entry.entityid = item['entityid']
                entry.entitytype = item['entitytype']
                entry.entitydata = item.get('entitydata',"").encode('ascii','ignore')
                clientid = item['client'] 
                entry.client = item['client']
                entry.save()
                committed.append(item['start'])

                maxwhen = max(maxwhen,entry.start)
                
            except StandardError, error:
                print "Error with entry %s item %s " % (repr(error),repr(item))
            pass