Пример #1
0
    def post(self):
        if not userIsLoggedIn(self):
            return
        
        user = users.get_current_user()
        lang = getLanguage(self, user)
        
        groupName = self.request.get('name').strip()
        escapedGroupName = escape(groupName)

        # Verificar que el nombre no sea vacio
        if groupName == "": 
            error = _('You must enter a group name.', lang)
            alertMessage(self,error)
            return
        
        group = self.createGroupAndInsertMember(groupName)

        # Si el usuario es miembro de un grupo con alias igual al nombre 
        # del grupo que quiere crear, no dejarlo
        if group is None: 
            error = _('You already belong to a group with the name %s.', lang) % escapedGroupName
            error += '\\n';
            error += _('Please select another name.', lang)
            alertMessage(self,error)
            return

        location = '/group?group=%s&msg=%s' % (group.key(), _('Group successfully created', lang))
        redirectPage(self,location)
Пример #2
0
    def post(self):
        if not userIsLoggedIn(self):
            return
        
        user = users.get_current_user()
        lang = getLanguage(self, user)
        
        groupKey = self.request.get('group').strip()
        
        if groupKey == "":
            error = _('Group is required', lang)
            alertMessage(self,error)
            return
        
        group = Group.get(groupKey)
        memberships = Membership.gql("WHERE group = :1 AND user = :2", group, user)

        if memberships.count() <> 1:
            error = _('You don\'t belong to this group.', lang)
            alertMessage(self,error)
            return
        
        membership = memberships.get()
        if not abs(membership.balance) <= 1e-07:
            error = _('You cannot leave this group, your balance must be zero.', lang)
            alertMessage(self,error)
            return
        
        membership.delete()
        if Membership.gql("WHERE group = :1", group).count() == 0:
            group.delete()
        
        msg = _('You have been succesfully unsubscribed from the group %s!', lang) % escape(group.name)
        location = '/?msg=' + msg
        redirectPage(self,location)
Пример #3
0
	def post(self):
		if not userIsLoggedIn(self):
			return
			
		rejectPath = UrlBuilder(self.request).buildUrl('/reject')
		
		user = users.get_current_user()
		lang = getLanguage(self, user)
		group = Group.get(self.request.get("group"))
		
		creatorMember = Membership.gql("WHERE group = :1 AND user = :2", group, user)[0]
		if not creatorMember:
			return
		
		command = self.request.get("cow")
		members = group.memberships
		
		parser = CowParser()
		parser.lang = lang
		transaction = parser.parse(members, command)
		
		if transaction.error:
			alertMessage(self, transaction.error)
			return
		
		result = transaction.getResult()
		
		# Update balance and send mails
		for member, balance in result.balanceChange.iteritems():
			balanceBefore = member.balance
			balanceNow = member.balance + balance
			
			# Balance
			member.balance += balance
			member.put()
			
			# Send mail, but not to the creator of this mail
			if member.user != creatorMember.user:
				message = createCowMail(creatorMember, transaction, result, member, balanceBefore, balanceNow, lang)
				sendEmail(message)
			
		# Create transactions
		for debt in result.debts:
			for singleDebt in debt.singleDebts:
				tr = Transaction(
					group = group,
					creatorMember = creatorMember, 
					fromMember = debt.fromMember,
					toMember = singleDebt.toMember,
					type = 'debt',
					amount = singleDebt.money, 
					reason = transaction.reason,
					isRejected = False
				)
				tr.put()
				
		location = '/group?group=%s&msg=%s' % (group.key(), _('Debts saved!', lang))
		redirectPage(self,location)
Пример #4
0
 def get(self):
     user = users.get_current_user()
     lang = ensureLanguage(self.request.get('lang'))
     
     # Set cookie
     self.response.headers['Set-Cookie'] = str('lang=%s; path=/;' % lang)
     
     # Set memcache if possible
     if user:
         key = '%s language' % user
         memcache.set(key, lang)
     
     redirectPage(self, '/')
