Ejemplo n.º 1
0
def undoOrRedo(request, practice_id, callgroup_id, srcStackName, targetStackName):
	callgroup_id = checkMultiCallGroupId(practice_id, callgroup_id)
	if (not canAccessMultiCallGroup(request.user, long(callgroup_id), practice_id)):
		return err403(request)

	user = request.user
	if request.method == 'POST':
		operateList = SessionHelper.popSessionStack(request, srcStackName)
		if (operateList is not None and len(operateList) > 0):
			operateList_n = []
			operateList_r = []
			for operateItem in operateList:
				type = operateItem["type"]
				data = operateItem["data"]
				view = operateItem["view"]
				pk = operateItem["pk"]	
				eventObj = serializers.deserialize("json", data).next()
				if ("0" == type):
					# set defaults
					eventObj.object.callGroup_id = int(callgroup_id)
					eventObj.object.notifyState = 2
					eventObj.object.whoCanModify = 1
					eventObj.object.eventStatus = 1
					if validateNewEvent(eventObj):
						# we are ok to save this new object
						eventObj.object.creator = user
						eventObj.object.creationdate = datetime.datetime.now()
						eventObj.object.lastupdate = datetime.datetime.now()
						eventObj.object.title = 'scheduled_event'
						eventObj.save()
						newOperate = {
							'type': "2",
							'view': view,
							"pk": eventObj.object.pk, 									
							'data': serializers.serialize("json", [eventObj.object], 
								fields=('oncallPerson', 'eventType', 'startDate', 
									'endDate', 'checkString'))}

						SessionHelper.checkSessionStack(request, 
							SessionHelper.SCHEDULE_UNDOSTACK_NAME, pk, eventObj.object.pk)
						SessionHelper.checkSessionStack(request, 
							SessionHelper.SCHEDULE_REDOSTACK_NAME, pk, eventObj.object.pk)

						operateList_n.append(newOperate)							
						operateList_r.append(newOperate)
				elif ("1" == type or "2" == type):
					# check checkString and fill in creationdate and lastupdate date
					oldEvent = EventEntry.objects.get(id=eventObj.object.pk)
					if (oldEvent.checkString == eventObj.object.checkString):
						newType = ("1" == type and "1" or "0") 

						eventObj.object.callGroup_id = int(callgroup_id)
						# necessary for easier access in the admin
						eventObj.object.title = 'scheduled_event-%i' % (eventObj.object.pk,)
						eventObj.object.notifyState = 2
						eventObj.object.whoCanModify = 1
						eventObj.object.creator = user
						eventObj.object.creationdate = oldEvent.creationdate
						eventObj.object.lastupdate = datetime.datetime.now()
						eventObj.object.eventStatus = newType

						eventObj.save()

						operateList_n.append({
							'type': newType,
							'view': view, 	
							"pk": eventObj.object.pk, 								
							'data': serializers.serialize("json", [oldEvent], 
								fields=('oncallPerson', 'eventType', 
									'startDate', 'endDate', 'checkString'))})	
						operateList_r.append({
							'type': newType,
							'view': view, 	
							'pk': pk, 							
							'data': serializers.serialize("json", [eventObj.object], 
								fields=('oncallPerson', 'eventType', 
									'startDate', 'endDate', 'checkString'))})
				request.session[SessionHelper.SCHEDULE_LASTVIEW] = view
			SessionHelper.pushSessionStack(request, targetStackName, operateList_n)
			response = {'operateList': operateList_r, 'error': '', 'undoSize': 
				SessionHelper.getSessionStackSize(request, SessionHelper.SCHEDULE_UNDOSTACK_NAME),
					'redoSize': SessionHelper.getSessionStackSize(
						request, SessionHelper.SCHEDULE_REDOSTACK_NAME)}
		else:
			response = {'operateList': [], 'error': '', 'count': 0,
				'undoSize': SessionHelper.getSessionStackSize(
					request, SessionHelper.SCHEDULE_UNDOSTACK_NAME),
				'redoSize': SessionHelper.getSessionStackSize(
					request, SessionHelper.SCHEDULE_REDOSTACK_NAME)}
		return HttpResponse(content=json.dumps(response), mimetype='application/json')
