~mhall119/onehundredscopes/loco-team-portal

« back to all changes in this revision

Viewing changes to ltp-lens

  • Committer: Michael Hall
  • Date: 2011-12-21 15:18:41 UTC
  • Revision ID: mhall119@ubuntu.com-20111221151841-933a0ch57ymy68bp
Attempt to find the user's launchpad username from their bazaar.conf, and if we find it try and display the loco teams they are a member of as the default, rather than all teams

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
        self._lens.export ()
75
75
 
76
76
        self._ltp = locodir.LocoDirectory()
 
77
        self.lpusername = None
 
78
        if os.path.exists(os.path.expanduser('~/.bazaar/bazaar.conf')):
 
79
            try:
 
80
                import configparser
 
81
            except ImportError:
 
82
                import ConfigParser as configparser
 
83
 
 
84
            bzrconf = configparser.ConfigParser()
 
85
            bzrconf.read(os.path.expanduser('~/.bazaar/bazaar.conf'))
 
86
            try:
 
87
                self.lpusername = bzrconf.get('DEFAULT', 'launchpad_username')
 
88
            except configparser.NoOptionError:
 
89
                pass
77
90
 
78
91
    def thaw(self, entry):
79
92
        entry.thaw_notify()
155
168
                                 tmeeting['name'], tmeeting['date_begin'], '')
156
169
 
157
170
        else:
 
171
 
 
172
            shownteams = False
 
173
            if self.lpusername:
 
174
                groups = self._ltp.getGroups(user__username=self.lpusername)
 
175
                
 
176
                for group in groups.values():
 
177
                    teams = self._ltp.getTeams(lp_name=group['name'])
 
178
                    if len(teams) == 1:
 
179
                        team = teams.values()[0]
 
180
                        shownteams = True
 
181
                        model.append('http://loco.ubuntu.com/teams/%s/' % team['lp_name'],
 
182
                                     team['mugshot_url'],
 
183
                                     LTP_TEAMS,
 
184
                                     "text/html",
 
185
                                     team['name'], team['lp_name'], '')
 
186
 
 
187
                        # To avoid long waits, don't search for a team's events and meetings until we have only a handful of teams
 
188
                        if len(teams) <= 5:
 
189
                            # Events by team
 
190
                            for tevent in self._ltp.getTeamEvents(teams=team['id'], date_end__gte=datetime.datetime.utcnow()).values():
 
191
                                model.append('http://loco.ubuntu.com/events/%s/%s/detail/' % (team['lp_name'], tevent['id']),
 
192
                                             team['mugshot_url'],
 
193
                                             LTP_EVENTS,
 
194
                                             "text/html",
 
195
                                             tevent['name'], '%s\n%s' % (tevent['date_begin'], tevent['description']), '')
 
196
 
 
197
                            # Meetings by team
 
198
                            for tmeeting in self._ltp.getTeamMeetings(teams=team['id'], date_end__gte=datetime.datetime.utcnow()).values():
 
199
                                model.append('http://loco.ubuntu.com/meetings/%s/%s/detail/' % (team['lp_name'], tmeeting['id']),
 
200
                                             team['mugshot_url'],
 
201
                                             LTP_MEETINGS,
 
202
                                             "text/html",
 
203
                                             tmeeting['name'], tmeeting['date_begin'], '')
 
204
                
158
205
            # Display all teams
159
 
            for team in self._ltp.getTeams().values():
160
 
                model.append('http://loco.ubuntu.com/teams/%s/' % team['lp_name'],
161
 
                             team['mugshot_url'],
162
 
                             LTP_TEAMS,
163
 
                             "text/html",
164
 
                             team['name'], team['lp_name'], '')
 
206
            if not shownteams:
 
207
                for team in self._ltp.getTeams().values():
 
208
                    model.append('http://loco.ubuntu.com/teams/%s/' % team['lp_name'],
 
209
                                 team['mugshot_url'],
 
210
                                 LTP_TEAMS,
 
211
                                 "text/html",
 
212
                                 team['name'], team['lp_name'], '')
165
213
 
166
214
if __name__ == "__main__":
167
215
    session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)