Пример #1
0
def add_user(req):
    user = req.user
    stub = user.username.split('@')[0]
    user.email = req.POST['email']
    user.first_name = req.POST['first_name']
    user.last_name = req.POST['last_name']
    user.save()
    org_group = OrgGroup(pk=req.POST['team'])
    office_location = OfficeLocation(pk=req.POST['office_location'])

    attributes = {
        'user': user,
        'stub': stub,
        'title': req.POST['title'],
        'office_location': office_location,
        'org_group': org_group,
        'office_phone': req.POST['office_phone'],
        'mobile_phone': req.POST['mobile_phone']
    }

    if req.FILES:
        attributes['photo_file'] = req.FILES['photo_file']

    person = Person(**attributes)
    person.save()
    return user
Пример #2
0
def create_superuser():
    user = get_user_model().objects.create_superuser('[email protected]', '[email protected]', '1')
    # If using collab, person objects needs to be created too
    if 'core' in settings.INSTALLED_APPS:
        from core.models import Person
        person = Person()
        person.user = user
        person.save()
Пример #3
0
    def test_generating_slug(self):
        person = Person(name='Charles Babbage')
        person.save()

        self.assertEqual(
            person.slug,
            'charles-babbage',
        )
Пример #4
0
 def get_user(self, user, name, profile_picture):
     person = None
     try:
         person = Person.objects.get(login=user)
     except Person.DoesNotExist:
         person = Person(login=user, name=name, profile_picture=profile_picture)
         person.save()
     return person
Пример #5
0
 def test_helper_no_profile(self):
     u = get_user_model()()
     u.first_name = "John"
     u.last_name = "Smith"
     u.save()
     self.assertEquals(False, helpers.user_has_profile(u))
     p = Person()
     p.user = u
     p.save()
     self.assertEquals(True, helpers.user_has_profile(u))
Пример #6
0
    def test_multiple_tags_multiple_users(self):
        user1 = UserF(username="[email protected]")
        person1 = Person(user=user1)
        person1.save()

        user2 = UserF(username="[email protected]")
        person2 = Person(user=user2)
        person2.save()

        user3 = UserF(username="[email protected]")
        person3 = Person(user=user3)
        person3.save()

        tag_category = TagCategory(name='Test Category',
                                   slug='staff-directory-test-category')
        tag_category.save()

        tags = []
        tagged_item = add_tags(person1, 'TagA',
                                'staff-directory-test-category', user1, 'person')
        tagged_item = add_tags(person2, 'TagA',
                                'staff-directory-test-category', user1, 'person')
        tags.append(tagged_item.tag.slug)

        tagged_item = add_tags(person2, 'TagB',
                                'staff-directory-test-category', user1, 'person')
        tagged_item = add_tags(person3, 'TagB',
                                'staff-directory-test-category', user2, 'person')
        tags.append(tagged_item.tag.slug)

        emails = _get_emails_for_tag(tags)
        self.assertTrue(len(emails) == 1)
        self.assertIn(user2.email, emails)