Ejemplo n.º 2
0
def bulkUpdateEvents(request, practice_id, callgroup_id=None):
	"""
		bulk update eventEntry returns result of eventEntries updated and any 
		errors/warnings if there is a mismatch with checkString
	"""
	callgroup_id = checkMultiCallGroupId(practice_id, callgroup_id)
	if (not canAccessMultiCallGroup(request.user, long(callgroup_id), practice_id)):
		return err403(request)

	user = request.user
	if request.method == 'POST':
		# form = BulkEventForm(request.POST) # never used.
		errorlist = []
		savelist = []
		operateList = []
		count = 0
		data = request.POST['data']
		view = request.POST['view']

		if checkSchedulerView(view):
			logger.debug('data from request is %s' % (data))
			for eventObj in serializers.deserialize("json", data):
				count = count + 1
				eventObj.object.callGroup_id = int(callgroup_id)
				# necessary for easier access in the admin
				eventObj.object.title = 'scheduled_event-%i' % (eventObj.object.pk,)
				eventObj.object.notifyState = 2
				eventObj.object.whoCanModify = 1
				# we check for pk presence first
				if (eventObj.object.pk == None):
					errorlist.append("0, error updating object - no key present %s %s" %
						(eventObj.object.checkString, eventObj))
				elif checkDSEventConsistency(eventObj):
					# check checkString and fill in creationdate and lastupdate date
					oldEvent = EventEntry.objects.get(id=eventObj.object.pk)
					if (oldEvent.checkString == eventObj.object.checkString):
						# we are ok
						eventObj.object.creator = user
						eventObj.object.creationdate = oldEvent.creationdate
						eventObj.object.lastupdate = datetime.datetime.now()

						try:
							# validate the updated EventEntry 
							eventObj.object.clean_fields()	
							eventObj.save()
							operateList.append({
								'type': eventObj.object.eventStatus,
								"view": view,
								"pk": eventObj.object.pk, 								
								'data': serializers.serialize("json", [oldEvent], 
									fields=('oncallPerson', 'eventType', 'startDate', 
										'endDate', 'checkString'))})							
							savelist.append('%s, %s' % (eventObj.object.id, 
									eventObj.object.checkString))
						except ValidationError:
							errorlist.append("%d, update failed - validate error %s obj %s" %
								(eventObj.object.pk, eventObj.object.checkString, eventObj))	
					else:
						errorlist.append("%d, update failed - invalid checkString %s obj %s" %
							(eventObj.object.pk, eventObj.object.checkString, eventObj))
				else:
					errorlist.append("%d, error updating object %s obj %s" %
						(eventObj.object.pk, eventObj.object.checkString, eventObj))
		else:
			errorlist.append("invalid view")

		SessionHelper.pushSessionStack(request, SessionHelper.SCHEDULE_UNDOSTACK_NAME, operateList)	
		SessionHelper.clearSessionStack(request, SessionHelper.SCHEDULE_REDOSTACK_NAME)	
		response = {'data': savelist, 'error': errorlist, 'count': count,
			'undoSize': SessionHelper.getSessionStackSize(request, SessionHelper.SCHEDULE_UNDOSTACK_NAME),
			'redoSize': SessionHelper.getSessionStackSize(request, SessionHelper.SCHEDULE_REDOSTACK_NAME)}
		logger.debug('returned result %s' % (response))
		return HttpResponse(content=json.dumps(response), mimetype='application/json')
	else:
		form = BulkEventForm()
		return render_to_response("bulkOperation.html", {'form': form, })
