Esempio n. 1
0
 def save(self, *args, **kwargs):
     is_create = not self.pk
     super(Quest, self).save(*args, **kwargs)
     if is_create:
         if not self.parent:
             Membership.objects.create(quest=self, user=self.creator, role=Membership.ORGANIZER)
             name = 'agent{0}'.format(self.pk)
             username = generate_random_username(name)
             password = generate_random_password()
             agent = User.objects.create_user(username=username, password=password, first_name=name, last_name=password)
             Membership.objects.create(quest=self, user=agent, role=Membership.AGENT)
             Mission.objects.create(quest=self, name_in_table='Старт', order_number=0)
         Mission.objects.create(quest=self, name_in_table='Финиш', order_number=1, is_finish=True)
Esempio n. 2
0
def players_quest(request, quest_id):
    quest = get_object_or_404(Quest, pk=quest_id, parent__isnull=True)
    request = is_quest_organizer(request, quest)
    players = quest.players()
    form = PlayerForm(request.POST or None)
    if form.is_valid():
        name = form.cleaned_data["name"]
        username = generate_random_username(name)
        password = generate_random_password()
        user = User.objects.create_user(username=username, password=password, first_name=name, last_name=password)
        Membership.objects.create(quest=quest, user=user, role=Membership.PLAYER)
        if quest.linear or quest.line_nonlinear:
            start_mission = quest.start_mission()
            CurrentMission.objects.create(player=user, mission=start_mission)
        return redirect('coordination:quest_players', quest_id=quest_id)
    context = {'quest': quest, 'form': form, 'players': players}
    return render(request, 'coordination/quests/members/players.html', context)