Guest User

invite.py

a guest
Jun 11th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1.   def _createFromForm(self):
  2.     """Creates a new connection based on the data inserted in the form.
  3.  
  4.    Returns:
  5.      a newly created Connection entity or None
  6.    """
  7.     assert isSet(self.data.organization)
  8.    
  9.     connection_form = ConnectionForm(self.data, self.data.POST)
  10.    
  11.     if not connection_form.is_valid():
  12.       return None
  13.  
  14.     assert isSet(self.data.connected_user)
  15.     assert self.data.connected_user
  16.  
  17.     # create a new connection entity
  18.     connection_form.cleaned_data['organization'] = self.data.organization
  19.     connection_form.cleaned_data['user_action'] = 'pending'
  20.     connection_form.cleaned_data['org_action'] = 'accepted'
  21.  
  22.     def create_invite_txn(user):
  23.       connection = connection_form.create(commit=True, parent=user)
  24.       # TODO(dcrodman): Make this work for connections
  25.       #context = notifications.inviteContext(self.data, connection)
  26.       #sub_txn = mailer.getSpawnMailTaskTxn(context, parent=connection)
  27.       #sub_txn()
  28.       return connection
  29.  
  30.     for user in self.data.connected_user:
  31.       connection_form.instance = None
  32.       connection_form.cleaned_data['user'] = user
  33.       db.run_in_transaction(create_invite_txn, user)
  34.  
  35.     return True
Advertisement
Add Comment
Please, Sign In to add comment