Ejemplo n.º 3
0
def bulkNewEvents(request, practice_id, callgroup_id=None):
	"""
		bulk add eventEntry
		returns result of eventEntries saved and any errors/warnings
	"""
	callgroup_id = checkMultiCallGroupId(practice_id, callgroup_id)
	if (not canAccessMultiCallGroup(request.user, long(callgroup_id), practice_id)):
		return err403(request)

	user = request.user
	if request.method == 'POST':
		form = BulkEventForm(request.POST)
		data = request.POST['data']
		view = request.POST['view']
		errorlist = []  # this contains errors/warnings 
		operateList = []		
		count = 0  # count how many events we got
		newPks = dict()
		logger.debug('data from request is %s' % (data))

		if checkSchedulerView(view):
			for newdsEventObj in serializers.deserialize("json", data):
				count = count + 1
				# set defaults
				newdsEventObj.object.callGroup_id = int(callgroup_id)
				newdsEventObj.object.notifyState = 2
				newdsEventObj.object.whoCanModify = 1
				newdsEventObj.object.eventStatus = 1
				if validateNewEvent(newdsEventObj):
					# we are ok to save this new object
					newdsEventObj.object.creator = user
					newdsEventObj.object.creationdate = datetime.datetime.now()
					newdsEventObj.object.lastupdate = datetime.datetime.now()
					newdsEventObj.object.title = 'scheduled_event'  
					try:
						# validate the EventEntry 
						newdsEventObj.object.clean_fields()	
						newdsEventObj.save()
						newPks[newdsEventObj.object.checkString] = newdsEventObj.object.pk

						operateList.append({
								'type': "2",
								"view": view,
								"pk": newdsEventObj.object.pk,
								'data': serializers.serialize("json", [newdsEventObj.object], 
									fields=('oncallPerson', 'eventType', 
										'startDate', 'endDate', 'checkString'))})	
					except ValidationError:
						errorlist.append('Validate error saving new object: %s' % 
							(serializers.serialize("json", [newdsEventObj.object], 
								fields=('oncallPerson', 'eventType', 'startDate', 
									'endDate', 'checkString'))))
				else:
					errorlist.append('%s, error saving new object' % (newdsEventObj.object.checkString))
		else:
			errorlist.append("invalid view")

		SessionHelper.pushSessionStack(request, SessionHelper.SCHEDULE_UNDOSTACK_NAME, operateList)		
		SessionHelper.clearSessionStack(request, SessionHelper.SCHEDULE_REDOSTACK_NAME)					
		response = {'data': newPks, 'error': errorlist, 'count': count,
			'undoSize': SessionHelper.getSessionStackSize(request, 
					SessionHelper.SCHEDULE_UNDOSTACK_NAME),
			'redoSize': SessionHelper.getSessionStackSize(request, 
					SessionHelper.SCHEDULE_REDOSTACK_NAME)}
		logger.debug('returned result %s' % (response))
		return HttpResponse(content=json.dumps(response), mimetype='application/json')
	else:
		form = BulkEventForm()
		return render_to_response("bulkOperation.html", {'form': form, })
Ejemplo n.º 4
0
def undoOrRedo(request, practice_id, callgroup_id, srcStackName,
               targetStackName):
    callgroup_id = checkMultiCallGroupId(practice_id, callgroup_id)
    if (not canAccessMultiCallGroup(request.user, long(callgroup_id),
                                    practice_id)):
        return err403(request)

    user = request.user
    if request.method == 'POST':
        operateList = SessionHelper.popSessionStack(request, srcStackName)
        if (operateList is not None and len(operateList) > 0):
            operateList_n = []
            operateList_r = []
            for operateItem in operateList:
                type = operateItem["type"]
                data = operateItem["data"]
                view = operateItem["view"]
                pk = operateItem["pk"]
                eventObj = serializers.deserialize("json", data).next()
                if ("0" == type):
                    # set defaults
                    eventObj.object.callGroup_id = int(callgroup_id)
                    eventObj.object.notifyState = 2
                    eventObj.object.whoCanModify = 1
                    eventObj.object.eventStatus = 1
                    if validateNewEvent(eventObj):
                        # we are ok to save this new object
                        eventObj.object.creator = user
                        eventObj.object.creationdate = datetime.datetime.now()
                        eventObj.object.lastupdate = datetime.datetime.now()
                        eventObj.object.title = 'scheduled_event'
                        eventObj.save()
                        newOperate = {
                            'type':
                            "2",
                            'view':
                            view,
                            "pk":
                            eventObj.object.pk,
                            'data':
                            serializers.serialize(
                                "json", [eventObj.object],
                                fields=('oncallPerson', 'eventType',
                                        'startDate', 'endDate', 'checkString'))
                        }

                        SessionHelper.checkSessionStack(
                            request, SessionHelper.SCHEDULE_UNDOSTACK_NAME, pk,
                            eventObj.object.pk)
                        SessionHelper.checkSessionStack(
                            request, SessionHelper.SCHEDULE_REDOSTACK_NAME, pk,
                            eventObj.object.pk)

                        operateList_n.append(newOperate)
                        operateList_r.append(newOperate)
                elif ("1" == type or "2" == type):
                    # check checkString and fill in creationdate and lastupdate date
                    oldEvent = EventEntry.objects.get(id=eventObj.object.pk)
                    if (oldEvent.checkString == eventObj.object.checkString):
                        newType = ("1" == type and "1" or "0")

                        eventObj.object.callGroup_id = int(callgroup_id)
                        # necessary for easier access in the admin
                        eventObj.object.title = 'scheduled_event-%i' % (
                            eventObj.object.pk, )
                        eventObj.object.notifyState = 2
                        eventObj.object.whoCanModify = 1
                        eventObj.object.creator = user
                        eventObj.object.creationdate = oldEvent.creationdate
                        eventObj.object.lastupdate = datetime.datetime.now()
                        eventObj.object.eventStatus = newType

                        eventObj.save()

                        operateList_n.append({
                            'type':
                            newType,
                            'view':
                            view,
                            "pk":
                            eventObj.object.pk,
                            'data':
                            serializers.serialize(
                                "json", [oldEvent],
                                fields=('oncallPerson', 'eventType',
                                        'startDate', 'endDate', 'checkString'))
                        })
                        operateList_r.append({
                            'type':
                            newType,
                            'view':
                            view,
                            'pk':
                            pk,
                            'data':
                            serializers.serialize(
                                "json", [eventObj.object],
                                fields=('oncallPerson', 'eventType',
                                        'startDate', 'endDate', 'checkString'))
                        })
                request.session[SessionHelper.SCHEDULE_LASTVIEW] = view
            SessionHelper.pushSessionStack(request, targetStackName,
                                           operateList_n)
            response = {
                'operateList':
                operateList_r,
                'error':
                '',
                'undoSize':
                SessionHelper.getSessionStackSize(
                    request, SessionHelper.SCHEDULE_UNDOSTACK_NAME),
                'redoSize':
                SessionHelper.getSessionStackSize(
                    request, SessionHelper.SCHEDULE_REDOSTACK_NAME)
            }
        else:
            response = {
                'operateList': [],
                'error':
                '',
                'count':
                0,
                'undoSize':
                SessionHelper.getSessionStackSize(
                    request, SessionHelper.SCHEDULE_UNDOSTACK_NAME),
                'redoSize':
                SessionHelper.getSessionStackSize(
                    request, SessionHelper.SCHEDULE_REDOSTACK_NAME)
            }
        return HttpResponse(content=json.dumps(response),
                            mimetype='application/json')
