Ejemplo n.º 1
0
    def GET(self):
        # Must be logged in.
        login_required()

        # List all their sources.
        sources = UserSources.get_user_sources(users.get_current_user())
        sources = sorted(sources, key=lambda source: source.title)
        renderer.addData('sources', sources)

        # List messages, optionally filtered by the source.
        source = self.get_source()
        if source:
            messages = UserMessages.get_user_messages_for_source(source)
        else:
            messages = UserMessages.get_user_messages(users.get_current_user())

        messages = sorted(messages,
                          key=lambda message: message.timestamp
                          if message else datetime.datetime.now())
        messages.reverse()

        renderer.addData('filtersource', source)
        renderer.addData('messages', messages)
        renderer.addData(
            'storedMessages',
            len(
                UserMessages.get_user_message_collection(
                    users.get_current_user()).messages))

        return renderer.render('messages/index.html')
Ejemplo n.º 2
0
    def GET(self, action):
        if action == 'create' or action == 'edit':
            source = self.get_source()
            renderer.addTemplate('action', self.get_pretty_action(action))

            form = self.get_form()
            form.fill(source.dict())

            renderer.addTemplate('form', form)
            return renderer.render('sources/edit.html')
        elif action == 'get':
            # Just get the object.
            source = self.get_source()
            renderer.addData('source', source)
            return renderer.render('sources/detail.html')
        elif action == 'delete':
            # Show deletion information page.
            source = self.get_source()
            renderer.addData('source', source)
            return renderer.render('sources/delete.html')
        elif action == 'test':
            # Use the same handler as the POST action.
            return self.POST(action)
        else:
            # List. Not fully supported - see the profile instead.
            # Although - handy for API's.
            sources = UserSources.get_user_sources(users.get_current_user())
            renderer.addDataList('sources', sources)
            return renderer.render('sources/list.html')
Ejemplo n.º 3
0
	def GET(self, action):
		if action == 'create' or action == 'edit':
			source = self.get_source()
			renderer.addTemplate('action', self.get_pretty_action(action))
			
			form = self.get_form()
			form.fill(source.dict())

			renderer.addTemplate('form', form)
			return renderer.render('sources/edit.html')
		elif action == 'get':
			# Just get the object.
			source = self.get_source()
			renderer.addData('source', source)
			return renderer.render('sources/detail.html')
		elif action == 'delete':
			# Show deletion information page.
			source = self.get_source()
			renderer.addData('source', source)
			return renderer.render('sources/delete.html')
		elif action == 'test':
			# Use the same handler as the POST action.
			return self.POST(action)
		else:
			# List. Not fully supported - see the profile instead.
			# Although - handy for API's.
			sources = UserSources.get_user_sources(users.get_current_user())
			renderer.addDataList('sources', sources)
			return renderer.render('sources/list.html')
Ejemplo n.º 4
0
	def get_source(key):
		pointer = SourcePointer.get_pointer(key)
		if pointer:
			source_collection = UserSources.get_user_source_collection(pointer.owner)
			source = UserSource.get_by_id(pointer.sourceId, source_collection)
			return source
		else:
			return None
Ejemplo n.º 5
0
 def get_source(key):
     pointer = SourcePointer.get_pointer(key)
     if pointer:
         source_collection = UserSources.get_user_source_collection(
             pointer.owner)
         source = UserSource.get_by_id(pointer.sourceId, source_collection)
         return source
     else:
         return None
Ejemplo n.º 6
0
	def GET(self):
		# Must be logged in.
		login_required()

		# List all their sources.
		sources = UserSources.get_user_sources(users.get_current_user())
		sources = sorted(sources, key=lambda source: source.title)
		renderer.addDataList('sources', sources)

		# List all their devices.
		devices = UserDevices.get_user_devices(users.get_current_user())
		devices = sorted(devices, key=lambda device: device.updated)
		renderer.addDataList('devices', devices)

		return renderer.render('profile/index.html')