Пример #5
0
    def post(self):
		if not userIsLoggedIn(self):
			return
            
		user = users.get_current_user()
		lang = getLanguage(self, user)
		userMembership = Membership.get(self.request.get('userMembership'))
        
		# Verificar que la membership que se paso sea efectivamente del usuario
		if not self.isMember(userMembership):
		    return
		
		newGroupNick = self.request.get('groupNick').strip()
		newUserNick = self.request.get('userNick').strip()
		
		# Verificar que el nombre de grupo no sea vacio
		if newGroupNick == "":
		    error = _('The name by which you want to see this group is required.', lang)
		    alertMessage(self,error)
		    return
		
		# Verificar que no exista un alias del usuario con el mismo nombre
		if self.isGroupNickTaken(newGroupNick, userMembership.group):
		    error = _('You already have a Group with the selected name, please select another name.', lang)
		    alertMessage(self,error)
		    return
		
		# Verificar que el nickname no sea vacio
		if newUserNick == "":
		    error = _('The name by which you want others to see you in this group is required.', lang)
		    alertMessage(self,error)
		    return
		
		# Verificar que el nickname no este tomado
		for other in Membership.gql("WHERE group = :1 AND user != :2", userMembership.group, userMembership.user):
		    if other.userNick == newUserNick:
		        error = _('The name by which you want others to see you in this group is already used by another member.', lang)
		        alertMessage(self,error)
		        return
		
		userMembership.alias = newGroupNick
		userMembership.nickname = newUserNick
		userMembership.put()
		
		location = '/group?group=%s&msg=%s' % (userMembership.group.key(), _('Properties changed!', lang))
		redirectPage(self,location)
Пример #6
0
 def post(self):
     if not userIsLoggedIn(self):
         return
     
     user = users.get_current_user()
     lang = getLanguage(self, user)
     groupKey = self.request.get('group')
     group = Group.get(groupKey)
     invitationText = self.request.get('invitationText')
     emails = self.request.get('emails')
     emails = emails.split(',')
     urlBuilder = UrlBuilder(self.request)
     
     # Check that all emails are valid
     for email in emails:
     	if not mail.is_email_valid(email.strip()):
     		alertMessage(self, _('%s is not a valid email address', lang) % email)
     		return
     
     for email in emails:
         self.sendInvitation(user, email.strip(), group, invitationText, urlBuilder, lang)
         
     redirectPage(self, "/group?group=%s&msg=%s" % (groupKey, escape(_('Your invite has been sent!', lang))))
Пример #7
0
	def post(self):
		if not userIsLoggedIn(self):
			return
			
		rejectPath = UrlBuilder(self.request).buildUrl('/reject')
		
		user = users.get_current_user()
		lang = getLanguage(self, user)
		group = Group.get(self.request.get("group"))
		
		creatorMember = Membership.gql("WHERE group = :1 AND user = :2", group, user)[0]
		if not creatorMember:
			return
		
		command = self.request.get("command")
		members = group.memberships
		
		parser = OrderParser()
		parser.lang = lang
		transaction = parser.parse(members, command)
		
		if transaction.error:
			alertMessage(self, transaction.error)
			return
			
		payersBalanceBefore = transaction.payer.balance
		
		for debt in transaction.debts:
		    debtor = debt.member
		    payer = transaction.payer
		    debtorLang = getLanguage(self, debtor.user)
			
		    if debtor.user.email().lower() == payer.user.email().lower():
		        continue
			
		    debtorsBalanceBefore = debtor.balance
		    
		    # Adjust balance
		    debtor.balance -= debt.money
		    debtor.put()
		    
		    payer.balance += debt.money
		    
		    debtorsBalanceNow = debtor.balance
		    
		    # Create transaction
		    tr = Transaction(
		        group = group,
		        creatorMember = creatorMember, 
		        fromMember = debtor,
		        toMember = payer,
		        type = 'debt',
		        amount = debt.money, 
		        reason = debt.reason,
		        isRejected = False
		        )
		    tr.put()
			
		    # If the one that created this transaction is the one that owes,
		    # don't sent a mail to him/her
		    if creatorMember.user == debtor.user:
		    	continue
		    
		    # Build the reject url
		    rejectUrl = UrlBuilder(self.request).buildUrl('/reject')
		    rejectUrl += "?key=%s&h=%s" % (str(tr.key()), tr.hash)
		    
		    # Try send email to the debtor
		    if creatorMember.user == transaction.payer.user:
		    	message = createActionMail(payer, debtor, debt.money, debt.reason, debtorsBalanceBefore, debtorsBalanceNow, rejectUrl, youOwedSomeone(debtorLang), debtorLang) 
		    else:
		    	message = createThirdPartyActionMail(creatorMember, payer, debtor, debt.money, debt.reason, debtorsBalanceBefore, debtorsBalanceNow, rejectUrl, creatorSaysYouOwedSomeone(debtorLang), debtorLang)
		    
		    sendEmail(message)
				
		transaction.payer.put()
		
		payersBalanceNow = transaction.payer.balance
		
		# Now try send email to the payer with a summary
		if not creatorMember.user == transaction.payer.user:
			payerLang = getLanguage(self, transaction.payer.user)
			message = createBulkMail(transaction, creatorMember, payersBalanceBefore, payersBalanceNow, payerLang)
			sendEmail(message)
				
		location = '/group?group=%s&msg=%s' % (group.key(), _('Debts saved!', lang))
		redirectPage(self,location)
