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

Requested reviews:
  loco-directory-dev (loco-directory-dev)
Related bugs:
  #582354 LD does not deal well with renamed teams
  https://bugs.launchpad.net/bugs/582354

-- 
https://code.launchpad.net/~dholbach/loco-directory/582354/+merge/37219
Your team loco-directory-dev is requested to review the proposed merge of 
lp:~dholbach/loco-directory/582354 into lp:loco-directory.
=== modified file 'loco_directory/teams/forms.py'
--- loco_directory/teams/forms.py	2010-01-05 20:56:19 +0000
+++ loco_directory/teams/forms.py	2010-10-01 05:31:44 +0000
@@ -8,12 +8,12 @@
 class UpdateTeamForm(forms.ModelForm):
     class Meta:
         model = Team
-        exclude = ('approved_date', 'approved', 'expires_date', 'name', 'lp_name', 'admins', 'owner')
+        exclude = ('approved_date', 'approved', 'expires_date', 'name', 'lp_name', 'admins', 'owner', 'active')
 
 class LoCoCouncilForm(forms.ModelForm):
     class Meta:
         model = Team
-        exclude = ('approved', 'expires_date', 'name', 'lp_name', 'admins', 'owner')
+        exclude = ('approved', 'expires_date', 'name', 'lp_name', 'admins', 'owner', 'active')
 
 class TeamSearchForm(forms.Form):
     """

=== modified file 'loco_directory/teams/management/commands/lpupdate.py'
--- loco_directory/teams/management/commands/lpupdate.py	2010-08-23 09:16:24 +0000
+++ loco_directory/teams/management/commands/lpupdate.py	2010-10-01 05:31:44 +0000
@@ -78,3 +78,12 @@
                 team.expires_date = None
             team.mugshot_url = launchpad.get_mugshot_url(lp, l.name)
             team.save()
+
+        lp_loco_names = set([a.name for a in locos])
+        ld_loco_names = set([a.lp_name for a in existing_locos])
+        for a in existing_locos:
+            if a.lp_name in ld_loco_names.difference(lp_loco_names):
+                a.active = False
+            else:
+                a.active = True
+            a.save()

=== modified file 'loco_directory/teams/migrations/0010_add_photos_feed_fields.py'
--- loco_directory/teams/migrations/0010_add_photos_feed_fields.py	2010-09-16 15:15:48 +0000
+++ loco_directory/teams/migrations/0010_add_photos_feed_fields.py	2010-10-01 05:31:44 +0000
@@ -6,7 +6,7 @@
 class Migration:
     
     def forwards(self, orm):
-        
+        db.current_orm.models['teams'] = db.current_orm.models['teams.team']
         # Adding field 'Team.picasa_id'
         db.add_column('teams', 'picasa_id', orm['teams.team:picasa_id'])
         
@@ -16,7 +16,7 @@
     
     
     def backwards(self, orm):
-        
+        db.current_orm.models['teams'] = db.current_orm.models['teams.team']
         # Deleting field 'Team.picasa_id'
         db.delete_column('teams', 'picasa_id')
         

=== added file 'loco_directory/teams/migrations/0011_add_team_active.py'
--- loco_directory/teams/migrations/0011_add_team_active.py	1970-01-01 00:00:00 +0000
+++ loco_directory/teams/migrations/0011_add_team_active.py	2010-10-01 05:31:44 +0000
@@ -0,0 +1,116 @@
+
+from south.db import db
+from django.db import models
+from teams.models import *
+
+class Migration:
+    
+    def forwards(self, orm):
+        db.current_orm.models['teams'] = db.current_orm.models['teams.team']        
+        # Adding field 'Team.active'
+        db.add_column('teams', 'active', orm['teams.team:active'])
+        
+    
+    
+    def backwards(self, orm):
+        db.current_orm.models['teams'] = db.current_orm.models['teams.team']
+        # Deleting field 'Team.active'
+        db.delete_column('teams', 'active')
+        
+    
+    
+    models = {
+        'auth.group': {
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'unique_together': "(('content_type', 'codename'),)"},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'unique_together': "(('app_label', 'model'),)", 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'teams.continent': {
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.TextField', [], {'max_length': '50'})
+        },
+        'teams.country': {
+            'continents': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['teams.Continent']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.TextField', [], {'max_length': '100'})
+        },
+        'teams.language': {
+            'code': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150', 'null': 'True'})
+        },
+        'teams.team': {
+            'Meta': {'db_table': "'teams'"},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
+            'admin_profiles': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['userprofiles.UserProfile']"}),
+            'approved': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'approved_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+            'city': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
+            'contact_profiles': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['userprofiles.UserProfile']"}),
+            'countries': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['teams.Country']"}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+            'expires_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+            'flickr_id': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            'forum_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'irc_chan': ('django.db.models.fields.CharField', [], {'max_length': '25', 'null': 'True', 'blank': 'True'}),
+            'languages': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['teams.Language']"}),
+            'lp_name': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True'}),
+            'ml_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'mugshot_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True'}),
+            'owner_profile': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'owner'", 'null': 'True', 'to': "orm['userprofiles.UserProfile']"}),
+            'picasa_id': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            'pixie_id': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            'provides_support': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
+            'spr': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
+            'web_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'wiki_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'})
+        },
+        'userprofiles.userprofile': {
+            'aim': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'blog': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'facebook': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'flickr': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'identica': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'irc': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'picasa': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'realname': ('django.db.models.fields.CharField', [], {'max_length': '150', 'blank': 'True'}),
+            'twitter': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'tz': ('django.db.models.fields.CharField', [], {'default': "'UTC'", 'max_length': '32'}),
+            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'}),
+            'xmpp': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'})
+        }
+    }
+    
+    complete_apps = ['teams']

=== modified file 'loco_directory/teams/models.py'
--- loco_directory/teams/models.py	2010-09-16 15:15:48 +0000
+++ loco_directory/teams/models.py	2010-10-01 05:31:44 +0000
@@ -91,6 +91,7 @@
                                 help_text=_("Ex. [email protected], so your Picasa id is : toto"))
     pixie_id = models.CharField(_("Pix.ie User ID"), max_length=20, null=True, blank=True,
                                 help_text=_("Your Pix.ie Username"))
+    active = models.BooleanField(_("Active Team"), default=True)
     
     objects = TeamManager()
     

=== modified file 'loco_directory/teams/urls.py'
--- loco_directory/teams/urls.py	2010-07-29 15:41:01 +0000
+++ loco_directory/teams/urls.py	2010-10-01 05:31:44 +0000
@@ -3,6 +3,8 @@
 urlpatterns = patterns('',
     url(r'^$', 'teams.views.team_list', name='team-list'),
     url(r'(?P<team_slug>[a-zA-Z0-9\-\.\+?]+)/edit$', 'teams.views.team_edit', name='team-edit'),
+    url(r'(?P<team_slug>[a-zA-Z0-9\-\.\+?]+)/merge$', 'teams.views.select_other_team', name='select-other-team'),
+    url(r'(?P<team_slug>[a-zA-Z0-9\-\.\+?]+)/merge/(?P<other_team_slug>[a-zA-Z0-9\-\.\+?]+)$', 'teams.views.team_merge', name='team-merge'),
     url(r'(?P<team_slug>[a-zA-Z0-9\-\.\+?]+)/events/history$', 'teams.views.team_event_history', name='team-event-history'),
     url(r'(?P<team_slug>[a-zA-Z0-9\-\.\+?]+)/events$', 'teams.views.team_event_list', name='team-event-list'),
     url(r'(?P<team_slug>[a-zA-Z0-9\-\.\+?]+)$', 'teams.views.team_detail', name='team-detail'),

=== modified file 'loco_directory/teams/views.py'
--- loco_directory/teams/views.py	2010-08-09 13:18:19 +0000
+++ loco_directory/teams/views.py	2010-10-01 05:31:44 +0000
@@ -16,6 +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
 
 import forms
 
@@ -103,6 +104,53 @@
     return render_to_response('teams/team_detail.html', 
                                          context, RequestContext(request))
 
+...@login_required
+def select_other_team(request, team_slug):
+    team_object = get_object_or_404(Team, lp_name=team_slug)
+    
+    #check if user has needed rights
+    is_admin = launchpad.is_admin_or_owner(request.user.username, team_object)
+    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)
+    team_list = Team.objects.all().order_by('name')
+    other_teams = team_list.exclude(id=team_object.id)
+    return render_to_response('teams/select_other_team.html',
+                              {'team_object':team_object,
+                               'other_teams':other_teams,
+                               'user':request.user,
+                              }, RequestContext(request))
+
+...@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)
+    
+    #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)
+    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)
+    
+    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)))
+
+    return render_to_response('teams/merge_teams.html',
+                              {'team_object':team_object,
+                               'other_team_object':other_team_object,
+                               'user':request.user,
+                              }, RequestContext(request))
+
 
 @login_required
 def team_edit(request, team_slug):

=== added file 'loco_directory/templates/teams/merge_teams.html'
--- loco_directory/templates/teams/merge_teams.html	1970-01-01 00:00:00 +0000
+++ loco_directory/templates/teams/merge_teams.html	2010-10-01 05:31:44 +0000
@@ -0,0 +1,24 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Merge Teams" %} | {% trans "Ubuntu LoCo Team Directory" %} {% endblock %}
+{% block extrahead %}{{ block.super }}
+<link rel="stylesheet" type="text/css" href="/media/css/newstyle.css" />
+{% endblock %}
+{% block sub_nav %}{% endblock %}
+
+{% block content %}
+
+<h1>{% trans "Merge Teams" %}</h1>
+
+<hr class="divide" />
+
+<article class="minor-content alone">
+    {% if not team_object or not other_team_object %}
+        <p>{% trans "You need two valid teams you want to merge with another." %}</p>
+    {% else %}
+        <p><a href="{% url team-detail other_team_object %}">{% blocktrans with other_team_object.name as teamname %}Go back to the main page of {{teamname}}.{% endblocktrans %}</a></p>
+    {% endif %}
+</article>
+
+{% endblock %}

=== added file 'loco_directory/templates/teams/select_other_team.html'
--- loco_directory/templates/teams/select_other_team.html	1970-01-01 00:00:00 +0000
+++ loco_directory/templates/teams/select_other_team.html	2010-10-01 05:31:44 +0000
@@ -0,0 +1,37 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Merge Teams" %} | {% trans "Ubuntu LoCo Team Directory" %} {% endblock %}
+{% block extrahead %}{{ block.super }}
+<link rel="stylesheet" type="text/css" href="/media/css/newstyle.css" />
+{% endblock %}
+{% block sub_nav %}{% endblock %}
+
+{% block content %}
+
+<h1>{% trans "Merge Teams" %}</h1>
+
+<hr class="divide" />
+
+<article class="minor-content alone">
+    {% if other_teams %}
+        <h2>{% blocktrans with team_object.lp_name as teamname %}Select the team you want to merge "{{teamname}}" with:{% endblocktrans %}</h2>
+        <table width="100%">
+            <tr>
+                <td width="100%" valign="top">
+                    <ul id="main-content">
+                        {% for team in other_teams %}
+                            <li><a href="{% url team-merge team_object.lp_name team.lp_name %}">{{ team.name }}</a></li>
+                        {% endfor %}
+                    </ul>
+                </td>
+            </tr>
+        </table>
+    {% endif %}
+
+    {% if not other_teams %}
+        <p>{% trans "There are currently no teams you could merge your team with." %}</p>
+    {% endif %}
+</article>
+
+{% endblock %}

=== modified file 'loco_directory/templates/teams/team_detail.html'
--- loco_directory/templates/teams/team_detail.html	2010-09-26 21:27:20 +0000
+++ loco_directory/templates/teams/team_detail.html	2010-10-01 05:31:44 +0000
@@ -7,6 +7,7 @@
 			<a class="sub-nav-item" href="{% url team-list %}" title="{% trans "Back to Teams List" %}">{% trans "Back to Teams List" %}</a>
 			{% if is_member %}{% else %} <a class="sub-nav-item" href="https://launchpad.net/~{{ team.lp_name }}/+join">{% trans "Join This Team!" %}</a>{% endif %}
         	{% if is_admin %}<a class="sub-nav-item" href="{% url team-edit team.lp_name %}" title="{% trans "Edit Details" %}">{% trans "Edit Details" %}</a>{% endif %}
+        	{% if is_admin and not team.active %}<a class="sub-nav-item" href="{% url select-other-team team.lp_name %}" title="{% trans "Merge with another team" %}">{% trans "Merge team" %}</a>{% endif %}
             {% if is_member %}<a class="sub-nav-item" href="{% url team-event-new team.lp_name %}" title="{% trans "Add New Event" %}">{% trans "Add New Event" %}</a>{% endif %}
 {% endblock %}
 

_______________________________________________
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