Ejemplo n.º 7
0
    def GET(self):
        # Must be logged in.
        login_required()

        # List all their sources.
        sources = UserSources.get_user_sources(users.get_current_user())
        sources = sorted(sources, key=lambda source: source.title)
        renderer.addDataList('sources', sources)

        # List all their devices.
        devices = UserDevices.get_user_devices(users.get_current_user())
        devices = sorted(devices, key=lambda device: device.updated)
        renderer.addDataList('devices', devices)

        return renderer.render('profile/index.html')
Ejemplo n.º 8
0
	def get_source(self):
		# Helper function to get the source object from the URL.
		input = web.input(sid=None)
		if input.sid:
			# Load source by ID.
			source_collection = UserSources.get_user_source_collection(users.get_current_user())
			source = UserSource.get_by_id(long(input.sid), source_collection)
			if not source:
				# It does not exist.
				raise web.notfound()

			# Check that the source belongs to the logged in user.
			if source.owner.user_id() != users.get_current_user().user_id():
				# It's not theirs. 404.
				raise web.notfound()

			return source
		else:
			# No source selected.
			return None
Ejemplo n.º 9
0
    def get_source(self):
        # Helper function to get the source object from the URL.
        input = web.input(sid=None)
        if input.sid:
            # Load source by ID.
            source_collection = UserSources.get_user_source_collection(
                users.get_current_user())
            source = UserSource.get_by_id(long(input.sid), source_collection)
            if not source:
                # It does not exist.
                raise web.notfound()

            # Check that the source belongs to the logged in user.
            if source.owner.user_id() != users.get_current_user().user_id():
                # It's not theirs. 404.
                raise web.notfound()

            return source
        else:
            # No source selected.
            return None
Ejemplo n.º 10
0
	def GET(self):
		# Must be logged in.
		login_required()
		mailbody = "Newtifry user data : \n"
		mailbody += "User : "******"\n"
		mailbody += "Message count : " + str(get_message_count(users.get_current_user())) + "\n"
		mailbody += "Sources : \n"
		# List all their sources.
		sources = UserSources.get_user_sources(users.get_current_user())
		sources = sorted(sources, key=lambda source: source.title)
		for source in sources:
			mailbody += source.title + " "
			if source.enabled:
				mailbody += "Enabled " 
			else:
				mailbody += "Disabled "
			mailbody += source.externalKey + "\n"
		mailbody += "\nDevices : \n"

		devices = UserDevices.get_user_devices(users.get_current_user())
		devices = sorted(devices, key=lambda device: device.updated)
		for device in devices:
			mailbody += device.deviceNickname + "\n\tHash : " + device.hash() + "\n\tDevicekey " + device.deviceKey + "\n\tDevice Version " + device.deviceVersion + "\n"
		
		mailbody += "\n\nRegards\n"
		
#		renderer.addDataList('sources', sources)
#		renderer.addData('messagecount', get_message_count(users.get_current_user()));
#		renderer.addData('messageleft', get_quota(users.get_current_user()));

		# List all their devices.
#		renderer.addDataList('devices', devices)
		mail.send_mail(sender="Newtifry <*****@*****.**>", to="Newtifry user " + users.get_current_user().email(), subject="Newtifry user data", body=mailbody)

		renderer.addData('owner_mail', users.get_current_user().email())
		return renderer.render('profile/datasent.html')
Ejemplo n.º 11
0
	def GET(self):
		# Must be logged in.
		login_required()

		# List all their sources.
		sources = UserSources.get_user_sources(users.get_current_user())
		sources = sorted(sources, key=lambda source: source.title)
		renderer.addData('sources', sources)

		# List messages, optionally filtered by the source.
		source = self.get_source()
		if source:
			messages = UserMessages.get_user_messages_for_source(source)
		else:
			messages = UserMessages.get_user_messages(users.get_current_user())

		messages = sorted(messages, key=lambda message: message.timestamp if message else datetime.datetime.now())
		messages.reverse()

		renderer.addData('filtersource', source)
		renderer.addData('messages', messages)
		renderer.addData('storedMessages', len(UserMessages.get_user_message_collection(users.get_current_user()).messages))

		return renderer.render('messages/index.html')
