コード例 #1
0
ファイル: appointment.py プロジェクト: jworr/scheduler
def checkDate(date):
	"""
	Returns true is the value is a date or is None else false
	"""
	result = True
	try:
		util.toDatetime(date)
	except:
		result = False
		
	return result
コード例 #2
0
ファイル: opac.py プロジェクト: bluestemscott/librarygadget
    def parse(self):
        duecomments = self.soup.findAll(text=re.compile("Due Date"))

        for comment in duecomments:
            tr = comment.findPrevious('tr')
            item = models.Item()

            marker = tr.find(text=re.compile("Title"))
            if marker is None:
                marker = tr.find(text=re.compile("Print the title"))
            title = self.findcontent(marker.parent)
            title = util.unescape(title)
            item.title = util.stripNonAscii(title)

            marker = tr.find(text=re.compile("Author"))
            author = self.findcontent(marker.parent)
            L = author.split(',')
            author = ','.join(L[0:2])
            author = util.unescape(author)
            item.author = util.stripNonAscii(author)

            marker = tr.find(text=re.compile("Due Date"))
            dueDate = self.findcontent(marker.parent)
            dueDate = dueDate.split(',')[0] #strip time
            item.dueDate = util.toDatetime(dueDate)
            self.itemsOut[item.title] = item
コード例 #3
0
ファイル: webCal.py プロジェクト: jworr/scheduler
def buildDay(locations, roles, appMap, theDate):
	"""
	Builds HTML to represent a given day
	"""
	result = """<table id=\"%s\" class="schedule">
	<tr>
		<th></th> <th colspan=\"3\"><a href=\"dayDetails?date=%s&location=%s\">Albany</a></th> 
		<th colspan=\"3\"><a href=\"dayDetails?date=%s&location=%s\">Corvallis</a></th>
	</tr>
	<tr>
		<th>%s</th> <th>Advocate</th> <th>Support</th> <th>Medical</th>
		<th>Advocate</th> <th>Support</th> <th>Medical</th>
	</tr>""" % (util.toDayName(theDate), util.startOfWeek(theDate), model.LOC1, util.startOfWeek(theDate), model.LOC2, util.toDateStr(theDate,True)) #e.g. Monday, 1/3

	base =  ""
	
	#for each hour in the day build the associated html
	for i,timeslot in enumerate(sorted( appMap.keys(), compareTimes )):
		result += buildSlot(locations, roles, appMap[timeslot], theDate, timeslot, not(i % 2))

	#build the default time
	defaultTime = util.toDatetime(util.toDateStr(theDate),DEFAULT_TIME)

	#build the base of the day
	for loc in locations:
		for role in roles:
			base += ADD_TEMPLATE % (role.roleId, loc, defaultTime) 

	return result + "<tr><td></td>" + base + "</tr></table>\n"
コード例 #4
0
	def parse(self):
		self.form = self.soup.find("form", {"name" : "hasnow"})
		row = self.soup.find('input', {'name' : 'HASNOW'})
		if row == None:
			return
		
		table = row.findPrevious('table')
		#print table.__class__.__name__

		#print table.prettify()
		rows = table.findAll('tr')
		#print len(rows)
		for itemrow in rows:
			#print row.__class__.__name__

			#print row.prettify()
			# ignore the header row -- we know it's a header if there isn't a renewal checkbox next to it
			if itemrow.find('input', {'name':'HASNOW'}) == row.Null:
				continue
			item = models.Item()
			#print row.prettify()
			renewitemkeys = itemrow.find('input', {'name':'HASNOW'})
			
			divs = itemrow.findAll('div', {'id' : 'globaltext'})
			#print len(divs)
			title = divs[0].string.strip()
			title = util.unescape(title)
			item.title = util.stripNonAscii(title)
			#print title
			dueDate = divs[4].string.strip()
			dueDate = dueDate.split(',')[0] #strip time
			item.dueDate = util.toDatetime(dueDate)
			self.itemsOut[item.title] = item
コード例 #5
0
ファイル: opac.py プロジェクト: bluestemscott/librarygadget
    def parse_itemlisting_style(self):
        item_tds = self.soup.findAll('td', {'class' : ('itemlisting', 'itemlisting2')})
        for td in item_tds:
            tr = td.findPrevious('tr')
            item = models.Item()

            marker = tr.find(text=re.compile("Print the title"))
            title = marker.nextSibling.strip()
            title = util.unescape(title)
            item.title = util.stripNonAscii(title)

            marker = tr.find(text=re.compile("Print the author"))
            if marker is None or marker.nextSibling is None:
                author = ''
            else:
                author = marker.nextSibling.strip().strip('.')
            L = author.split(',')
            author = ','.join(L[0:2])
            author = util.unescape(author)
            item.author = util.stripNonAscii(author)

            marker = tr.find(text=re.compile("Print the date due"))
            #<td>Due <!--Print the date due--> <strong>12/10/2011,....
            dueDate = marker.parent.find('strong').string.strip()
            dueDate = dueDate.split(',')[0] #strip time
            item.dueDate = util.toDatetime(dueDate)
            self.itemsOut[item.title] = item
        print self.itemsOut
