예제 #1
0
파일: views.py 프로젝트: durm/titan
def save(request, num=None):
    if request.method == 'GET':
        c = {"unit": Unit.objects.get(id=int(num)) if num is not None else None}
        c.update(csrf(request))
        return render_to_response("save.html", c, context_instance=RequestContext(request))
    elif request.method == 'POST':
        if "unit_id" in request.POST:
            unit = Unit.objects.get(id=int(request.POST["unit_id"]))
            unit.name = request.POST["name"]
            unit.desc = request.POST["desc"]
            unit.updated_by = request.user
        else:
            unit = Unit(name=request.POST.get("name"), desc=request.POST.get("desc"), created_by=request.user, updated_by=request.user)
        unit.save()
        return redirect(reverse(page, kwargs={"num": int(unit.id)}))
예제 #2
0
def get_current_unit(request, unit_blank=True, allow_all_units=False):
    """Return the current unit"""

    from units.models import Unit

    current_unit_pk = request.session.get('current_unit_pk', 1)

    try:
        if int(current_unit_pk) == -1 and unit_blank:
            return None
    except:
        pass

    try:
        if int(current_unit_pk) == -2 and allow_all_units:
            return Unit(name=_(u'Toutes les unités'), pk=-2)
    except:
        pass

    try:
        current_unit = Unit.objects.get(pk=current_unit_pk)
    except Unit.DoesNotExist:
        try:
            current_unit = Unit.objects.get(pk=settings.ROOT_UNIT_PK)
        except:
            current_unit = None

    return current_unit
예제 #3
0
 def test_sync_rlc(self):
     from units.models import Unit, Role
     Unit(pk=settings.AUTO_RLC_UNIT_PK, name='RLC',
          description='RLC').save()
     Role(pk=settings.AUTO_RLC_GIVEN_ROLE,
          name="RLC",
          order=1,
          need_validation=False).save()
     self.call_command()
예제 #4
0
 def test_unit_delete(self):
     from units.models import Unit
     Unit(id=3,
          name='other unit',
          description='bad unit',
          is_commission=True,
          is_equipe=True).save()
     self.call_check_html('/units/unit/3/delete')
     self.call_check_redirect('/units/unit/3/delete',
                              method='post',
                              data={'do': 'it'},
                              redirect_url='/units/unit/')
예제 #5
0
def setup_testing_users_units():
    from units.models import Unit, Role, Accreditation
    now = timezone.now()
    admin_user = TruffeUser.objects.create_superuser(username='******',
                                                     password='******',
                                                     first_name='admin',
                                                     last_name='admin')
    admin_user.mobile = "0123456789"
    admin_user.adresse = "rue machin"
    admin_user.nom_banque = "Postfinance"
    admin_user.iban_ou_ccp = "0009876543210"
    admin_user.save()
    Unit(id=2,
         name='My unit',
         description='unit very nice',
         is_commission=True,
         is_equipe=True).save()
    user1 = TruffeUser.objects.create_user(username='******',
                                           password='******',
                                           first_name='user1',
                                           last_name='user1')
    user1.mobile = "0123456789"
    user1.adresse = "rue machin"
    user1.nom_banque = "Postfinance"
    user1.iban_ou_ccp = "0009876543210"
    user1.save()
    user2 = TruffeUser.objects.create_user(username='******',
                                           password='******',
                                           first_name='user2',
                                           last_name='user2')
    user2.mobile = "0123456789"
    user2.adresse = "rue machin"
    user2.nom_banque = "Postfinance"
    user2.iban_ou_ccp = "0009876543210"
    user2.save()
    user3 = TruffeUser.objects.create_user(username='******',
                                           password='******',
                                           first_name='user3',
                                           last_name='user3')
    user3.mobile = "0123456789"
    user3.adresse = "rue machin"
    user3.nom_banque = "Postfinance"
    user3.iban_ou_ccp = "0009876543210"
    user3.save()
    user4 = TruffeUser.objects.create_user(username='******',
                                           password='******',
                                           first_name='user4',
                                           last_name='user4')
    user4.mobile = "0123456789"
    user4.adresse = "rue machin"
    user4.nom_banque = "Postfinance"
    user4.iban_ou_ccp = "0009876543210"
    user4.save()

    Role(id=1, name="role0", order=1, need_validation=False).save()
    Role(id=2,
         name="role1",
         order=2,
         need_validation=False,
         access='PRESIDENCE').save()
    Role(id=3,
         name="role2",
         order=3,
         need_validation=False,
         access='TRESORERIE').save()
    Role(id=4,
         name="role3",
         order=4,
         need_validation=False,
         access='SECRETARIAT').save()
    Role(id=5,
         name="role4",
         order=5,
         need_validation=False,
         access='INFORMATIQUE').save()
    Accreditation(unit_id=settings.ROOT_UNIT_PK,
                  user=admin_user,
                  role_id=1,
                  need_validation=True).save()
    Accreditation(unit_id=2, user=user1, role_id=2,
                  need_validation=False).save()
    Accreditation(unit_id=2, user=user2, role_id=3,
                  need_validation=False).save()
    Accreditation(unit_id=2, user=user3, role_id=4,
                  need_validation=False).save()
    Accreditation(unit_id=2, user=user4, role_id=5,
                  need_validation=False).save()
    system_user = TruffeUser(pk=settings.SYSTEM_USER_PK,
                             username='******',
                             first_name='system',
                             last_name='system',
                             is_active=True,
                             is_superuser=True,
                             last_login=now,
                             date_joined=now)
    system_user.set_password('system')
    system_user.save()
    return admin_user