Ejemplo n.º 12
0
	def POST(self, action):
		if action == 'list':
			sources = UserSources.get_user_sources(users.get_current_user())
			renderer.addDataList('sources', sources)
			return renderer.render('sources/list.html')
		elif action == 'get':
			source = self.get_source()
			renderer.addData('source', source)
			return renderer.render('sources/detail.html')
		elif action == 'test':
			# Send a test message to the source.
			source = self.get_source()

			# Fix up the source pointer. Useful if it's broken somehow.
			SourcePointer.persist(source)

			# Now create the test message.
			message_collection = UserMessages.get_user_message_collection(users.get_current_user())
			message = UserMessage.create_test(source, web.ctx.ip, message_collection)
			def transaction(message):
				message.put()
				message_collection = UserMessages.get_user_message_collection_static(users.get_current_user())
				message_collection.add_message(message)
				message_collection.put()
			db.run_in_transaction(transaction, message)

			sender = AC2DM.factory()
			sender.send_to_all(message)

			# And we're done.
			return renderer.render('sources/test.html')
		elif action == 'delete':
			source = self.get_source()
			message_collection = UserMessages.get_user_message_collection(source.owner)
			message_collection.delete_for_source(source)
			source_collection = UserSources.get_user_source_collection(users.get_current_user())

			# Notify devices that something changed.
			# Also, if given a device, exclude that device from
			# the notification.
			input = web.input(device = None)
			source.notify_delete(input.device)
			def transaction(source):
				source_collection = UserSources.get_user_source_collection_static(users.get_current_user())
				source_collection.remove_source(source)
				source.delete()
				source_collection.put()
			db.run_in_transaction(transaction, source)

			# Remove the pointer. If this fails, it's not a big issue, as it's
			# checked anyway before use.
			SourcePointer.remove(source)

			renderer.addData('success', True)
			return renderer.render('sources/deletecomplete.html')
		else:
			source = self.get_source()

			# Get the form and the form data.
			form = self.get_form()
			form.fill(source.dict())

			if not form.validates():
				# Failed to validate. Display the form again.
				renderer.addTemplate('action', self.get_pretty_action(action))
				renderer.addTemplate('form', form)
				errors = form.getnotes()
				renderer.addDataList('errors', errors)
				return renderer.render('sources/edit.html')
			else:
				# Validated - proceed.
				source.updated = datetime.datetime.now()
				source.title = form.title.get_value()
				#source.description = form.description.get_value()
				source.enabled = False
				source.owner = users.get_current_user()
				if form.enabled.get_value():
					source.enabled = True

				# Make sure the source collection exists.
				UserSources.get_user_source_collection(users.get_current_user())
				
				# Place into source collection.
				def transaction(source):
					source_collection = UserSources.get_user_source_collection_static(users.get_current_user())
					source.put()
					source_collection.add_source(source)
					source_collection.put()
				db.run_in_transaction(transaction, source)

				# Set up the source pointer.
				SourcePointer.persist(source)

				# Notify devices that something changed.
				# Also, if given a device, exclude that device from
				# the notification.
				input = web.input(device = None)
				source.notify(input.device)

				if renderer.get_mode() == 'html':
					# Redirect to the source list.
					raise web.found('/profile')
				else:
					# Send back the source data.
					renderer.addData('source', source)
					return renderer.render('apionly.html')
