コード例 #1
0
ファイル: pages.py プロジェクト: activityworkshop/Murmeli
	def servePage(self, view, url, params):
		DbClient.exportAvatars(Config.getWebCacheDir())
		if url == "/send":
			print("send message of type '%(messageType)s' to id '%(sendTo)s'" % params)
		elif url.startswith("/delete/"):
			DbClient.deleteMessageFromInbox(params.get("msgId", ""))
		# Make dictionary to convert ids to names
		contactNames = {c['torid']:c['displayName'] for c in DbClient.getContactList()}
		unknownSender = I18nManager.getText("messages.sender.unknown")
		unknownRecpt = I18nManager.getText("messages.recpt.unknown")
		# Get contact requests, responses and mails from inbox
		conreqs = []
		conresps = []
		mails = []
		for m in DbClient.getInboxMessages():
			m['msgId'] = str(m.get("_id", ""))
			if m['messageType'] == "contactrequest":
				conreqs.append(m)
			elif m['messageType'] == "contactrefer":
				senderId = m.get('fromId', None)
				m['senderName'] = contactNames.get(senderId, unknownSender)
				conreqs.append(m)
			elif m['messageType'] == "contactresponse":
				if not m.get('accepted', False):
					m['messageBody'] = I18nManager.getText("messages.contactrequest.refused")
					m['fromName'] = DbClient.getProfile(m['fromId'], True).get("displayName")
				elif not m.get('messageBody', False):
					m['messageBody'] = I18nManager.getText("messages.contactrequest.accepted")
				conresps.append(m)
			else:
				senderId = m.get('fromId', None)
				if not senderId and m.get('signatureKeyId', None):
					senderId = DbClient.findUserIdFromKeyId(m['signatureKeyId'])
				m['senderName'] = contactNames.get(senderId, unknownSender)
				m['sentTimeStr'] = self.makeLocalTimeString(m['timestamp'])
				# Split m['recipients'] by commas, and look up each id with contactNames
				recpts = m.get('recipients', '')
				if recpts:
					m['recipients'] = ", ".join([contactNames.get(i, unknownRecpt) for i in recpts.split(",")])
				else:
					m['recipients'] = unknownRecpt
				mails.append(m)
		bodytext = self.messagestemplate.getHtml({"contactrequests":conreqs, "contactresponses":conresps,
			"mails":mails, "nummessages":len(conreqs)+len(conresps)+len(mails),
			"webcachedir" : Config.getWebCacheDir()})
		contents = self.buildPage({'pageTitle' : I18nManager.getText("messages.title"),
			'pageBody' : bodytext,
			'pageFooter' : "<p>Footer</p>"})
		view.setHtml(contents)
コード例 #2
0
ファイル: pages.py プロジェクト: activityworkshop/Murmeli
	def servePage(self, view, url, params):
		self.requirePageResources(['button-addperson.png', 'button-drawgraph.png', 'avatar-none.jpg'])
		DbClient.exportAvatars(Config.getWebCacheDir())
		if url == "/add" or url == "/add/":
			contents = self.generateAddPage()
			view.setHtml(contents)
			return
		elif url == "/submitaddrequest":
			print("Submit add request!:", url)
			if len(params) > 0:
				# request to add a new friend
				recipientid  = params.get('murmeliid', '')
				dispname     = params.get('displayname', '')
				intromessage = params.get('intromessage', '')
				if len(recipientid) == 16:
					# TODO: How to react if: person already added (untrusted/trusted); request already sent (requested)
					# update the database accordingly
					ContactMaker.handleInitiate(recipientid, dispname)
					print("I should send an add request to '%s' now." % recipientid)
					outmsg = message.ContactRequestMessage(introMessage=intromessage)
					outmsg.recipients = [recipientid]
					DbClient.addMessageToOutbox(outmsg)
				else:
					print("Hmm, show an error message here?")
				# in any case, go back to contact list
				url = "/" + recipientid
				# ensure that picture is generated for new id
				DbClient.exportAvatars(Config.getWebCacheDir())
		contents = None
		userid   = None
		pageParams = {}
		# Split url into components /userid/command
		command = [i for i in url.split("/") if i != ""]
		if len(command) > 0 and len(command[0]) == 16 and re.match("([a-zA-Z0-9]+)$", command[0]):
			userid = command[0]
			# check for command edit or submit-edit
			if len(command) == 2:
				if command[1] == "edit":
					contents = self.generateListPage(doEdit=True, userid=userid) # show edit fields
				elif command[1] == "submitedit":
					DbClient.updateContact(userid, params)
					# don't generate contents, go back to details
				elif command[1] == "delete":
					ContactMaker.handleDeleteContact(userid)
					userid = None
				elif command[1] == "checkfingerprint":
					contents = self.generateFingerprintsPage(userid)
				elif command[1] == "checkedfingerprint":
					givenAnswer = int(params.get('answer', -1))
					fc = self._makeFingerprintChecker(userid)
					expectedAnswer = fc.getCorrectAnswer()
					if expectedAnswer == givenAnswer:
						ContactMaker.keyFingerprintChecked(userid)
						# Show page again
						contents = self.generateFingerprintsPage(userid)
					else:
						# Add a message to show when the list page is re-generated
						pageParams['fingerprint_check_failed'] = True

		# If we haven't got any contents yet, then do a show details
		if not contents:
			# Show details for selected userid (or for self if userid is None)
			contents = self.generateListPage(doEdit=False, userid=userid, extraParams=pageParams)

		view.setHtml(contents)