コード例 #6
0
ファイル: webCal.py プロジェクト: jworr/scheduler
def display(date, tab):
	"""
	Displays the calendar page
	"""
	standardSlots = ["08:00AM", "08:15AM", "08:30AM", "08:45AM", "09:00AM", "09:15AM",
			"09:30AM", "09:45AM", "10:00AM", "10:15AM", "10:30AM", "10:45AM", "11:00AM",
			"11:15AM", "11:30AM", "11:45AM", "12:00PM", "12:15PM", "12:30PM", "12:45PM",
			"01:00PM", "01:15PM", "01:30PM", "01:45PM", "02:00PM", "02:15PM", "02:30PM",
			"02:45PM", "03:00PM", "03:15PM", "03:30PM", "03:45PM", "04:00PM", "04:15PM",
			"04:30PM", "04:45PM", "05:00PM", "05:15PM", "05:30PM", "05:45PM", "06:00PM",
			"06:15PM", "06:30PM", "06:45PM", "07:00PM"]
	
	schedule = [] #list of dicts of lists, days -> timeslot -> appointment list
	locations = None
	roles = None

	for day in range(util.DAYS_IN_WEEK):
		schedule.append({})
	
	#the beginning of the week - the week is either given or the current week is used
	startDate = util.startOfWeek(util.toDatetime(date) if date else util.today())
	tab = int(tab)
	
	#build a list of maps of time to appointments with some default values
	#prepopulated so they are always displayed
	for day in schedule:
	
		for timeslot in standardSlots:
		
			day[timeslot] = []
	
	#get a database connection
	conn = services.getConnection()
	
	#get all the locations and roles
	locations = services.getLocations(conn)
	roles = sorted(services.getRoles(conn))
	
	#get all the appointments for the week and add them to the schedule
	for appointment in services.getAppointments(conn, startDate):
		
		time = appointment.getFTime()
		weekday = appointment.time.weekday()
		
		#if the appointment is not scheduled for one of the standard times
		#then add that time slot
		if time not in schedule[weekday]:
			
			schedule[weekday][time] = []

		schedule[weekday][time].append(appointment)
			
	conn.close()
	
	#format and return the page
	return build(locations, roles, schedule, startDate, tab)
コード例 #7
0
ファイル: appointment.py プロジェクト: jworr/scheduler
	def __init__(self, time, staffName, location, appType, description=None, clientName=None, purpose=None, previousClient=None, contactNumber=None, madeBy=None, dateMade=None, advocateCalled=None, confirmedBy=None, dateConfirmed=None, lastPeriod=None):
		"""
		Creates a new Appointment
		time - a standard string timestamp in the form of YYYY-MM-DD HH:MM:SS
		staffName - the name of the staff member the appointment is for
		location - the name of the location of the appointment
		appType - the role of the person the appointment is for
		"""
		self.time = util.toDatetime(time)
		self.staffName = staffName
		self.location = location
		self.description = description
		self.clientName = clientName
		self.purpose = purpose
		self.previousClient = previousClient
		self.contactNumber = contactNumber
		self.madeBy = madeBy
		self.dateMade = util.toDatetime(dateMade)
		self.advocateCalled = advocateCalled
		self.confirmedBy = confirmedBy
		self.dateConfirmed = util.toDatetime(dateConfirmed)
		self.lastPeriod = util.toDatetime(lastPeriod)
		self.appType = appType
コード例 #8
0
ファイル: appointment.py プロジェクト: jworr/scheduler
def delete( name, timestamp ):
	"""
	deletes the appointment identified by given timestamp and name
	"""
	results = process.ERROR_PAGE
	datetime = util.toDatetime(timestamp)
	connection = services.getConnection()
	
	#if the data is valid then delete the appointment and redirect to the 
	#main page
	if services.nameExists(connection, name) and datetime:
		
		services.deleteAppointment(connection, datetime, name)
		results = REDIRECT % (util.toDateStr(datetime), datetime.weekday())
	
	connection.close()
	
	return results