Пример #7
0
    def handle(self, *args, **options):
        last_names = [
            'Sherman', 'Maddox', 'Montgomery', 'Small', 'Larsen', 'Marsh', 'Gardner', 'White', 'Gill', 'Pennington', 'Stein', 'Kirby', 'Jennings', 'French', 'Glass', 'Velasquez', 'Doyle', 'York', 'Fisher', 'Strong', 'Henson', 'Harmon', 'Higgins', 'James', 'Hancock', 'Drake', 'Eaton', 'Gordon', 'Harrington', 'Blevins', 'Avila', 'Solis', 'Richmond', 'Stark', 'Haynes', 'Durham', 'Montoya', 'Barrett', 'Chase', 'Mckay', 'Little', 'Perry', 'Howard', 'Caldwell', 'West', 'Fox', 'Long', 'Wright', 'Foster', 'Sloan', 'Frazier', 'Lowe', 'Cabrera', 'Barron', 'Ayala', 'Frank', 'Hammond', 'Orr', 'Holloway', 'King', 'Rush', 'Wiley', 'Neal', 'Davis', 'Fulton', 'Webb', 'Sanchez', 'Strickland', 'Clark', 'Middleton', 'Moody', 'Owens', 'Graham', 'Cotton', 'Shaffer', 'Hawkins',
            'Cooper', 'Justice', 'Clarke', 'Mcconnell', 'Mccarthy', 'Macdonald', 'Castillo', 'Gilbert', 'Horton', 'Finley', 'Beard', 'Sanders', 'Levy', 'Richard', 'Bowen', 'Grant', 'Wilkins', 'Ramsey', 'Lynch', 'Koch', 'Mercado', 'Roach', 'Bond', 'Lane', 'Tanner', 'Byers', 'Humphrey', 'Austin', 'Carney', 'Golden', 'Pope', 'Kramer', 'Ellison', 'Jefferson', 'Duffy', 'Gross', 'Mcmahon', 'Hudson', 'Mckee', 'Atkinson', 'Bush', 'Thompson', 'Faulkner', 'Christian', 'Ingram', 'Cannon', 'Gay', 'Nieves', 'Hodges', 'Langley', 'Watson', 'Woods', 'Gallagher', 'Delacruz', 'Stafford', 'Knight', 'Kerr', 'Chapman', 'Roman', 'Christensen', 'Robles', 'Mathews', 'Waller', 'Buckley', 'Myers', 'Powers', 'Lindsay', 'Gates', 'Miller', 'Johns', 'Morin', 'Fleming', 'Bishop', 'Clements']
        first_names = [
            'Sarah', 'Ian', 'Upton', 'Uriah', 'Hayden', 'Zia', 'Lila', 'Benjamin', 'Addison', 'Vivian', 'Kirby', 'Oscar', 'Demetrius', 'Hashim', 'Michelle', 'Odessa', 'Phillip', 'Michael', 'Dante', 'Omar', 'Dominic', 'Wing', 'Joshua', 'Charlotte', 'Thomas', 'Aquila', 'Rana', 'Jolene', 'Felix', 'Cailin', 'Tatiana', 'Oprah', 'Belle', 'Sydnee', 'Kuame', 'Fleur', 'Matthew', 'Sylvia', 'Mary', 'Deborah', 'Ross', 'Hyacinth', 'Jacqueline', 'Jessica', 'Callie', 'Ariana', 'Leo', 'Desiree', 'Lunea', 'Chava', 'Jorden', 'Rudyard', 'Cally', 'Knox', 'Arthur', 'Dana', 'Rebekah', 'Yen', 'Hadassah', 'Duncan', 'Ginger', 'Valentine', 'Ivana', 'Iona', 'Jemima', 'Dorothy', 'Joan', 'Timothy', 'Amity', 'Uriel', 'Skyler', 'Phelan', 'Alma', 'Hadley',
            'Quemby', 'Sonya', 'Axel', 'Slade', 'Riley', 'Rajah', 'Giselle', 'Selma', 'Nadine', 'Pascale', 'Carol', 'Steel', 'Lane', 'Emi', 'Trevor', 'Wyatt', 'Claire', 'Harlan', 'Liberty', 'Alexandra', 'Avram', 'Barbara', 'Rashad', 'Holmes', 'Kenneth', 'Preston', 'Patience', 'Adele', 'Alfonso', 'Harrison', 'Julian', 'Jena', 'Peter', 'Kessie', 'Katell', 'Denton', 'Piper', 'Jerry', 'Teegan', 'Chandler', 'Walter', 'Cheryl', 'Desirae', 'Tasha', 'Hunter', 'Logan', 'Tatyana', 'Gail', 'Galvin', 'Dara', 'Athena', 'Kay', 'Dustin', 'Faith', 'Mariam', 'Leroy', 'Edan', 'Alexis', 'Nissim', 'Octavia', 'Kareem', 'Heidi', 'Aspen', 'Gregory', 'Garrison', 'Jolie', 'Gloria', 'Alec', 'Asher', 'Julie', 'Ayanna', 'Gavin', 'Germane', 'Bertha', 'Quinn', 'Tarik']

        office_location = OfficeLocation.objects.get(pk='DC123')

        for x in xrange(int(args[0])):
            while True:
                first_name = first_names[int(random.random() *
                                             len(first_names))]
                last_name = last_names[int(random.random() * len(last_names))]
                username = last_name + first_name[0]
                email = username + '@exmaple.com'
                if not get_user_model().objects.filter(username=email).exists():
                    break

            user_attr = {
                'first_name': first_name,
                'last_name': last_name,
                'is_active': True,
                'is_superuser': False,
                'date_joined': '2012-03-01T16:03:14Z',
                'password': 'pbkdf2_sha256$10000$ggAKkiHobFL8$xQzwPeHNX1vWr9uNmZ/gKbd17uLGZVM8QNcgmaIEAUs=',
                'is_staff': True,
                'email': email,
                'username': email
            }

            userModel = get_user_model()
            user = userModel(**user_attr)
            user.save()

            person_attr = {
                'office_location': office_location,
                'allow_tagging': True,
                'photo_file': 'avatars/default.jpg',
                'stub': username.replace('.', ''),
                'office_phone': '5555555555',
                'user': user,
                'email_notifications': False,
                'org_group': OrgGroup.objects.order_by('?')[0]
            }

            person = Person(**person_attr)
            person.save()

        self.stdout.write(
            'Successfully created %d users and persons' % int(args[0]))
