scripts/export_kml.py
author Mario Ferraro <fadinlight@gmail.com>
Sun, 15 Nov 2009 22:12:20 +0100
changeset 3093 d1be59b6b627
parent 2967 676c0ca67e21
permissions -rwxr-xr-x
GMaps related JS changed to use new google namespace. Google is going to change permanently in the future the way to load its services, so better stay safe. Also this commit shows uses of the new melange.js module. Fixes Issue 634.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2967
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
     2
#
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
     4
#
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
     8
#
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    10
#
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    16
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    17
"""The script which generates KML file for Google Summer of Code 2009 program.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    18
"""
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    19
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    20
__authors__ = [
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    21
  '"Daniel Hans" <daniel.m.hans@gmail.com>',
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    22
]
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    23
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    24
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    25
import sys
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    26
import codecs
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    27
import interactive
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    28
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    29
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    30
from xml.dom.minidom import Document
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    31
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    32
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    33
def _getMentoredProjects(mentor):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    34
  """Returns a list of projects which are mentored by a given mentor.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    35
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    36
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    37
  from soc.logic.models.student_project import logic as project_logic
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    38
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    39
  filter = {
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    40
      'mentor': mentor
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    41
      }
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    42
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    43
  return project_logic.getForFields(filter=filter)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    44
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    45
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    46
def _getAcceptedOrgs():
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    47
  """Returns a list of organizations which got accepted.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    48
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    49
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    50
  from soc.logic.models.organization import logic as org_logic
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    51
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    52
  filter = {
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    53
      'status': 'active'
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    54
      }
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    55
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    56
  entities = org_logic.getForFields(filter=filter)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    57
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    58
  filter = {
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    59
      'status': 'new'
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    60
      }
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    61
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    62
  entities += org_logic.getForFields(filter=filter)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    63
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    64
  return entities
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    65
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    66
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    67
def _getStudentProject(entity):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    68
  """Returns a project for a given student.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    69
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    70
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    71
  from soc.logic.models.student_project import logic as project_logic
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    72
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    73
  filter = {
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    74
      'student': entity,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    75
      'status': 'accepted',
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    76
      }
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    77
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    78
  return project_logic.getForFields(filter=filter, unique=True)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    79
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    80
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    81
def _getAllUsers():
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    82
  """Returns a list of all valid users.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    83
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    84
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    85
  from soc.models.user import User
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    86
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    87
  gen = lambda: User.all().filter('status =', 'valid')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    88
  return interactive.deepFetch(gen)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    89
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    90
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    91
def _getAllOrgAdmins():
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    92
  """Returns a generator of all active mentors.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    93
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    94
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    95
  from soc.models.org_admin import OrgAdmin
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    96
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    97
  gen = lambda: OrgAdmin.all().filter('status = ', 'active')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    98
  return interactive.deepFetch(gen)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
    99
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   100
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   101
def _getAllMentors():
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   102
  """Returns a generator of all active mentors.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   103
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   104
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   105
  from soc.models.mentor import Mentor
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   106
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   107
  gen = lambda: Mentor.all().filter('status = ', 'active')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   108
  return interactive.deepFetch(gen)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   109
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   110
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   111
def _getAllStudents():
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   112
  """Returns a generator of all active students.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   113
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   114
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   115
  from soc.models.student import Student
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   116
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   117
  gen = lambda: Student.all().filter('status = ', 'active')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   118
  return interactive.deepFetch(gen)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   119
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   120
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   121
def _getPersonStyle(doc, type):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   122
  """Returns <Style> element for a particular person.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   123
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   124
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   125
  if type == 'org_admin':
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   126
    x_text, y_text = '0', '0'
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   127
  elif type == 'mentor':
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   128
    x_text, y_text = '128', '96'
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   129
  elif type == 'student':
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   130
    x_text, y_text = '64', '160'
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   131
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   132
  style = doc.createElement('Style')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   133
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   134
  icon_style = doc.createElement('IconStyle')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   135
  style.appendChild(icon_style)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   136
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   137
  icon = doc.createElement('Icon')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   138
  icon_style.appendChild(icon)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   139
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   140
  href = doc.createElement('href')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   141
  icon.appendChild(href)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   142
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   143
  text = doc.createTextNode('root://icons/palette-5.png')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   144
  href.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   145
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   146
  x = doc.createElement('x')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   147
  icon.appendChild(x)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   148
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   149
  text = doc.createTextNode(x_text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   150
  x.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   151
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   152
  y = doc.createElement('y')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   153
  icon.appendChild(y)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   154
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   155
  text = doc.createTextNode(y_text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   156
  y.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   157
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   158
  w = doc.createElement('w')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   159
  icon.appendChild(w)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   160
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   161
  text = doc.createTextNode('32')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   162
  w.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   163
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   164
  h = doc.createElement('h')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   165
  icon.appendChild(h)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   166
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   167
  text = doc.createTextNode('32')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   168
  h.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   169
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   170
  return style
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   171
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   172
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   173
def _getLineStringStyle(doc):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   174
   """Returns <Style> element for a line string placemark.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   175
   """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   176
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   177
   style = doc.createElement('Style')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   178
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   179
   line_style = doc.createElement('LineStyle')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   180
   style.appendChild(line_style)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   181
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   182
   color = doc.createElement('color')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   183
   line_style.appendChild(color)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   184
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   185
   text = doc.createTextNode('ff00ff00')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   186
   color.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   187
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   188
   width = doc.createElement('width')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   189
   line_style.appendChild(width)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   190
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   191
   text = doc.createTextNode('1')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   192
   width.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   193
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   194
   return style
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   195
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   196
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   197
def _getDescriptionForStudent(doc, student, project):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   198
  """Returns <description> element for a given student.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   199
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   200
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   201
  description = doc.createElement('description')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   202
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   203
  text = doc.createTextNode('Working on...')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   204
  description.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   205
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   206
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   207
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   208
  i = doc.createElement('i')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   209
  description.appendChild(i)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   210
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   211
  title = doc.createTextNode(project.title)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   212
  i.appendChild(title)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   213
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   214
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   215
  mentor = doc.createTextNode(
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   216
      'mentored by ' + _getName(project.mentor))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   217
  description.appendChild(mentor)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   218
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   219
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   220
  org = doc.createTextNode(project.scope.name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   221
  description.appendChild(org)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   222
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   223
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   224
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   225
  description = _appendHomePageAndBlogContent(doc, description, student)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   226
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   227
  description = _appendStateAndCountryContnent(doc, description, student)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   228
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   229
  return description
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   230
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   231
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   232
def _appendStateAndCountryContnent(doc, description, state, country):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   233
  """Appends state and country info to the description of a placemark.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   234
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   235
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   236
  if state:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   237
    description.appendChild(doc.createTextNode(state + ', '))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   238
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   239
  description.appendChild(doc.createTextNode(country))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   240
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   241
  return description
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   242
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   243
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   244
def _appendHomePageAndBlogContent(doc, description, home_pages, blogs):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   245
  """Appends home page and blog info to the description of a placemark.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   246
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   247
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   248
  if home_pages:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   249
    text = doc.createTextNode('Home page:')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   250
    description.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   251
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   252
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   253
  for home_page in home_pages:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   254
    description.appendChild(doc.createTextNode(home_page))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   255
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   256
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   257
  if home_pages:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   258
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   259
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   260
  if blogs:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   261
    text = doc.createTextNode('Blog:')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   262
    description.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   263
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   264
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   265
  for blog in blogs:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   266
    description.appendChild(doc.createTextNode(blog))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   267
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   268
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   269
  if blogs:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   270
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   271
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   272
  return description
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   273
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   274
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   275
def _getName(entity):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   276
  """For a given entity returns a name to be displayed.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   277
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   278
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   279
  return entity.name()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   280
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   281
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   282
def _getMentorDescription(doc, content):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   283
  """Returns <description> element for a mentor / org admin based on content.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   284
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   285
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   286
  description = doc.createElement('description')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   287
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   288
  admin = content['admin']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   289
  if admin:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   290
    text = doc.createTextNode('Organization admin for ' + admin)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   291
    description.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   292
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   293
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   294
  projects = content['projects']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   295
  if projects:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   296
    text = doc.createTextNode('Mentoring...')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   297
    description.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   298
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   299
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   300
  for project in projects:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   301
    i = doc.createElement('i')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   302
    description.appendChild(i)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   303
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   304
    title = doc.createTextNode(project['title'])
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   305
    i.appendChild(title)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   306
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   307
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   308
    student = doc.createTextNode('by ' + project['student'])
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   309
    description.appendChild(student)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   310
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   311
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   312
    organization = doc.createTextNode(project['org'])
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   313
    description.appendChild(organization)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   314
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   315
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   316
  consults = content['consults']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   317
  for consult in consults:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   318
    text = doc.createTextNode(consult)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   319
    description.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   320
    description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   321
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   322
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   323
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   324
  home_pages = content['home_pages']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   325
  blogs = content['blogs']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   326
  description = _appendHomePageAndBlogContent(doc, description,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   327
      home_pages, blogs)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   328
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   329
  state = content['state']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   330
  country = content['country']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   331
  description = _appendStateAndCountryContnent(doc, description, state,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   332
      country)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   333
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   334
  return description
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   335
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   336
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   337
def _getStudentDescription(doc, content):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   338
  """Returns <description> element for a student based on content.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   339
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   340
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   341
  description = doc.createElement('description')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   342
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   343
  text = doc.createTextNode('Working on...')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   344
  description.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   345
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   346
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   347
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   348
  project = content['project']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   349
  i = doc.createElement('i')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   350
  description.appendChild(i)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   351
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   352
  title = doc.createTextNode(project.title)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   353
  i.appendChild(title)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   354
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   355
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   356
  mentor = doc.createTextNode('mentored by ' + project.mentor.name())
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   357
  description.appendChild(mentor)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   358
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   359
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   360
  org = doc.createTextNode(project.scope.name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   361
  description.appendChild(org)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   362
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   363
  description.appendChild(doc.createElement('br'))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   364
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   365
  home_pages = content['home_pages']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   366
  blogs = content['blogs']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   367
  description = _appendHomePageAndBlogContent(doc, description,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   368
      home_pages, blogs)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   369
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   370
  state = content['state']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   371
  country = content['country']
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   372
  description = _appendStateAndCountryContnent(doc, description, state,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   373
      country)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   374
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   375
  return description
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   376
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   377
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   378
def _createFolderForMentorsAndOrgAdmins(doc):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   379
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   380
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   381
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   382
  folder = doc.createElement("Folder")
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   383
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   384
  name = doc.createElement("name")
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   385
  folder.appendChild(name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   386
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   387
  nametext = doc.createTextNode("Mentors")
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   388
  name.appendChild(nametext)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   389
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   390
  return folder
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   391
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   392
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   393
def _createLineString(doc, student, mentor):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   394
  """Generates line string between a given student and mentor.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   395
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   396
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   397
  line_string = doc.createElement('LineString')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   398
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   399
  coordinates = doc.createElement('coordinates')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   400
  line_string.appendChild(coordinates)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   401
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   402
  text = doc.createTextNode(str(student[0]) + ',' + str(student[1]) + ' ' +
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   403
      str(mentor[0]) + ',' + str(mentor[1]))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   404
  coordinates.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   405
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   406
  altitude_mode = doc.createElement('altitudeMode')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   407
  line_string.appendChild(altitude_mode)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   408
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   409
  text = doc.createTextNode('clampToGround')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   410
  altitude_mode.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   411
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   412
  extrude = doc.createElement('extrude')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   413
  line_string.appendChild(extrude)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   414
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   415
  text = doc.createTextNode('1')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   416
  extrude.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   417
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   418
  tessellate = doc.createElement('tessellate')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   419
  line_string.appendChild(tessellate)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   420
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   421
  text = doc.createTextNode('1')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   422
  tessellate.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   423
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   424
  return line_string
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   425
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   426
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   427
def _createPoint(doc, longitude, latitude):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   428
  """Generates <Point> subtree with coordinates for a given entity.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   429
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   430
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   431
  point = doc.createElement('Point')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   432
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   433
  coordinates = doc.createElement('coordinates')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   434
  point.appendChild(coordinates)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   435
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   436
  text = doc.createTextNode(str(longitude) + ',' + str(latitude))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   437
  coordinates.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   438
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   439
  return point
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   440
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   441
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   442
def _createStudentPlacemark(doc, coordinates, content):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   443
  """Creates <Placemark> element for a student based on a given content.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   444
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   445
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   446
  placemark = doc.createElement('Placemark')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   447
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   448
  style = _getPersonStyle(doc, 'student')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   449
  placemark.appendChild(style)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   450
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   451
  name = doc.createElement('name')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   452
  placemark.appendChild(name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   453
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   454
  text = doc.createTextNode(content['name'])
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   455
  name.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   456
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   457
  description = _getStudentDescription(doc, content)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   458
  placemark.appendChild(description)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   459
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   460
  point = _createPoint(doc, coordinates[0], coordinates[1])
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   461
  placemark.appendChild(point)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   462
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   463
  return placemark
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   464
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   465
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   466
def _createMentorPlacemark(doc, coordinates, content):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   467
  """Creates <Placemark> element for a mentor based on a given content.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   468
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   469
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   470
  placemark = doc.createElement('Placemark')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   471
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   472
  type = 'org_admin' if content['admin'] is not None else 'mentor'
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   473
  style = _getPersonStyle(doc, type)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   474
  placemark.appendChild(style)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   475
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   476
  name = doc.createElement('name')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   477
  placemark.appendChild(name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   478
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   479
  text = doc.createTextNode(content['name'])
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   480
  name.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   481
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   482
  description = _getMentorDescription(doc, content)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   483
  placemark.appendChild(description)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   484
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   485
  point = _createPoint(doc, coordinates[0], coordinates[1])
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   486
  placemark.appendChild(point)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   487
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   488
  return placemark
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   489
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   490
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   491
def _createLineStringPlacemark(doc, student_coordinates, mentor_coordinates):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   492
  """Creates <Placemark> element for a line string between given student
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   493
     coordinates and mentor coordinates.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   494
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   495
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   496
  placemark = doc.createElement('Placemark')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   497
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   498
  line_string = _createLineString(doc, student_coordinates, mentor_coordinates)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   499
  placemark.appendChild(line_string)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   500
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   501
  style = _getLineStringStyle(doc)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   502
  placemark.appendChild(style)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   503
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   504
  return placemark
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   505
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   506
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   507
def _processMentor(doc, org_admin, mentors, folder):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   508
  """Processes a student and adds information to a folder.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   509
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   510
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   511
  projects = []
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   512
  placemarks = {}
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   513
  longitude = None
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   514
  latitude = None
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   515
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   516
  for entity in mentors:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   517
    if not entity.publish_location:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   518
      continue
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   519
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   520
    longitude, latitude = (entity.longitude, entity.latitude)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   521
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   522
    if not placemarks.get((longitude, latitude)):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   523
      placemarks[(longitude, latitude)] = {
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   524
          'admin': None,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   525
          'projects': [],
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   526
          'consults': [],
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   527
          'name': entity.name(),
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   528
          'country': entity.res_country,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   529
          'state': entity.res_state,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   530
          'home_pages': set(),
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   531
          'blogs': set()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   532
          }
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   533
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   534
    projects = _getMentoredProjects(entity)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   535
    if not projects:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   536
      placemarks[(longitude, latitude)]['consults'].append(
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   537
          'Mentor for ' + entity.scope.name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   538
    else:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   539
      for project in projects:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   540
        placemarks[(longitude, latitude)]['projects'].append({
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   541
            'title': project.title,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   542
            'org': project.scope.name,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   543
            'student': project.student.name()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   544
            })
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   545
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   546
    if entity.home_page:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   547
      placemarks[(longitude, latitude)]['home_pages'].add(entity.home_page)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   548
    if entity.blog:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   549
      placemarks[(longitude, latitude)]['blogs'].add(entity.blog)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   550
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   551
  if org_admin and org_admin.publish_location:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   552
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   553
    if not (longitude, latitude):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   554
      longitude, latitude = (org_admin.longitude, org_admin.latitude)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   555
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   556
    if not placemarks.get((longitude, latitude)):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   557
      placemarks[(longitude, latitude)] = {
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   558
          'admin': None,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   559
          'projects': [],
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   560
          'consults': [],
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   561
          'name': org_admin.name(),
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   562
          'country': org_admin.res_country,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   563
          'state': org_admin.res_state,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   564
          'home_pages': set(),
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   565
          'blogs': set()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   566
          }
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   567
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   568
    placemarks[(longitude, latitude)]['admin'] = org_admin.scope.name
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   569
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   570
    if org_admin.home_page:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   571
      placemarks[(longitude, latitude)]['home_pages'].add(org_admin.home_page)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   572
    if org_admin.blog:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   573
      placemarks[(longitude, latitude)]['blogs'].add(org_admin.blog)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   574
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   575
  for coordinates, content in placemarks.iteritems():
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   576
    placemark = _createMentorPlacemark(doc, coordinates, content)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   577
    folder.appendChild(placemark)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   578
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   579
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   580
def _processStudent(doc, student, orgs_folder):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   581
  """Processes a student and adds information to a folder.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   582
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   583
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   584
  if not student.publish_location:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   585
    return
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   586
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   587
  project = _getStudentProject(student)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   588
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   589
  if not project:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   590
    return
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   591
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   592
  folder = doc.createElement('Folder')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   593
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   594
  name = doc.createElement('name')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   595
  folder.appendChild(name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   596
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   597
  name.appendChild(doc.createTextNode(student.name()))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   598
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   599
  content = {
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   600
      'name': student.name(),
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   601
      'project': project,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   602
      'country': student.res_country,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   603
      'state': student.res_state,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   604
      'home_pages': [student.home_page] if student.home_page else [],
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   605
      'blogs': [student.blog] if student.blog else []
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   606
      }
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   607
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   608
  coordinates = student.longitude, student.latitude
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   609
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   610
  placemark = _createStudentPlacemark(doc, coordinates, content)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   611
  folder.appendChild(placemark)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   612
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   613
  mentor = project.mentor
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   614
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   615
  if mentor.publish_location:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   616
    mentor_coordinates = mentor.longitude, mentor.latitude
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   617
    line_string = _createLineStringPlacemark(doc, coordinates,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   618
        mentor_coordinates)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   619
    folder.appendChild(line_string)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   620
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   621
  org = project.scope
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   622
  org_folder = orgs_folder[org.name]
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   623
  org_folder.appendChild(folder)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   624
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   625
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   626
def _processAllUsers(doc, mentors_folder, orgs_folder):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   627
  """Processes all users and fills folders with information based on roles.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   628
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   629
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   630
  from soc.logic.models.mentor import logic as mentor_logic
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   631
  from soc.logic.models.org_admin import logic as org_admin_logic
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   632
  from soc.logic.models.student import logic as student_logic
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   633
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   634
  it = _getAllOrgAdmins()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   635
  org_admins = dict()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   636
  for org_admin in it:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   637
    org_admins[org_admin.link_id] = org_admin
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   638
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   639
  it = _getAllMentors()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   640
  mentors = dict()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   641
  for mentor in it:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   642
    link_id = mentor.link_id
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   643
    if link_id not in mentors:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   644
      mentors[link_id] = []
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   645
    mentors[link_id].append(mentor)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   646
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   647
  it = _getAllStudents()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   648
  students = dict()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   649
  for student in it:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   650
    students[student.link_id] = student
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   651
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   652
  link_ids = set(mentors.keys() + org_admins.keys())
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   653
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   654
  for link_id in link_ids:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   655
    entity = org_admins.get(link_id)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   656
    entities = mentors.get(link_id, [])
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   657
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   658
    if entity or entities:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   659
      _processMentor(doc, entity, entities, mentors_folder)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   660
      continue
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   661
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   662
  link_ids = students.keys()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   663
  for link_id in link_ids:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   664
    entity = students.get(link_id)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   665
    if entity:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   666
      _processStudent(doc, entity, orgs_folder)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   667
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   668
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   669
def _createFolderForStudentsAndOrgs(doc):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   670
  """Creates <Folder> elements for all students and for all accepted
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   671
     organizations.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   672
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   673
  Returns:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   674
    A tuple whose first element is a folder for students and the second
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   675
    one is a dictionary mapping organization names with their folders.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   676
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   677
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   678
  folder = doc.createElement('Folder')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   679
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   680
  name = doc.createElement('name')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   681
  folder.appendChild(name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   682
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   683
  text = doc.createTextNode('Students')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   684
  name.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   685
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   686
  orgs = _getAcceptedOrgs()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   687
  org_folders = {}
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   688
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   689
  for org in orgs:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   690
    org_folder = doc.createElement('Folder')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   691
    folder.appendChild(org_folder)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   692
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   693
    name = doc.createElement('name')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   694
    org_folder.appendChild(name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   695
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   696
    text = doc.createTextNode(org.name)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   697
    name.appendChild(text)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   698
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   699
    org_folders[org.name] = org_folder
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   700
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   701
  return folder, org_folders
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   702
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   703
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   704
def generateCompleteKML():
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   705
  """Generates complete KML file for Google Summer of Code 2009.
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   706
  """
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   707
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   708
  doc = Document()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   709
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   710
  kml = doc.createElement('kml')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   711
  doc.appendChild(kml)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   712
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   713
  document = doc.createElement('Document')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   714
  kml.appendChild(document)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   715
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   716
  mentor_folder = _createFolderForMentorsAndOrgAdmins(doc)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   717
  document.appendChild(mentor_folder)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   718
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   719
  student_folder, org_folders = _createFolderForStudentsAndOrgs(doc)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   720
  document.appendChild(student_folder)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   721
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   722
  _processAllUsers(doc, mentor_folder, org_folders)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   723
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   724
  out = codecs.open('soc_map2009.kml', 'w', 'utf-8')
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   725
  out.write(doc.toprettyxml(indent='  '))
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   726
  out.close()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   727
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   728
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   729
def main(args):
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   730
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   731
  context = {
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   732
      'export': generateCompleteKML,
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   733
      }
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   734
  interactive.setup()
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   735
  interactive.remote(args, context)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   736
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   737
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   738
if __name__ == '__main__':
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   739
  if len(sys.argv) < 2:
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   740
    print "Usage: %s app_id [host]" % (sys.argv[0],)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   741
    sys.exit(1)
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   742
676c0ca67e21 Add a script to generate a kml file with all active GSoC participants
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
diff changeset
   743
  main(sys.argv[1:])