コード例 #9
0
ファイル: daydetails.py プロジェクト: jworr/scheduler
def display(startDateStr, location):
	"""
	Displays a detailed list of the days appointments
	"""
	startOfWeek = util.toDatetime( startDateStr )
	connection = services.getConnection()
	appointments = []
	
	#make the appointment list nested - a list for each day of the week
	for day in range(util.DAYS_IN_WEEK):
		appointments.append( [] )
	
	#add all the appointments to the list
	for appointment in services.getAppointments(connection, startOfWeek, location):
		
		weekday = appointment.time.weekday()
		
		appointments[weekday].append(appointment)
		
	return build( appointments, startOfWeek, location )
コード例 #10
0
ファイル: webCal.py プロジェクト: jworr/scheduler
def buildSlot(locations, roles, apps, theDate, hourStamp, highlight):
	"""
	builds the HTML to represent a timeslot, i.e. a row in the calendar
	locations - a list of all the locations (strings)
	roles - a list of all the roles (role objects)
	apps - a list of all the appointments for the hour (appoinment objects)
	theDate - a date object representing the given day
	hourStamp - a formatted string representing the hour to build the html for
	highlight - a boolean for if the row should be 
	"""
	result = "<tr %s><td>%s</td>" % (ROW_COLOR_TAG2 if highlight else "", hourStamp)
	
	#for each location
	for i, loc in enumerate(locations):

		#pick the color of the row if the row is to be highlighted 
		colorTag = (ROW_COLOR_TAG if i % 2 else ROW_COLOR_TAG2) if highlight else ""

		#for each role
		for role in roles:

			#find all the appointments for the current location/site
			relevant = filter(lambda a: a.location == loc and a.getAppType() == role.roleId, apps)
			
			#build html for each appointment
			if len(relevant):
				result += "<td %s>" % colorTag

				for app in relevant:
					result += APP_TEMPLATE % ("class=\"booked\"" if app.isBooked() else "", \
					app.staffName, app.time, app.getAppType(), app.staffName)
				
				result += "</td>"
				
			#else build a placeholder
			else:
				result += NO_APP_TEMPLATE % (colorTag, role.roleId, loc, util.toDatetime(util.toDateStr(theDate),hourStamp))
				
	return result + "</tr>"
コード例 #11
0
ファイル: ajax.py プロジェクト: jworr/scheduler
def isAppointmentConflict(name, timestamp):
	"""
	Returns an html snipit saying whether or not there is a conflict with another appointment
	"""
	appointment = None
	result = ""
	
	datetime = util.toDatetime(timestamp);
	connection = services.getConnection()
	
	#lookup an appointment for that time for that person, if we have the whole
	#timestamp
	if datetime:
		appointment = services.getAppointment(connection, datetime, name)
	
	#if an appointment was found generate an error string
	if appointment:
		result = "There is already an appointment for %s on %s at %s" %( appointment.staffName, appointment.getFDate(), appointment.getFTime() )
	
	connection.close()
	
	return result
コード例 #12
0
ファイル: appointment.py プロジェクト: jworr/scheduler
def add( date, time, staff, location, desc, addToSupport=False, addToMedical=False, \
oldName=None, oldTime=None, oldDate=None, **kwargs):
	"""
	Checks the given data and if it looks valid then add/update the appointment
	date - the date of the appointment
	time - the time of the appointment
	location - the location
	desc - generic text about the appt
	oldName - the previous person the appt was for
	oldTime - the previous time of the appt
	oldDate - the previous date of the appt
	addToSupport - copy all the information to the support appointment at the
					same time and place
	addToMedical - copy all the information to the medical appointment at the
					same time and place
	kwargs - a collection of optional data (the names of the form field match 
				the names of the appointment fields
	"""
	result = None
	oldTimestamp = None
	date = util.strip(date)
	name = util.strip(staff)
	location = util.strip(location)
	supportAppts = None
	medicalAppts = None

	#set all the optional parameters to None if they are an empty string
	for key,value in kwargs.items():
		if value == "":
			kwargs[key] = None
	
	conn = services.getConnection()
	datetime = util.toDatetime(date, time)

	#check the required data for errors
	validData = services.locationExists(conn, location) \
	and datetime != None and services.nameExists(conn, name) \
	and checkDate(kwargs["lastPeriod"]) \
	and checkDate(kwargs["dateConfirmed"])
	
	#check the old name of the appointment if one was given	
	if oldName:
		oldName= util.strip(oldName)
		validData = validData and services.nameExists(conn, oldName)
	
	#assemble the old timestamp for the appointment if all the information was given
	if oldTime and oldDate:
		oldTimestamp = util.toDatetime(util.strip(oldDate), util.strip(oldTime))
		validData = validData and oldTimestamp != None
	
	#if we are not performing an update then check to see if the new appointment
	#time and person are not already taken
	if not (oldTimestamp == datetime and oldName == staff):
		validData= validData and not services.getAppointment(conn, datetime, staff)

	if addToSupport:
		supportAppts = services.getAppsAtTime(conn, datetime, location, model.role.SUPPORT)
		validData = validData and len(supportAppts)

	if addToMedical:
		medicalAppts = services.getAppsAtTime(conn, datetime, location, model.role.MEDICAL)
		validData = validData and len(medicalAppts)

	#if the data was valid than save it to the database	
	if validData:

		otherAppts = []

		#create the appointment object
		appointment = Appointment(datetime, name, location, None, desc, **kwargs)
		
		#flush the appointment object to the database
		appointment.flush(conn, oldTimestamp, oldName)

		if addToSupport:
			otherAppts += supportAppts	

		if addToMedical:
			otherAppts += medicalAppts

		#add the one extra field that needs to be updated as well
		kwargs["description"] = desc

		#update all the other appointments
		for appt in otherAppts:
			model.updateAll(appt, kwargs)
			appt.flush(conn, appt.time, appt.staffName)

		#set the redirect for the brower
		result = REDIRECT % (date, datetime.weekday())
		
	#else show an error page
	else:
		result = process.ERROR_PAGE

	conn.close()
		
	return result