Пример #8
0
    def test_create_tags_for_person(self):
        user = UserF(username="[email protected]")
        person = Person(user=user)
        person.save()

        tag_category = TagCategory(name='Test Category',
                                   slug='staff-directory-test-category')
        tag_category.save()

        tagged_item = add_tags(person, 'TagA',
                                'staff-directory-test-category', user, 'person')

        self.assertEqual(1, person.tags.count())
Пример #9
0
Файл: views.py Проект: yrik/42cc
def add_person(request):

    """
    >>> from django.test import Client
    >>> from django.core.urlresolver import reverse
    >>> client = Client()

    >>> response = client.get('add_person')
    >>> response.status_code
    200

    >>> client.post('/add_person/', {'name': 'fred')
    200
    """

    items = Person.objects.all()

    if request.method == 'POST':  # If the form has been submitted...
        form = PersonForm(request.POST)  # A  form bound to the POST data
        if form.is_valid():  # All validation rules pass
            newPerson = Person(
                        name=form.cleaned_data['name'],
                        bio=form.cleaned_data['bio'],
                        contacts=form.cleaned_data['contacts'],
                        surname=form.cleaned_data['surname'],
                        birth_date=form.cleaned_data['birth_date']
                        )
            newPerson.save()

        if request.is_ajax():
            rdict = {'bad': 'false'}
            if not form.is_valid():
                rdict.update({'bad': 'true'})
                d = {}
                for e in form.errors.iteritems():
                    d.update({e[0]: unicode(e[1])})
                rdict.update({'errs': d})
            json = simplejson.dumps(rdict, ensure_ascii=False)
            return HttpResponse(json, mimetype='application/javascript')
        else:
            return HttpResponseRedirect('/')  # Redirect after POST

    else:
        form = PersonForm()  # An unbound form

    return render_to_response('add_person.html', {
        'form': form,
        'items': items,
    },
     context_instance=RequestContext(request),
    )
Пример #10
0
    def setUp(self):
        self.meta, unused = BadgesEventMeta.get_or_create_dummy()
        LabourEventMeta.get_or_create_dummy()
        ProgrammeEventMeta.get_or_create_dummy()

        self.event = self.meta.event
        self.person, unused = Person.get_or_create_dummy()
Пример #11
0
    def test_single_tag_single_user(self):
        user = UserF(username="[email protected]")
        person = Person(user=user)
        person.save()

        tag_category = TagCategory(name='Test Category',
                                   slug='staff-directory-test-category')
        tag_category.save()

        tags = []
        tagged_item = add_tags(person, 'TagA',
                                'staff-directory-test-category', user, 'person')
        tags.append(tagged_item.tag.slug)

        emails = _get_emails_for_tag(tags)
        self.assertTrue(len(emails) == 1)
        self.assertIn(user.email, emails)
Пример #12
0
    def test_event_adminship(self):
        person, unused = Person.get_or_create_dummy(superuser=False)
        labour_event_meta, unused = LabourEventMeta.get_or_create_dummy()

        assert not labour_event_meta.is_user_admin(person.user)

        labour_event_meta.admin_group.user_set.add(person.user)

        assert labour_event_meta.is_user_admin(person.user)
Пример #13
0
    def test_single_tag_user_profile(self):
        user = UserF(username="[email protected]")
        user.set_password("x")
        user.save()
        person = Person(user=user)
        person.stub = "jack"
        person.save()
        resp1 = self.client.login(username="[email protected]", password="x")
        self.assertTrue(resp1)

        tag_category = TagCategory(name='Test Category',
                                   slug='staff-directory-test-category')
        tag_category.save()

        resp2 = self.client.post('/staff/add-person-to-tag/%s/hello!/' %
                                (person.stub), {'person_stub': person.stub,
                                                'tag_category': 'staff-directory-test-category'})

        self.assertContains(resp2, "redirect", status_code=200)
Пример #14
0
    def get_or_create_dummy(cls):
        from .email_alias_type import EmailAliasType
        from core.models import Person
        alias_type, unused = EmailAliasType.get_or_create_dummy()
        person, unused = Person.get_or_create_dummy()

        return cls.objects.get_or_create(
            type=alias_type,
            person=person,
        )