Пример #8
0
    def post(self):
        if not userIsLoggedIn(self):
            return
        
        key = self.request.get('key')
        hash = self.request.get('h')
        reason = self.request.get('reason').strip()
        user = users.get_current_user()
        lang = getLanguage(self, user)
        
        # Check that all is ok
        tr = isValidTransaction(key, hash, user)
        if not tr:
            self.redirect('/')
            return
        
        # Check that the transaction is not rejected
        if tr.isRejected:
            self.redirect('/')
            return
        
        # Reject it and everything else...
        tr.isRejected = True
        
        compensateTr = tr.getCompensateFor(user)
        
        # See who is me, and who is someone
        if compensateTr.creatorMember == compensateTr.fromMember:
            me = compensateTr.fromMember
            someone = compensateTr.toMember
        else:
            me = compensateTr.toMember
            someone = compensateTr.fromMember
            
        someoneLang = getLanguage(self, someone.user)
            
        balanceBefore = someone.balance

        # ========================================================= #
        # See what's the type of the transaction and adjust balance
        # ========================================================= #
        
        if tr.type == 'debt':
            # If it's a debt, fromMember always wins
            tr.fromMember.balance += tr.amount
            tr.toMember.balance -= tr.amount
            
            if compensateTr.creatorMember.user == tr.fromMember.user:
                # I owe someone
                mailBody = someoneOwedYou(someoneLang, reject = True)
            else:
                # Someone owes me
                mailBody = youOwedSomeone(someoneLang, reject = True)
        elif tr.type == 'payment':
            # If it's a payment, fromMember always looses
            tr.fromMember.balance -= tr.amount
            tr.toMember.balance += tr.amount
            
            if compensateTr.creatorMember.user == tr.fromMember.user:
                # I paid someone
                mailBody = someonePayedYou(someoneLang, reject = True)
            else:
                # Someone paid me
                mailBody = youPayedSomeone(someoneLang, reject = True)
        else:
            # Can't happen, only with hackery
            return
        
        tr.fromMember.put()
        tr.toMember.put()
        tr.put()
        compensateTr.put()
        
        balanceNow = someone.balance

        # ========================== #
        # Try send notification mail #
        # ========================== #        
        
        # Try send mail
        message = createRejectionMail(me, someone, tr, reason, balanceBefore, balanceNow, mailBody, someoneLang)
        sendEmail(message)
        
        location = '/group?group=%s&msg=%s' % (tr.group.key(), _('You rejected the transaction', lang))
        redirectPage(self,location)