コード例 #13
0
ファイル: koha.py プロジェクト: bluestemscott/librarygadget
 def parse_due_date(self, td, item):
     item.dueDate = util.toDatetime(td.string.strip())
     return item
コード例 #14
0
 def parseDueDate(self, td, item):
     links = td.findAll("a", {"class": lambda (x): x != "boldRedFont1"})
     item.dueDate = util.toDatetime(links[0].string.strip())
     return item
コード例 #15
0
 def parseDueDate(self, td, item):
     span = td.find('span')
     item.dueDate = util.toDatetime(span.string.strip())
     return item
コード例 #16
0
ファイル: servicesTest.py プロジェクト: jworr/scheduler
def run():
	
	#YYYY-MM-DD HH:MM:SS
	
	#--------------------------SETUP------------------------------------------
	conn = services.getConnection()
	staff = [ model.staff.StaffMember("test1", 1, False), model.staff.StaffMember("test2", 1, True), model.staff.StaffMember("test3", 2, True) ]
	apps = [ model.appointment.Appointment("2010-12-25 11:00:00", "test1", "Albany"),
			model.appointment.Appointment("2010-12-23 00:00:00", "test1", "Corvallis"),
			model.appointment.Appointment("2010-12-21 00:00:00", "test2", "Albany"),
			model.appointment.Appointment(util.toDatetime("2010-12-25 00:00:00"), "test3", "Albany"),
			model.appointment.Appointment("2010-12-24 00:00:00", "test3", "Corvallis"),
			model.appointment.Appointment("2010-11-24 00:00:00", "test3", "Corvallis") ]
	
	objs = []

	for a in apps:
		services.deleteAppointment(conn, a.time, a.staffName)
		
	for s in staff:
		services.deleteStaff(conn, s.name)

	for s in staff:
		objs.append(s)
	
	for a in apps:
		objs.append(a)
		
	for o in objs:
		o.flush(conn)
	
	#-----------------------------ALL STAFF-----------------------------------

	#all staff
	results = filterList( services.getAllStaff(conn), staff )
	print "all staff", len(results) == 3
	
	#only role 1
	results = filterList( services.getAllStaff(conn, roleId = 1), staff )
	print "role 1 staff", len(results) == 2
		
	#only active
	results = filterList( services.getAllStaff(conn, active=True), staff )
	print "active staff", len(results) == 2
	
	#only inactive, role 1
	results = filterList( services.getAllStaff(conn, active=False, roleId = 1), staff )
	print "inactive, role 1 staff", len(results) == 1
	

	#------------------------------ALL APPOINTMENTS---------------------------
	
	#all appointments
	results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00"))), apps )
	print "all appointments", len(results) == 5
	
	#only role 1
	results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00")), roleId = 1), apps )
	print "role 1 appointments", len(results) == 3
	
	#only Albany
	results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00")), location = "Albany"), apps )
	print "Albany appointments", len(results) == 3

	#only Corvallis role 2
	results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00")), location = "Corvallis", roleId = 2), apps )
	print "role 2 corvallis appointments", len(results) == 1
	
	#---------------------------------ROLES-------------------------------------
	print "3 Roles found", len( services.getRoles(conn) ) == 3
	
	#---------------------------CLEAN UP--------------------------------------
	for a in apps:
		services.deleteAppointment(conn, a.time, a.staffName)
		
	for s in staff:
		services.deleteStaff(conn, s.name)
コード例 #17
0
ファイル: booking.py プロジェクト: jworr/scheduler
def convert(date):
	return util.toDatetime(date) if type(date) == str and len(date) > 0 else date