Пример #15
0
    def get_or_create_dummy(cls):
        from core.models import Person, Event

        person, unused = Person.get_or_create_dummy()
        event, unused = Event.get_or_create_dummy()

        signup, created = Signup.objects.get_or_create(person=person, event=event)
        extra = signup.signup_extra
        extra.save()

        return signup, created
Пример #16
0
    def get_or_create_dummy(cls):
        from core.models import Person
        from labour.models import PersonnelClass

        person, unused = Person.get_or_create_dummy()
        personnel_class, unused = PersonnelClass.get_or_create_dummy()

        return cls.objects.get_or_create(
            person=person,
            personnel_class=personnel_class,
        )
Пример #17
0
    def get_or_create_dummy(cls):
        from core.models import Person
        from .team import Team

        team, unused = Team.get_or_create_dummy()
        person, unused = Person.get_or_create_dummy()

        return cls.objects.get_or_create(
            team=team,
            person=person,
        )
Пример #18
0
    def get_or_create_dummy(cls):
        from core.models import Person

        person, unused = Person.get_or_create_dummy()
        role, unused = Role.get_or_create_dummy()
        programme, unused = Programme.get_or_create_dummy()

        ProgrammeRole.objects.get_or_create(
            person=person,
            programme=programme,
            role=role,
        )
Пример #19
0
    def get_facebook_user(cls, client, facebook_id):
        
        """
        method to retrieve facebook user, if it doesn't exist it'll be created

        """

        try:
            fbu = cls.objects.get(facebook_id__exact=facebook_id, deleted=False)
        except cls.DoesNotExist:
            try:
                user_data = client.obj_id(
                    facebook_id,
                    fields='id,name,first_name,middle_name,last_name,link,username,gender,locale,picture',
                    )
            except FacebookGenericError:
                user_data = client.obj_id(
                    facebook_id,
                    fields='id,name,link,picture',
                    )

                person = Person(
                    name=user_data[u'name'] if u'name' in user_data else None,
                    )
                person.save()

                fbu = cls(
                    person=person,
                    facebook_id=user_data[u'id'],
                    name=user_data[u'name'] if u'name' in user_data else None,
                    link=user_data[u'link'] if u'link' in user_data else None,
                    page=True,
                    )

                if u'picture' in user_data:
                    fbu.picture = user_data[u'picture'][u'data'][u'url']
            else:
                person = Person(
                    name=user_data[u'name'] if u'name' in user_data else None,
                    gender=user_data[u'gender'] if u'gender' in user_data else None,
                    )
                person.save()

                fbu = cls(
                    person=person,
                    facebook_id=user_data[u'id'],
                    name=user_data[u'name'] if u'name' in user_data else None,
                    first_name=user_data[u'first_name'] if u'first_name' in user_data else None,
                    middle_name=user_data[u'middle_name'] if u'middle_name' in user_data else None,
                    last_name=user_data[u'last_name'] if u'last_name' in user_data else None,
                    link=user_data[u'link'] if u'link' in user_data else None,
                    username=user_data[u'username'] if u'username' in user_data else None,
                    gender=user_data[u'gender'] if u'gender' in user_data else None,
                    locale=user_data[u'locale'] if u'locale' in user_data else None,
                    picture=user_data[u'picture'][u'data'][u'url'] if u'picture' in user_data else None,
                    page=False,
                    )

            fbu.save()
        return fbu
Пример #20
0
    def get_or_create_dummy(cls, programme=None):
        from core.models import Person
        from .role import Role

        person, unused = Person.get_or_create_dummy()
        role, unused = Role.get_or_create_dummy()

        if programme is None:
            programme, unused = Programme.get_or_create_dummy()

        ProgrammeRole.objects.get_or_create(
            person=person,
            programme=programme,
            role=role,
        )
Пример #21
0
    def get_or_create_dummy(cls, entry_type=None, **kwargs):
        from .entry_type_metadata import EntryTypeMetadata
        from core.models import Person

        if entry_type is None:
            entry_type, unused = EntryTypeMetadata.get_or_create_dummy()
            entry_type = entry_type.name

        person, unused = Person.get_or_create_dummy()

        attrs = dict(
            entry_type=entry_type,
            user=person.user,
        )

        attrs.update(kwargs)

        return cls.objects.get_or_create(**attrs)
Пример #22
0
    def test_qualifications(self):
        person, unused = Person.get_or_create_dummy()
        qualification1, qualification2 = Qualification.get_or_create_dummies()
        jc1, jc2 = JobCategory.get_or_create_dummies()

        jc1.required_qualifications.add(qualification1)

        assert not jc1.is_person_qualified(person)
        assert jc2.is_person_qualified(person)

        person.personqualification_set.create(qualification=qualification2)

        assert not jc1.is_person_qualified(person)
        assert jc2.is_person_qualified(person)

        person.personqualification_set.create(qualification=qualification1)

        assert jc1.is_person_qualified(person)
        assert jc2.is_person_qualified(person)