Ejemplo n.º 5
0
def bulkUpdateEvents(request, practice_id, callgroup_id=None):
    """
		bulk update eventEntry returns result of eventEntries updated and any 
		errors/warnings if there is a mismatch with checkString
	"""
    callgroup_id = checkMultiCallGroupId(practice_id, callgroup_id)
    if (not canAccessMultiCallGroup(request.user, long(callgroup_id),
                                    practice_id)):
        return err403(request)

    user = request.user
    if request.method == 'POST':
        # form = BulkEventForm(request.POST) # never used.
        errorlist = []
        savelist = []
        operateList = []
        count = 0
        data = request.POST['data']
        view = request.POST['view']

        if checkSchedulerView(view):
            logger.debug('data from request is %s' % (data))
            for eventObj in serializers.deserialize("json", data):
                count = count + 1
                eventObj.object.callGroup_id = int(callgroup_id)
                # necessary for easier access in the admin
                eventObj.object.title = 'scheduled_event-%i' % (
                    eventObj.object.pk, )
                eventObj.object.notifyState = 2
                eventObj.object.whoCanModify = 1
                # we check for pk presence first
                if (eventObj.object.pk == None):
                    errorlist.append(
                        "0, error updating object - no key present %s %s" %
                        (eventObj.object.checkString, eventObj))
                elif checkDSEventConsistency(eventObj):
                    # check checkString and fill in creationdate and lastupdate date
                    oldEvent = EventEntry.objects.get(id=eventObj.object.pk)
                    if (oldEvent.checkString == eventObj.object.checkString):
                        # we are ok
                        eventObj.object.creator = user
                        eventObj.object.creationdate = oldEvent.creationdate
                        eventObj.object.lastupdate = datetime.datetime.now()

                        try:
                            # validate the updated EventEntry
                            eventObj.object.clean_fields()
                            eventObj.save()
                            operateList.append({
                                'type':
                                eventObj.object.eventStatus,
                                "view":
                                view,
                                "pk":
                                eventObj.object.pk,
                                'data':
                                serializers.serialize(
                                    "json", [oldEvent],
                                    fields=('oncallPerson', 'eventType',
                                            'startDate', 'endDate',
                                            'checkString'))
                            })
                            savelist.append('%s, %s' %
                                            (eventObj.object.id,
                                             eventObj.object.checkString))
                        except ValidationError:
                            errorlist.append(
                                "%d, update failed - validate error %s obj %s"
                                % (eventObj.object.pk,
                                   eventObj.object.checkString, eventObj))
                    else:
                        errorlist.append(
                            "%d, update failed - invalid checkString %s obj %s"
                            % (eventObj.object.pk, eventObj.object.checkString,
                               eventObj))
                else:
                    errorlist.append("%d, error updating object %s obj %s" %
                                     (eventObj.object.pk,
                                      eventObj.object.checkString, eventObj))
        else:
            errorlist.append("invalid view")

        SessionHelper.pushSessionStack(request,
                                       SessionHelper.SCHEDULE_UNDOSTACK_NAME,
                                       operateList)
        SessionHelper.clearSessionStack(request,
                                        SessionHelper.SCHEDULE_REDOSTACK_NAME)
        response = {
            'data':
            savelist,
            'error':
            errorlist,
            'count':
            count,
            'undoSize':
            SessionHelper.getSessionStackSize(
                request, SessionHelper.SCHEDULE_UNDOSTACK_NAME),
            'redoSize':
            SessionHelper.getSessionStackSize(
                request, SessionHelper.SCHEDULE_REDOSTACK_NAME)
        }
        logger.debug('returned result %s' % (response))
        return HttpResponse(content=json.dumps(response),
                            mimetype='application/json')
    else:
        form = BulkEventForm()
        return render_to_response("bulkOperation.html", {
            'form': form,
        })