Ejemplo n.º 13
0
	def POST(self, action):
		if action == 'list':
			sources = UserSources.get_user_sources(users.get_current_user())
			renderer.addDataList('sources', sources)
			return renderer.render('sources/list.html')
		elif action == 'get':
			source = self.get_source()
			renderer.addData('source', source)
			return renderer.render('sources/detail.html')
		elif action == 'test':
			# Send a test message to the source and the caller device id.
			source = self.get_source()
			input = web.input(deviceid=None, language=None, src=None)
			logging.debug("Test DDB language : " + get_user_language(users.get_current_user()))
			if input.src:
				logging.debug("Test src : " + input.src)
			if input.language:
				logging.debug("Test input language : " + input.language)

			if input.src and input.src == "web":
				#get language from User DDB
				input.language = get_user_language(users.get_current_user());
			else:
				if get_user_language(users.get_current_user()) == "English":
					logging.debug("DDB is English")
				if get_user_language(users.get_current_user()) == "English" and input.language and input.language != "English":
					logging.debug("Store new language in DDB")
					set_user_language(users.get_current_user(), input.language)
			
			# Fix up the source pointer. Useful if it's broken somehow.
			SourcePointer.persist(source)

			# Now create the test message.
			message_collection = UserMessages.get_user_message_collection(users.get_current_user())
			message = UserMessage.create_test(source, web.ctx.ip, message_collection, input.language)
			
#			def transaction(message):
#				message.put()
#				message_collection = UserMessages.get_user_message_collection_static(users.get_current_user())
#				message_collection.add_message(message)
#				message_collection.put()
#			db.run_in_transaction(transaction, message)

			sender = AC2DM.factory()
			result = sender.send_to_all(message, input.deviceid)
			renderer.addData('messagescount', get_message_count(message.source.owner));
			renderer.addData('result', result);


			# And we're done.
			return renderer.render('sources/test.html')
		elif action == 'delete':
			source = self.get_source()
			message_collection = UserMessages.get_user_message_collection(source.owner)
			message_collection.delete_for_source(source)
			source_collection = UserSources.get_user_source_collection(users.get_current_user())

			# Notify devices that something changed.
			# Also, if given a device, exclude that device from
			# the notification.
			input = web.input(device = None)
			source.notify_delete(input.device)
			def transaction(source):
				source_collection = UserSources.get_user_source_collection_static(users.get_current_user())
				source_collection.remove_source(source)
				source.delete()
				source_collection.put()
			db.run_in_transaction(transaction, source)

			# Remove the pointer. If this fails, it's not a big issue, as it's
			# checked anyway before use.
			SourcePointer.remove(source)

			renderer.addData('success', True)
			return renderer.render('sources/deletecomplete.html')
		else:
			source = self.get_source()

			# Get the form and the form data.
			form = self.get_form()
			form.fill(source.dict())

			if not form.validates():
				# Failed to validate. Display the form again.
				renderer.addTemplate('action', self.get_pretty_action(action))
				renderer.addTemplate('form', form)
				errors = form.getnotes()
				renderer.addDataList('errors', errors)
				return renderer.render('sources/edit.html')
			else:
				# Validated - proceed.
				source.updated = datetime.datetime.now()
				try:
					title = form.title.get_value()
					title.replace('\n', ' ')
					title.replace('\r', ' ')
					source.title = title
				except:
					logging.error('source name error' + form.title.get_value());
					source.title = "Bad source name format"
					
				#source.description = form.description.get_value()
				#source.enabled = False
				source.owner = users.get_current_user()
				#if form.enabled.get_value():
				#  source.enabled = True
				source.enabled = True
				# Make sure the source collection exists.
				UserSources.get_user_source_collection(users.get_current_user())
				
				# Place into source collection.
				def transaction(source):
					source_collection = UserSources.get_user_source_collection_static(users.get_current_user())
					source.put()
					source_collection.add_source(source)
					source_collection.put()
				db.run_in_transaction(transaction, source)

				# Set up the source pointer.
				SourcePointer.persist(source)

				# Notify devices that something changed.
				# Also, if given a device, exclude that device from
				# the notification.
				input = web.input(device = None)
				source.notify(input.device)

				if renderer.get_mode() == 'html':
					# Redirect to the source list.
					raise web.found('/profile')
				else:
					# Send back the source data.
					renderer.addData('source', source)
					return renderer.render('apionly.html')
Ejemplo n.º 14
0
 def transaction(source):
     source_collection = UserSources.get_user_source_collection_static(
         users.get_current_user())
     source.put()
     source_collection.add_source(source)
     source_collection.put()