Пример #23
0
    def handle(*args, **options):
        if settings.DEBUG:
            person, unused = Person.get_or_create_dummy()

            Application.objects.get_or_create(
                client_id='kompassi_insecure_test_client_id',
                defaults=dict(
                    user=person.user,
                    redirect_uris='\n'.join([
                        'http://ssoexample.dev:8001/oauth2/callback',
                        'http://infokala.dev:8001/oauth2/callback',
                        'http://tracontent.dev:8001/oauth2/callback',
                    ]),
                    client_type='confidential', # hah
                    authorization_grant_type='authorization-code',
                    client_secret='kompassi_insecure_test_client_secret',
                    name='Insecure test application',
                )
            )
Пример #24
0
def membership_organization_box_context(request, organization):
    meta = organization.membership_organization_meta
    if not meta:
        return dict()

    if Person.is_user_person(request.user):
        membership = Membership.objects.filter(
            organization=organization,
            person=request.user.person,
        ).first()
        is_membership_admin = meta.is_user_admin(request.user)
    else:
        membership = None
        is_membership_admin = False

    return dict(
        can_apply=meta.receiving_applications and not membership,
        membership=membership,
        is_membership_admin=is_membership_admin,
    )
Пример #25
0
    def get_or_create_dummy(cls, accepted=False):
        from core.models import Person, Event
        from .job_category import JobCategory

        person, unused = Person.get_or_create_dummy()
        event, unused = Event.get_or_create_dummy()
        job_category, unused = JobCategory.get_or_create_dummy()

        signup, created = Signup.objects.get_or_create(person=person, event=event)
        if created:
            signup.job_categories.set([job_category])

        if accepted:
            signup.job_categories_accepted.set(signup.job_categories.all())
            signup.personnel_classes.add(signup.job_categories.first().personnel_classes.first())
            signup.state = 'accepted'
            signup.save()
            signup.apply_state()

        return signup, created
Пример #26
0
    def test_card_number(self):
        """
        Tests that only well-formed JV card numbers are accepted.
        """

        person, unused = Person.get_or_create_dummy()
        qualification = Qualification.create_dummy()
        personqualification = PersonQualification.objects.create(
            person=person,
            qualification=qualification,
        )

        today = date.today()

        valid_examples = [
            '8330/J1234/09',
            '8520/J0000/13',
        ]

        for valid_example in valid_examples:
            JVKortti(
                personqualification=personqualification,
                card_number=valid_example,
                expiration_date=today
            ).full_clean()

        invalid_examples = [
            'lol',
            # '8330/J1234/0', # need more lax validation due to new cards having a new format
            None,
            ''
        ]

        for invalid_example in invalid_examples:
            invalid = JVKortti(
                personqualification=personqualification,
                card_number=invalid_example,
                expiration_date=today
            )

            self.assertRaises(ValidationError, lambda: invalid.full_clean())
Пример #27
0
    def get_or_create_dummy(cls, programme=None, role=None):
        from core.models import Person
        from .role import Role
        from .programme import Programme

        person, unused = Person.get_or_create_dummy()

        if role is None:
            role, unused = Role.get_or_create_dummy()

        if programme is None:
            programme, unused = Programme.get_or_create_dummy()

        programme_role, created = ProgrammeRole.objects.get_or_create(
            person=person,
            programme=programme,
            defaults=dict(
                role=role,
            )
        )

        programme.apply_state()

        return programme_role, created
Пример #28
0
    def test_no_emails(self):
        user1 = UserF(username="[email protected]")
        person1 = Person(user=user1)
        person1.save()

        user2 = UserF(username="[email protected]")
        person2 = Person(user=user2)
        person2.save()

        tag_category = TagCategory(name='Test Category',
                                   slug='staff-directory-test-category')
        tag_category.save()

        tags = []
        tagged_item = add_tags(person1, 'TagA',
                                'staff-directory-test-category', user1, 'person')
        tags.append(tagged_item.tag.slug)

        tagged_item = add_tags(person2, 'TagB',
                                'staff-directory-test-category', user1, 'person')
        tags.append(tagged_item.tag.slug)

        emails = _get_emails_for_tag(tags)
        self.assertEqual(len(emails), 0)
