Пример #1
0
def settings():
    if request.method == 'GET':
        profile = Profile.get_or_create(users.get_current_user())
        return jinja.get_template('settings.html').render(locals())

    elif request.method == 'POST':
        profile = Profile.get_or_create(users.get_current_user())
        profile.timezone_offset = int(request.form.get('timezone_offset'))
        profile.digest_hour = int(request.form.get('digest_hour'))
        profile.prompt_hour = int(request.form.get('prompt_hour'))
        profile.put()
        return redirect(request.path)
Пример #2
0
def home():
    if request.method == 'GET':
        profile = Profile.get_or_create(users.get_current_user())
        edit = request.query_string == 'edit'
        return jinja.get_template('home.html').render(locals())

    elif request.method == 'POST':
        profile = Profile.get_or_create(users.get_current_user())
        if request.query_string == 'edit':
            e = profile.entry_today
            e.body = request.form.get('body')
        else:
            e = Entry(body=request.form.get('body'))
        e.put()
        return redirect(request.path)
Пример #3
0
	def get(self):
		profile = Profile.get_or_create()
		assert profile is not None
		
		agencies = Agency.query(Agency.enabled == True)
		if agencies.count(limit=1) < 1:
			agencies = None

		context = dict(
			object_list=agencies,
			report_count=StopReport.query(StopReport.user == profile.key).count(limit=100),
		)
		self.render_to_response('agency_list.html', context)
Пример #4
0
def get_or_create_profile(msg):
    """Prompt `msg`, then create the profile if it doesn't exist and return it
    """
    profile_name = input(msg).lower().strip()
    profile, created = Profile.get_or_create(name=profile_name)

    if created:
        print("Profile was created for {}.".format(profile.name))

    calculate_gpa(profile)

    clear()
    return profile
Пример #5
0
	def post(self):
		profile = Profile.get_or_create()
		assert profile is not None

		agency_id = self.request.get('agency_id')
		vehicle = self.request.get('vehicle')
		card_id = self.request.get('card_id')
		known_stop = self.request.get('known_stop')
		stop_name = self.request.get('stop_name')
		comment = self.request.get('comment')

		# Start validation!
		# Check agency
		try:
			agency = Agency.get_by_id(int(agency_id))
			if agency is None or not agency.enabled:
				# Invalid agency
				return self.send_404()
		except:
			return self.send_404()

		# Check vehicle type
		if vehicle not in VEHICLE_TYPES or vehicle not in agency.vehicle_types:
			return self.send_404()

		# Check card id
		try:
			card_id = int(card_id)
		except:
			# invalid card id, not a number.
			return self._retry_form(agency, vehicle, card_id, known_stop, stop_name, comment, 'Card ID is not a number')

		# Check known_stop
		if known_stop != '':
			try:
				known_stop = Stop.get_by_id(int(known_stop))
				if known_stop.agency.id() != agency.key.id():
					# stop is not for agency
					known_stop = None
			except:
				
				known_stop = None
		
		if known_stop is None:
			# Invalid stop
			return self._retry_form(agency, vehicle, card_id, known_stop, stop_name, comment, 'Stop ID is not valid')

		if known_stop == '':
			known_stop = None

		# Check stop_name is present if known_stop is not
		if known_stop is None and stop_name == '':
			# Custom name not specified and no known stop selected.
			return self._retry_form(agency, vehicle, card_id, known_stop, stop_name, comment, 'No stop name was entered')

		# If the user is banned, then say we processed the report, but don't
		# actually store it anywhere.
		if not profile.banned:
			# Now get the extra metadata and make the report
			country = self.request.headers.get('x-appengine-country', 'XX')
			region = self.request.headers.get('x-appengine-region', '')
			city = self.request.headers.get('x-appengine-city', '')
			ip = self.request.remote_addr
		
			report = StopReport(
				agency=agency.key,
				stop=known_stop.key if known_stop else None,
				name=stop_name,
				stop_type=vehicle,
				card_id=str(card_id),
				comment=comment,
				gae_country=country,
				gae_region=region,
				gae_city=city,
				gae_ip=ip,
				user=profile.key
			)
			report.put()
		
		context = dict(
			agency_name=agency.name,
			agency_id=agency.key.id(),
		)
		self.render_to_response('report_sent.html', context)