Ejemplo n.º 15
0
 def transaction(source):
     source_collection = UserSources.get_user_source_collection_static(
         users.get_current_user())
     source_collection.remove_source(source)
     source.delete()
     source_collection.put()
Ejemplo n.º 16
0
    def POST(self, action):
        if action == 'list':
            sources = UserSources.get_user_sources(users.get_current_user())
            renderer.addDataList('sources', sources)
            return renderer.render('sources/list.html')
        elif action == 'get':
            source = self.get_source()
            renderer.addData('source', source)
            return renderer.render('sources/detail.html')
        elif action == 'test':
            # Send a test message to the source.
            source = self.get_source()

            # Fix up the source pointer. Useful if it's broken somehow.
            SourcePointer.persist(source)

            # Now create the test message.
            message_collection = UserMessages.get_user_message_collection(
                users.get_current_user())
            message = UserMessage.create_test(source, web.ctx.ip,
                                              message_collection)

            def transaction(message):
                message.put()
                message_collection = UserMessages.get_user_message_collection_static(
                    users.get_current_user())
                message_collection.add_message(message)
                message_collection.put()

            db.run_in_transaction(transaction, message)

            sender = AC2DM.factory()
            sender.send_to_all(message)

            # And we're done.
            return renderer.render('sources/test.html')
        elif action == 'delete':
            source = self.get_source()
            message_collection = UserMessages.get_user_message_collection(
                source.owner)
            message_collection.delete_for_source(source)
            source_collection = UserSources.get_user_source_collection(
                users.get_current_user())

            # Notify devices that something changed.
            # Also, if given a device, exclude that device from
            # the notification.
            input = web.input(device=None)
            source.notify_delete(input.device)

            def transaction(source):
                source_collection = UserSources.get_user_source_collection_static(
                    users.get_current_user())
                source_collection.remove_source(source)
                source.delete()
                source_collection.put()

            db.run_in_transaction(transaction, source)

            # Remove the pointer. If this fails, it's not a big issue, as it's
            # checked anyway before use.
            SourcePointer.remove(source)

            renderer.addData('success', True)
            return renderer.render('sources/deletecomplete.html')
        else:
            source = self.get_source()

            # Get the form and the form data.
            form = self.get_form()
            form.fill(source.dict())

            if not form.validates():
                # Failed to validate. Display the form again.
                renderer.addTemplate('action', self.get_pretty_action(action))
                renderer.addTemplate('form', form)
                errors = form.getnotes()
                renderer.addDataList('errors', errors)
                return renderer.render('sources/edit.html')
            else:
                # Validated - proceed.
                source.updated = datetime.datetime.now()
                source.title = form.title.get_value()
                #source.description = form.description.get_value()
                source.enabled = False
                source.owner = users.get_current_user()
                if form.enabled.get_value():
                    source.enabled = True

                # Make sure the source collection exists.
                UserSources.get_user_source_collection(
                    users.get_current_user())

                # Place into source collection.
                def transaction(source):
                    source_collection = UserSources.get_user_source_collection_static(
                        users.get_current_user())
                    source.put()
                    source_collection.add_source(source)
                    source_collection.put()

                db.run_in_transaction(transaction, source)

                # Set up the source pointer.
                SourcePointer.persist(source)

                # Notify devices that something changed.
                # Also, if given a device, exclude that device from
                # the notification.
                input = web.input(device=None)
                source.notify(input.device)

                if renderer.get_mode() == 'html':
                    # Redirect to the source list.
                    raise web.found('/profile')
                else:
                    # Send back the source data.
                    renderer.addData('source', source)
                    return renderer.render('apionly.html')
Ejemplo n.º 17
0
			def transaction(source):
				source_collection = UserSources.get_user_source_collection_static(users.get_current_user())
				source_collection.remove_source(source)
				source.delete()
				source_collection.put()
Ejemplo n.º 18
0
				def transaction(source):
					source_collection = UserSources.get_user_source_collection_static(users.get_current_user())
					source.put()
					source_collection.add_source(source)
					source_collection.put()