Пример #29
0
    def setup_labour(self):
        from core.models import Person
        from labour.models import (
            AlternativeSignupForm,
            InfoLink,
            Job,
            JobCategory,
            LabourEventMeta,
            Perk,
            PersonnelClass,
            Qualification,
            WorkPeriod,
        )
        from ...models import SignupExtra, SpecialDiet, Night
        from django.contrib.contenttypes.models import ContentType

        labour_admin_group, = LabourEventMeta.get_or_create_groups(self.event, ['admins'])

        if self.test:
            from core.models import Person
            person, unused = Person.get_or_create_dummy()
            labour_admin_group.user_set.add(person.user)

        content_type = ContentType.objects.get_for_model(SignupExtra)

        labour_event_meta_defaults = dict(
            signup_extra_content_type=content_type,
            work_begins=datetime(2015, 7, 10, 12, 0, tzinfo=self.tz),
            work_ends=datetime(2015, 7, 12, 22, 0, tzinfo=self.tz),
            admin_group=labour_admin_group,
            contact_email='Animeconin työvoimatiimi <[email protected]>',
        )

        if self.test:
            t = now()
            labour_event_meta_defaults.update(
                registration_opens=t - timedelta(days=60),
                registration_closes=t + timedelta(days=60),
            )
        else:
            # TODO once we know when the registration opens
            # labour_event_meta_defaults.update(
            #     registration_opens=datetime(2014, 3, 1, 0, 0, tzinfo=self.tz),
            #     registration_closes=datetime(2014, 8, 1, 0, 0, tzinfo=self.tz),
            # )
            pass

        labour_event_meta, unused = LabourEventMeta.objects.get_or_create(
            event=self.event,
            defaults=labour_event_meta_defaults,
        )

        for pc_name, pc_slug, pc_app_label in [
            (u'Conitea', 'conitea', 'labour'),
            (u'Työvoima', 'tyovoima', 'labour'),
            (u'Järjestyksenvalvoja', 'jv', 'labour'),
            (u'Ohjelmanjärjestäjä', 'ohjelma', 'programme'),
            (u'Kunniavieras', 'goh', 'programme'), # tervetullut muttei kutsuta automaattiviestillä
            (u'Tulkki', 'tulkki', 'labour'),
            (u'Media', 'media', 'badges'),
            (u'Myyjä', 'myyja', 'badges'),
        ]:
            personnel_class, created = PersonnelClass.objects.get_or_create(
                event=self.event,
                slug=pc_slug,
                defaults=dict(
                    name=pc_name,
                    app_label=pc_app_label,
                    priority=self.get_ordering_number(),
                ),
            )

        tyovoima = PersonnelClass.objects.get(event=self.event, slug='tyovoima')
        jv = PersonnelClass.objects.get(event=self.event, slug='jv')
        conitea = PersonnelClass.objects.get(event=self.event, slug='conitea')
        ohjelma = PersonnelClass.objects.get(event=self.event, slug='ohjelma')

        for name, description, pcs in [
            (u'Conitea', u'Tapahtuman järjestelytoimikunnan eli conitean jäsen', [conitea]),

            (u'Narikka', u'Narikassa ja isotavara- eli asenarikassa säilytetään tapahtuman aikana kävijöiden omaisuutta. Tehtävä ei vaadi erikoisosaamista.', [tyovoima]),
            (u'Info', u'Infopisteen henkilökunta vastaa kävijöiden kysymyksiin ja ratkaisee heidän ongelmiaan tapahtuman paikana. Tehtävä edellyttää asiakaspalveluasennetta, tervettä järkeä ja ongelmanratkaisukykyä.', [tyovoima]),
            (u'Siivous', u'Tapahtumapaikan siistinä pitäminen tapahtuman aikana.', [tyovoima]),
            (u'Yleisvänkäri', u'Sekalaisia tehtäviä laidasta laitaan, jotka eivät vaadi erikoisosaamista. Voit halutessasi kirjata lisätietoihin, mitä osaat ja haluaisit tehdä.', [tyovoima]),
            (u'Majoitusvalvoja', u'Huolehtivat lattiamajoituspaikkojen pyörittämisestä yöaikaan. Työvuoroja myös molempina öinä.', [tyovoima]),
            (u'Myynti', u'Pääsylippujen myyntiä sekä lippujen tarkastamista. Myyjiltä edellytetään täysi-ikäisyyttä, asiakaspalveluhenkeä ja huolellisuutta rahankäsittelyssä. Vuoroja myös perjantaina.', [tyovoima]),
            (u'Green room', u'Työvoiman ruokahuolto green roomissa. Hygieniapassi suositeltava.', [tyovoima]),
            (u'Kirjasto', u'Mangakirjaston virkailijana toimimista.', [tyovoima]),
            (u'Ohjelma-avustaja', u'Lautapelien pyörittämistä, karaoken valvontaa, cosplay-kisaajien avustamista. Kerro Vapaa alue -kohdassa tarkemmin, mitä haluaisit tehdä. Huom! Puheohjelmasalien vänkäreiltä toivotaan AV-tekniikan osaamista.', [tyovoima]),
            (u'Kasaus ja purku', u'Kalusteiden siirtelyä & opasteiden kiinnittämistä. Ei vaadi erikoisosaamista. Työvuoroja myös jo pe sekä su conin sulkeuduttua, kerro lisätiedoissa jos voit osallistua näihin.', [tyovoima]),
            (u'Järjestyksenvalvoja', u'Kävijöiden turvallisuuden valvominen conipaikalla ja yömajoituksessa. Edellyttää voimassa olevaa JV-korttia ja asiakaspalveluasennetta. HUOM! Et voi valita tätä tehtävää hakemukseesi, ellet ole täyttänyt tietoihisi JV-kortin numeroa (oikealta ylhäältä oma nimesi &gt; Pätevyydet).', [jv]),
            (u'Kortiton järjestyksenvalvoja', u'Kävijöiden turvallisuuden valvominen conipaikalla ja yömajoituksessa. HUOM! Tähän tehtävään hakeminen edellyttää henkilötunnuksen syöttämistä sille varattuun kenttään.', [jv]),

            (u'Erikoistehtävä', u'Mikäli olet sopinut erikseen työtehtävistä ja/tai sinut on ohjeistettu täyttämään lomake, valitse tämä ja kerro tarkemmin Vapaa alue -kentässä mihin tehtävään ja kenen toimesta sinut on valittu.', [tyovoima]),

            (u'Ohjelmanpitäjä', u'Luennon tai muun vaativan ohjelmanumeron pitäjä', [ohjelma]),
        ]:
            job_category, created = JobCategory.objects.get_or_create(
                event=self.event,
                name=name,
                defaults=dict(
                    description=description,
                    slug=slugify(name),
                )
            )

            if created:
                job_category.personnel_classes = pcs
                job_category.save()

        labour_event_meta.create_groups()

        for name in [u'Conitea']:
            JobCategory.objects.filter(event=self.event, name=name).update(public=False)

        for jc_name, qualification_name in [
            (u'Järjestyksenvalvoja', u'JV-kortti'),
            # (u'Green room', u'Hygieniapassi'),
        ]:
            jc = JobCategory.objects.get(event=self.event, name=jc_name)
            qual = Qualification.objects.get(name=qualification_name)

        # TODO
        period_length = timedelta(hours=8)
        for period_description, period_start in [
            ("Perjantain kasaus (pe klo 12–21)", None),
            ("Lauantain aamuvuoro (la klo 08–14)", None),
            ("Lauantain iltapäivävuoro (la klo 14–20)", None),
            ("Lauantain iltavuoro (la klo 20–02)", None),
            ("Lauantai–sunnuntai-yövuoro (su klo 02–08)", None),
            ("Sunnuntain aamuvuoro (su klo 08–14)", None),
            ("Sunnuntain iltapäivävuoro ja purku (su klo 14–20)", None),
        ]:
            WorkPeriod.objects.get_or_create(
                event=self.event,
                description=period_description,
                defaults=dict(
                    start_time=period_start,
                    end_time=(period_start + period_length) if period_start else None,
                )
            )

        for diet_name in [
            u'Gluteeniton',
            u'Laktoositon',
            u'Maidoton',
            u'Vegaaninen',
            u'Lakto-ovo-vegetaristinen',
        ]:
            SpecialDiet.objects.get_or_create(name=diet_name)

        for night in [
            u'Perjantain ja lauantain välinen yö',
            u'Lauantain ja sunnuntain välinen yö',
        ]:
            Night.objects.get_or_create(name=night)

        AlternativeSignupForm.objects.get_or_create(
            event=self.event,
            slug=u'conitea',
            defaults=dict(
                title=u'Conitean ilmoittautumislomake',
                signup_form_class_path='events.animecon2015.forms:OrganizerSignupForm',
                signup_extra_form_class_path='events.animecon2015.forms:OrganizerSignupExtraForm',
                active_from=datetime(2015, 3, 3, 18, 0, 0, tzinfo=self.tz),
                active_until=datetime(2015, 11, 22, 23, 59, 59, tzinfo=self.tz),
            ),
        )

        for wiki_space, link_title, link_group in [
            ('ACONWORK', 'Työvoimawiki', 'accepted'),
        ]:
            InfoLink.objects.get_or_create(
                event=self.event,
                title=link_title,
                defaults=dict(
                    url='https://confluence.tracon.fi/display/{wiki_space}'.format(wiki_space=wiki_space),
                    group=labour_event_meta.get_group(link_group),
                )
            )
