Example #1
0
def serveTerm(request, format, term, resource=""):
    backlinks = os.path.join(os.path.dirname(__file__), 'backlinks.json')
    mappings = os.path.join(os.path.dirname(__file__), 'mapping.json')

    isJsonp = format == 'jsonp'
    
    backlinksInfo = json.load(open(backlinks))
    mapping = json.load(open(mappings))
    backlinks = backlinksInfo['backlinks']
    
    if resource:
        result = json.dumps(lookup(term,resource,mapping,backlinks))
    else:
        result = []
        resources = backlinksInfo['resources']
        for resource in resources:
            cResult = lookup(term,resource,mapping,backlinks)
            cResult['name'] = resource
            cResult['fullName'] = resources[resource]['fullName']
            cResult['isLinkable'] = resources[resource]['isLinkable']
            result.append(cResult)
        result = json.dumps(result)
    if isJsonp:
       result = request.GET.get('callback', 'callback') + '(' + result + ')'
    return HttpResponse(result, content_type='application/javascript' if isJsonp else 'text/json')
Example #2
0
 def test_cosmo(self):
     matches = lookup('cosmo')
     self.assertEqual(matches.sort(),
                      ["cosmo", "cosmos", "cosmote", "cosmocom", "cosmogony", "cosmochim", "cosmogirl", "cosmonaut",
                       "cosmonazi", "cosmology", "cosmopolis", "cosmodrome", "cosmogenic", "cosmograph",
                       "cosmonauts", "cosmologies", "microcosmos", "cosmosworks", "cosmologist", "cosmological",
                       "cosmochimica", "cosmologists", "cosmopolitan", "cosmopolitans", "cosmopolitanism"].sort())
Example #3
0
 def test_environ(self):
     matches = lookup('environ')
     self.assertEqual(matches.sort(),
                      ["environ", "environm", "environs", "environme", "environet", "environics", "environews",
                       "environmen", "environment", "environement", "environments", "environmental", "environnement",
                       "dbenvironment", "newenvironment", "environmetrics", "environmentally", "microenvironment",
                       "environmentalism", "environmentalist", "geoenvironmental", "bioenvironmental",
                       "environnementale", "environnementaux", "environmentalists"].sort())
Example #4
0
def user(name):
    search = SearchForm()
    if request.method == "POST":
        # if search.validate_on_submit():
        l = search.note.data
    else:
        l = ''
    ls = lookup(l)
    return render_template('user.html', name=name, search=search, ls=ls)
Example #5
0
	def post(self, rota_id=None):
		rota = models.lookup(rota_id)

		email = self.request.POST.get('email')

		if email not in rota.members:
			rota.members.append(email)

		rota.put()

		return webapp2.redirect('/rota/' + rota.key.urlsafe())
Example #6
0
	def get(self, person_id=None):
		template = jinja_environment.get_template('people/person.html')

		template_values = {
			'form_action': "/person",
			'person': None,
		}

		if person_id:
			person = models.lookup(person_id)
			template_values.update({
				'form_action': "/person/{0}".format(person.key.urlsafe()),
				'person': person,
				})

		self.response.out.write(template.render(template_values))
Example #7
0
	def get(self, rota_id=None):
		template = jinja_environment.get_template('rota.html')

		template_values = {}

		if rota_id:
			rota = models.lookup(rota_id)

			if not rota:
				return webapp2.abort(404, 'Rota not found')

			template_values.update({
					'rota': rota,
					'schedule' : schedule.calculate(rota),
				})

		self.response.out.write(template.render(template_values))
Example #8
0
	def get(self, rota_id):

		if not 'api-key' in self.request.GET:
			webapp2.abort(400, 'No API key specified')
			return

		api_key = self.request.get('api-key')
		if api_key not in configuration.lookup('VALID_API_KEYS', "").split(','):
			webapp2.abort(400, 'The API key {0} specified is invalid'.format(api_key))
			return

		rota = models.lookup(rota_id)

		payload = {
			'rota_id': rota_id,
			'current': rota.current,
		}

		headers.json(self.response)
		self.response.out.write(json.dumps(payload))
Example #9
0
	def post(self, person_id=None):
		person = None
		
		name = self.request.POST.get('name')
		email = self.request.POST.get('email')

		if not person_id:
			person = models.person(name, email)

		if person_id:
			person = models.lookup(person_id)
			person.name = name
			person.email = email

		if 'phone_number' in self.request.POST:
			person.phone_number = self.request.POST.get('phone_number')

		person.put()

		return webapp2.redirect('/person/{0}'.format(person.key.urlsafe()))
Example #10
0
	def post(self):
		request = self.request

		rota_id = request.POST.get('rota_id')
		name = request.POST.get('name')
		description = request.POST.get('description')
		start_date = datetime.datetime.strptime(request.POST.get('start_date'), '%Y-%m-%d').date()
		interval = int(request.POST.get('frequency'))
		observer_emails = request.POST.get('observer_emails')

		today = datetime.date.today()

		next_start_date = start_date + datetime.timedelta(days=interval)

		if today == start_date:
			next_start_date = start_date

		rota = None

		if not rota_id: 
			rota = models.Rota(name=name, description=description,
				start_date=start_date, interval=interval,
				next_start_date=next_start_date)
		else:
			rota = models.lookup(rota_id)

			rota.name = name
			rota.description = description
			rota.interval = interval
			rota.start_date = start_date

		if observer_emails:
			rota.observing_emails = observer_emails.split(',')

		rota.put()

		return webapp2.redirect('/rota/' + rota.key.urlsafe())
Example #11
0
 def setModel (self, model=None, number=None):
   if number:
     self.model = models.lookup(number, self)
   if model:
     self.model = model
Example #12
0
 def setModel(self, model=None, number=None):
     if number:
         self.model = models.lookup(number, self)
     if model:
         self.model = model
Example #13
0
 def test_the(self):
     matches = lookup('the')
     self.assertEqual(matches.sort(),
                      ["the", "thew", "nthe", "they", "thee", "thep", "thea", "thel", "ithe", "theg", "ethe", "fthe",
                       "thef", "rthe", "thed", "them", "thec", "thex", "then", "sthe", "cthe", "ythe", "gthe",
                       "uthe", "mthe"].sort())
Example #14
0
def role(name):
    ls = lookup(name)
    return render_template('role.html', role=ls)