Daniel Holbach has proposed merging lp:~dholbach/loco-directory/656270 into 
lp:loco-directory.

Requested reviews:
  loco-directory-dev (loco-directory-dev)
Related bugs:
  #656270 Better teams merge
  https://bugs.launchpad.net/bugs/656270

-- 
https://code.launchpad.net/~dholbach/loco-directory/656270/+merge/37939
Your team loco-directory-dev is requested to review the proposed merge of 
lp:~dholbach/loco-directory/656270 into lp:loco-directory.
=== added file 'loco_directory/teams/utils.py'
--- loco_directory/teams/utils.py	1970-01-01 00:00:00 +0000
+++ loco_directory/teams/utils.py	2010-10-08 09:11:00 +0000
@@ -0,0 +1,63 @@
+from django.utils.translation import ugettext
+
+from events.models import TeamEvent
+
+def merge_teams(old_team, new_team):
+    msgs = []
+    related_events = TeamEvent.objects.filter(teams__id=old_team.id)
+    for event in related_events:
+        for team in event.teams.filter(id=old_team.id):
+            msgs += [ugettext('New owner of event "%s" is team "%s".' % (event.name, new_team.name))]
+            event.teams.remove(team)
+            event.teams.add(new_team)
+        event.save()
+    if old_team.contact_profiles.count() and not new_team.contact_profiles.count():
+        for contact_profile in old_team.contact_profiles.all():
+            new_team.contact_profiles.add(contact_profile)
+            msgs += [ugettext('Adding contact "%s" to team "%s".' % (contact_profile.realname, new_team.name))]
+    if old_team.countries.count() and not new_team.countries.count():
+        for country in old_team.countries.all():
+            new_team.countries.add(country)
+            msgs += [ugettext('Adding country "%s" to team "%s".' % (country.name, new_team.name))]
+    if old_team.languages.count() and not new_team.languages.count():
+        for language in old_team.languages.all():
+            new_team.languages.add(language)
+            msgs += [ugettext('Adding language "%s" to team "%s".' % (language.name, new_team.name))]
+    if old_team.spr and not new_team.spr:
+        new_team.spr = old_team.spr
+        msgs += [ugettext('Setting State/Province/Region of "%s" to "%s".' % (new_team.name, old_team.spr))]
+    if old_team.city and not new_team.city:
+        new_team.city = old_team.city
+        msgs += [ugettext('Setting city of "%s" to "%s".' % (new_team.name, old_team.city))]
+    if old_team.wiki_url and not new_team.wiki_url:
+        new_team.wiki_url = old_team.wiki_url
+        msgs += [ugettext('Setting Wiki URL of "%s" to "%s".' % (new_team.name, old_team.wiki_url))]
+    if old_team.web_url and not new_team.web_url:
+        new_team.web_url = old_team.web_url
+        msgs += [ugettext('Setting Web URL of "%s" to "%s".' % (new_team.name, old_team.web_url))]
+    if old_team.ml_url and not new_team.ml_url:
+        new_team.ml_url = old_team.ml_url
+        msgs += [ugettext('Setting Mailing list URL of "%s" to "%s".' % (new_team.name, old_team.ml_url))]
+    if old_team.forum_url and not new_team.forum_url:
+        new_team.forum_url = old_team.forum_url
+        msgs += [ugettext('Setting Forum URL of "%s" to "%s".' % (new_team.name, old_team.forum_url))]
+    if old_team.email and not new_team.email:
+        new_team.email = old_team.email
+        msgs += [ugettext('Setting email address of "%s" to "%s".' % (new_team.name, old_team.email))]
+    if old_team.irc_chan and not new_team.irc_chan:
+        new_team.irc_chane = old_team.irc_chan
+        msgs += [ugettext('Setting IRC channel of "%s" to "%s".' % (new_team.name, old_team.irc_chan))]
+    if old_team.flickr_id and not new_team.flickr_id:
+        new_team.flickr_id = old_team.flickr_id
+        msgs += [ugettext('Setting Flickr ID of "%s" to "%s".' % (new_team.name, old_team.flickr_id))]
+    if old_team.picasa_id and not new_team.picasa_id:
+        new_team.picasa_id = old_team.picasa_id
+        msgs += [ugettext('Setting Picasa ID of "%s" to "%s".' % (new_team.name, old_team.picasa_id))]
+    if old_team.pixie_id and not new_team.pixie_id:
+        new_team.pixie_id = old_team.pixie_id
+        msgs += [ugettext('Setting Pix.ie ID of "%s" to "%s".' % (new_team.name, old_team.pixie_id))]
+    new_team.save()
+    old_team.delete()
+    msgs += [ugettext('Team "%s" merged with "%s".' % (old_team.name, new_team.name))]
+    return msgs
+

=== modified file 'loco_directory/teams/views.py'
--- loco_directory/teams/views.py	2010-09-30 16:14:48 +0000
+++ loco_directory/teams/views.py	2010-10-08 09:11:00 +0000
@@ -16,7 +16,7 @@
 from common import launchpad
 
 from teams.models import Continent, Team, countries_without_continent, countries_without_continent_have_teams, teams_without_country
-from events.models import TeamEvent
+from teams.utils import merge_teams
 
 import forms
 
@@ -123,31 +123,23 @@
 
 @login_required
 def team_merge(request, team_slug, other_team_slug):
-    team_object = get_object_or_404(Team, lp_name=team_slug)
-    other_team_object = get_object_or_404(Team, lp_name=other_team_slug)
+    old_team = get_object_or_404(Team, lp_name=team_slug)
+    new_team = get_object_or_404(Team, lp_name=other_team_slug)
     
     #check if user has needed rights
-    is_admin = launchpad.is_admin_or_owner(request.user.username, team_object) and \
-               launchpad.is_admin_or_owner(request.user.username, other_team_object)
+    is_admin = launchpad.is_admin_or_owner(request.user.username, old_team) and \
+               launchpad.is_admin_or_owner(request.user.username, new_team)
     if not is_admin:
         request.user.message_set.create(message=ugettext('You are not allowed to merge this team with another one.'))
-        return redirect(team_object)
+        return redirect(old_team)
     
-    related_events = TeamEvent.objects.filter(teams__id=team_object.id)
-    for event in related_events:
-        for team in event.teams.filter(id=team_object.id):
-            request.user.message_set.create(message=ugettext('New owner of event "%s" is team "%s".' % \
-                                                        (event.name, other_team_object.name)))
-            event.teams.remove(team)
-            event.teams.add(other_team_object)
-        event.save()
-    team_object.delete()
-    request.user.message_set.create(message=ugettext('Team "%s" merged with "%s".' % \
-                                                        (team_object.name, other_team_object.name)))
+    msgs = merge_teams(old_team, new_team)
+    for msg in msgs:
+        request.user.message_set.create(message=msg)
 
     return render_to_response('teams/merge_teams.html',
-                              {'team_object':team_object,
-                               'other_team_object':other_team_object,
+                              {'team_object':old_team,
+                               'other_team_object':new_team,
                                'user':request.user,
                               }, RequestContext(request))
 

_______________________________________________
Mailing list: https://launchpad.net/~loco-directory-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~loco-directory-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to