示例#1
0
  def setUp(self):
    """Set up required for sample feed item test. 
    
    Creates sender, receiver, and user entities required for news_feed
    test. 
    """

    # ensure that current user is created
    properties = {
        'account': users.get_current_user(),
        'link_id': 'current_user',
        'name': 'Current User',
        }

    key_name = user_logic.getKeyNameFromFields(properties)
    self.user = user_logic.updateOrCreateFromKeyName(properties, key_name)

    site_properties = {
      'key_name': 'site',
      'link_id': 'site',
      }

    key_name = site_logic.getKeyNameFromFields(site_properties)
    self.site = site_logic.updateOrCreateFromKeyName(
    site_properties, key_name)
        
    document_properties = {
      'key_name': 'site/site/home',
      'link_id': 'home',
      'scope_path': 'site',
      'scope': self.site,
      'prefix': 'site',
      'author': self.user,
      'title': 'Home Page',
      'short_name': 'Home',
      'content': 'This is the Home Page',
      'modified_by': self.user,
      }

    key_name = document_logic.getKeyNameFromFields(document_properties)
    self.document = document_logic.updateOrCreateFromKeyName(
    document_properties, key_name)
示例#2
0
def runDocumentUpdate(request, entities, context, *args, **kwargs):
  """AppEngine Task that updates Document entities.

  Args:
    request: Django Request object
    entities: list of Document entities to update
    context: the context of this task
  """

  from soc.modules.gsoc.logic.models.organization import logic as org_logic
  from soc.modules.gsoc.logic.models.program import logic as program_logic

  # get all the properties that are part of each Document
  document_model = document_logic.getModel()
  document_properties = document_model.properties().keys()

  # use this to store all the new Documents and Presences
  documents = []
  presences = []

  for entity in entities:

    if entity.prefix not in ['org', 'program']:
      # we do not want to convert this Document
      continue

    new_document_properties = {}

    for document_property in document_properties:
      # copy over all the information from the Document entity
      new_document_properties[document_property] = getattr(entity,
                                                           document_property)

    if entity.prefix == 'org':
      new_document_prefix = 'gsoc_org'
      presence_entity = org_logic.getFromKeyName(entity.scope_path)
    elif entity.prefix == 'program':
      new_document_prefix = 'gsoc_program'
      presence_entity = program_logic.getFromKeyName(entity.scope_path)

    new_document_properties['prefix'] = new_document_prefix
    new_document_properties['scope'] = presence_entity
    new_document_properties['home_for'] = presence_entity if entity.home_for else None

    # create the new Document entity and prepare it to be stored
    new_document_entity = document_model(
        key_name=document_logic.getKeyNameFromFields(new_document_properties),
        **new_document_properties)
    documents.append(new_document_entity)

    if entity.home_for:
      # update the presence for which this document was the home page
      presence_entity.home = new_document_entity
      presences.append(presence_entity)

  # store all the new Documents and updated Presences
  db.put(documents)
  db.put(presences)

  # task completed, return
  return
示例#3
0
def runDocumentUpdate(request, entities, context, *args, **kwargs):
  """AppEngine Task that updates Document entities.

  Args:
    request: Django Request object
    entities: list of Document entities to update
    context: the context of this task
  """

  from soc.modules.gsoc.logic.models.organization import logic as org_logic
  from soc.modules.gsoc.logic.models.program import logic as program_logic

  # get all the properties that are part of each Document
  document_model = document_logic.getModel()
  document_properties = document_model.properties().keys()

  # use this to store all the new Documents and Presences
  documents = []
  presences = []

  for entity in entities:

    if entity.prefix not in ['org', 'program']:
      # we do not want to convert this Document
      continue

    new_document_properties = {}

    for document_property in document_properties:
      # copy over all the information from the Document entity
      new_document_properties[document_property] = getattr(entity,
                                                           document_property)

    if entity.prefix == 'org':
      new_document_prefix = 'gsoc_org'
      presence_entity = org_logic.getFromKeyName(entity.scope_path)
    elif entity.prefix == 'program':
      new_document_prefix = 'gsoc_program'
      presence_entity = program_logic.getFromKeyName(entity.scope_path)

    new_document_properties['prefix'] = new_document_prefix
    new_document_properties['scope'] = presence_entity
    new_document_properties['home_for'] = presence_entity if entity.home_for else None

    # create the new Document entity and prepare it to be stored
    new_document_entity = document_model(
        key_name=document_logic.getKeyNameFromFields(new_document_properties),
        **new_document_properties)
    documents.append(new_document_entity)

    if entity.home_for:
      # update the presence for which this document was the home page
      presence_entity.home = new_document_entity
      presences.append(presence_entity)

  # store all the new Documents and updated Presences
  db.put(documents)
  db.put(presences)

  # task completed, return
  return