Changeset 440 in main


Ignore:
Timestamp:
11/02/11 16:32:06 (8 years ago)
Author:
pcosquer
Message:

groups and users: fix a bug (group's owner changed when a new user is sponsored)

Location:
trunk/openPLM/plmapp
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/controllers/group.py

    r402 r440  
    189189        user = invitation.guest 
    190190        user.groups.add(self.object) 
    191         user.groupinfo_set.add(self.object) 
    192191        invitation.save() 
    193192        user.save() 
  • trunk/openPLM/plmapp/controllers/user.py

    r402 r440  
    239239        password = generate_password() 
    240240        new_user.set_password(password) 
    241         new_user.groupinfo_set.add(*[g.groupinfo for g in new_user.groups.all()]) 
    242241        new_user.save() 
    243242        new_user.get_profile().is_contributor = is_contributor 
  • trunk/openPLM/plmapp/forms.py

    r435 r440  
    9393    form = Form(data=data, empty_permitted=empty_allowed) if data else Form() 
    9494    if issubclass(cls, m.PLMObject): 
    95         form.fields["group"].queryset = user.groupinfo_set.all() 
     95        groups = user.groups.all().values_list("id", flat=True) 
     96        form.fields["group"].queryset = m.GroupInfo.objects.filter(id__in=groups) 
    9697    return form 
    9798get_creation_form.cache = {} 
  • trunk/openPLM/plmapp/models.py

    r425 r440  
    167167 
    168168    description = models.TextField(blank=True) 
    169     creator = models.ForeignKey(User) 
     169    creator = models.ForeignKey(User, related_name="%(class)s_creator") 
    170170     
    171171    owner = models.ForeignKey(User, verbose_name=_("owner"),  
  • trunk/openPLM/plmapp/tests/controllers/group.py

    r376 r440  
    2727""" 
    2828 
    29 import os 
    30 import datetime 
    31 from django.conf import settings 
    3229from django.db import IntegrityError 
    3330from django.contrib.auth.models import User 
    34 from django.core.files.base import ContentFile 
    35 from django.core.files import File 
    3631 
    3732from openPLM.plmapp.utils import * 
     
    3934from openPLM.plmapp.models import * 
    4035from openPLM.plmapp.controllers import * 
    41 from openPLM.plmapp.lifecycle import * 
    42 from openPLM.computer.models import * 
    43 from openPLM.office.models import * 
    44 from openPLM.cad.models import * 
     36from openPLM.plmapp.forms import get_creation_form, get_user_formset 
    4537 
    4638from openPLM.plmapp.tests.base import BaseTestCase 
     
    5951        self.assertEqual(obj.owner, self.user) 
    6052        self.assertEqual(obj.creator, self.user) 
    61         self.assertTrue(obj in self.user.groupinfo_set.all()) 
     53        self.assertTrue(self.user.groups.filter(id=obj.id)) 
    6254 
    6355    def test_create_error1(self): 
     
    10294        c2 = GroupController(controller.object, user) 
    10395        c2.accept_invitation(inv) 
    104         self.failUnless(c2.object in user.groupinfo_set.all()) 
     96        self.failUnless(user.groups.filter(id=controller.id)) 
    10597        self.assertEqual(inv.state, Invitation.ACCEPTED) 
    10698 
     
    115107        c2 = GroupController(controller.object, user) 
    116108        c2.refuse_invitation(inv) 
    117         self.failIf(c2.object in user.groupinfo_set.all()) 
     109        self.failIf(user.groups.filter(id=c2.id)) 
    118110        self.assertEqual(inv.state, Invitation.REFUSED) 
    119111 
     112    def test_create_from_form(self): 
     113        form = get_creation_form(self.user, GroupInfo, 
     114                {"name" : "grname", "description" :"desc" }) 
     115        gr = self.CONTROLLER.create_from_form(form, self.user) 
     116        self.assertEqual(self.user.username, gr.owner.username) 
     117        self.assertEqual("grname", gr.name) 
     118        self.assertTrue(self.user.groups.get(id=gr.id)) 
     119 
     120    def test_update_users(self): 
     121        controller = self.CONTROLLER.create("Grp1", "a", self.user, self.DATA) 
     122        user = User.objects.create(username="dede", email="dede@test") 
     123        user.groups.add(controller.object) 
     124        user2 = User.objects.create(username="dede2", email="dede2@test") 
     125        user2.groups.add(controller.object) 
     126        controller.save() 
     127        for u in (self.user, user, user2): 
     128            u.save() 
     129            self.assertTrue(u.groups.filter(id=controller.id)) 
     130        data = { 
     131                'form-0-group': controller.id, 
     132                'form-0-user': user.id, 
     133                'form-0-delete' : 'on', 
     134                'form-0-ORDER': '0', 
     135                'form-1-group': controller.id, 
     136                'form-1-user': user2.id, 
     137                'form-1-ORDER': '1', 
     138                'form-MAX_NUM_FORMS': '', 
     139                'form-TOTAL_FORMS': 2,  
     140                'form-INITIAL_FORMS': 2, 
     141                } 
     142        formset = get_user_formset(controller, data) 
     143        controller.update_users(formset) 
     144        self.assertFalse(user.groups.filter(id=controller.id)) 
     145        self.assertTrue(user2.groups.filter(id=controller.id)) 
     146        self.assertTrue(self.user.groups.filter(id=controller.id)) 
     147 
     148 
  • trunk/openPLM/plmapp/tests/views.py

    r410 r440  
    297297        self.assertTrue(user.get_profile().is_contributor) 
    298298        self.assertFalse(user.get_profile().is_administrator) 
    299         self.assertTrue(self.group in user.groupinfo_set.all()) 
     299        self.assertTrue(user.groups.filter(id=self.group.id)) 
    300300 
    301301 
Note: See TracChangeset for help on using the changeset viewer.