Ejemplo n.º 6
0
def bulkNewEvents(request, practice_id, callgroup_id=None):
    """
		bulk add eventEntry
		returns result of eventEntries saved and any errors/warnings
	"""
    callgroup_id = checkMultiCallGroupId(practice_id, callgroup_id)
    if (not canAccessMultiCallGroup(request.user, long(callgroup_id),
                                    practice_id)):
        return err403(request)

    user = request.user
    if request.method == 'POST':
        form = BulkEventForm(request.POST)
        data = request.POST['data']
        view = request.POST['view']
        errorlist = []  # this contains errors/warnings
        operateList = []
        count = 0  # count how many events we got
        newPks = dict()
        logger.debug('data from request is %s' % (data))

        if checkSchedulerView(view):
            for newdsEventObj in serializers.deserialize("json", data):
                count = count + 1
                # set defaults
                newdsEventObj.object.callGroup_id = int(callgroup_id)
                newdsEventObj.object.notifyState = 2
                newdsEventObj.object.whoCanModify = 1
                newdsEventObj.object.eventStatus = 1
                if validateNewEvent(newdsEventObj):
                    # we are ok to save this new object
                    newdsEventObj.object.creator = user
                    newdsEventObj.object.creationdate = datetime.datetime.now()
                    newdsEventObj.object.lastupdate = datetime.datetime.now()
                    newdsEventObj.object.title = 'scheduled_event'
                    try:
                        # validate the EventEntry
                        newdsEventObj.object.clean_fields()
                        newdsEventObj.save()
                        newPks[newdsEventObj.object.
                               checkString] = newdsEventObj.object.pk

                        operateList.append({
                            'type':
                            "2",
                            "view":
                            view,
                            "pk":
                            newdsEventObj.object.pk,
                            'data':
                            serializers.serialize(
                                "json", [newdsEventObj.object],
                                fields=('oncallPerson', 'eventType',
                                        'startDate', 'endDate', 'checkString'))
                        })
                    except ValidationError:
                        errorlist.append(
                            'Validate error saving new object: %s' %
                            (serializers.serialize(
                                "json", [newdsEventObj.object],
                                fields=('oncallPerson', 'eventType',
                                        'startDate', 'endDate',
                                        'checkString'))))
                else:
                    errorlist.append('%s, error saving new object' %
                                     (newdsEventObj.object.checkString))
        else:
            errorlist.append("invalid view")

        SessionHelper.pushSessionStack(request,
                                       SessionHelper.SCHEDULE_UNDOSTACK_NAME,
                                       operateList)
        SessionHelper.clearSessionStack(request,
                                        SessionHelper.SCHEDULE_REDOSTACK_NAME)
        response = {
            'data':
            newPks,
            'error':
            errorlist,
            'count':
            count,
            'undoSize':
            SessionHelper.getSessionStackSize(
                request, SessionHelper.SCHEDULE_UNDOSTACK_NAME),
            'redoSize':
            SessionHelper.getSessionStackSize(
                request, SessionHelper.SCHEDULE_REDOSTACK_NAME)
        }
        logger.debug('returned result %s' % (response))
        return HttpResponse(content=json.dumps(response),
                            mimetype='application/json')
    else:
        form = BulkEventForm()
        return render_to_response("bulkOperation.html", {
            'form': form,
        })