Пример #30
0
    def setup_labour(self):
        from core.models import Person
        from labour.models import (
            AlternativeSignupForm,
            InfoLink,
            Job,
            JobCategory,
            LabourEventMeta,
            Perk,
            PersonnelClass,
            Qualification,
            WorkPeriod,
        )
        from ...models import SignupExtra
        from django.contrib.contenttypes.models import ContentType

        labour_admin_group, = LabourEventMeta.get_or_create_groups(self.event, ['admins'])

        if self.test:
            from core.models import Person
            person, unused = Person.get_or_create_dummy()
            labour_admin_group.user_set.add(person.user)

        content_type = ContentType.objects.get_for_model(SignupExtra)

        labour_event_meta_defaults = dict(
            signup_extra_content_type=content_type,
            work_begins=self.event.start_time - timedelta(days=1),
            work_ends=self.event.end_time + timedelta(hours=4),
            admin_group=labour_admin_group,
            contact_email='Popcult Helsingin työvoimavastaava <[email protected]>',
        )

        if self.test:
            t = now()
            labour_event_meta_defaults.update(
                registration_opens=t - timedelta(days=60),
                registration_closes=t + timedelta(days=60),
            )

        labour_event_meta, unused = LabourEventMeta.objects.get_or_create(
            event=self.event,
            defaults=labour_event_meta_defaults,
        )

        for pc_name, pc_slug, pc_app_label in [
            ('Vastaava', 'vastaava', 'labour'),
            ('Työvoima', 'tyovoima', 'labour'),
            ('Ohjelmanjärjestäjä', 'ohjelma', 'programme'),
            ('Media', 'media', 'badges'),
            ('Myyjä', 'myyja', 'badges'),
            ('Vieras', 'vieras', 'badges'),
        ]:
            personnel_class, created = PersonnelClass.objects.get_or_create(
                event=self.event,
                slug=pc_slug,
                defaults=dict(
                    name=pc_name,
                    app_label=pc_app_label,
                    priority=self.get_ordering_number(),
                ),
            )

        tyovoima = PersonnelClass.objects.get(event=self.event, slug='tyovoima')
        vastaava = PersonnelClass.objects.get(event=self.event, slug='vastaava')

        for jc_data in [
            (
                'Vastaava',
                'Tapahtuman järjestelytoimikunnan jäsen eli vastaava',
                [vastaava]
            ),
            (
                'Järjestyksenvalvoja',
                'Järjestyksenvalvojan tehtäviin kuuluvat lippujen tarkistus, kulunvalvonta sekä ihmisten ohjaus. Tehtävään vaaditaan JV-kortti.',
                [tyovoima]
            ),
        ]:
            if len(jc_data) == 3:
                name, description, pcs = jc_data
                job_names = []
            elif len(jc_data) == 4:
                name, description, pcs, job_names = jc_data
            else:
                raise ValueError("Length of jc_data must be 3 or 4")

            job_category, created = JobCategory.objects.get_or_create(
                event=self.event,
                slug=slugify(name),
                defaults=dict(
                    name=name,
                    description=description,
                )
            )

            if created:
                job_category.personnel_classes = pcs
                job_category.save()

            for job_name in job_names:
                job, created = Job.objects.get_or_create(
                    job_category=job_category,
                    slug=slugify(job_name),
                    defaults=dict(
                        title=job_name,
                    )
                )

        labour_event_meta.create_groups()

        JobCategory.objects.filter(event=self.event, slug='vastaava').update(public=False)

        for jc_name, qualification_name in [
            ('Järjestyksenvalvoja', 'JV-kortti'),
        ]:
            jc = JobCategory.objects.get(event=self.event, name=jc_name)
            qual = Qualification.objects.get(name=qualification_name)
            if not jc.required_qualifications.exists():
                jc.required_qualifications = [qual]
                jc.save()

        AlternativeSignupForm.objects.get_or_create(
            event=self.event,
            slug='vastaava',
            defaults=dict(
                title='Vastaavien ilmoittautumislomake',
                signup_form_class_path='events.popcult2017.forms:OrganizerSignupForm',
                signup_extra_form_class_path='events.popcult2017.forms:OrganizerSignupExtraForm',
                active_from=datetime(2017, 1, 12, 0, 0, 0, tzinfo=self.tz),
                active_until=self.event.start_time,
            ),
        )