Exemplo n.º 1
0
def create_character():
    """Creates a new character"""
    if "user_id" not in session:
        flash("Please login first!")
        return redirect('/')

    form = CharacterForm()

    if form.validate_on_submit():
        name = form.name.data
        c_class = form.c_class.data
        race = form.race.data
        background = form.background.data
        equipment = form.equipment.data
        origin = form.origin.data

        character = Character(
        name=name, c_class=c_class, race=race, 
        background=background, equipment=equipment,
        origin=origin, user_id=session['user_id']
        )
        
        db.session.add(character)   
        db.session.commit()
        return redirect('/characters')

    return render_template('new_character.html', form=form)
Exemplo n.º 2
0
def NewCharacter(request):
    print "new character"
    form = CharacterForm()
    if request.POST:
        character = BaseCharacter()
        form = CharacterForm(request.POST, instance=character)
        new_character = form.save()
        print "now redirect to " + str(new_character)
        return redirect('characters.views.BasicInfo', new_character.id)
    return render_to_response("characters/new.html", {"form": form}, context_instance=RequestContext(request))
Exemplo n.º 3
0
def character_add(request):
    if request.method == 'POST':
        form = CharacterForm(request.POST)
        if form.is_valid():
            character = AlbionCharacter(name=request.POST['name'],
                                        role=request.POST['role'],
                                        user=request.user)
            character.save()
            return redirect('dashboard')
    else:
        form = CharacterForm()
    context = {}
    context['form'] = form
    return render(request, 'characters/character_add.html', context)
Exemplo n.º 4
0
class CharacterCreate(View, QtGui.QWidget):
    def __init__(self, *args, **kwargs):
        self.current_sidebar = None
        instance = kwargs.pop('instance', None)
        super(CharacterCreate, self).__init__(*args, **kwargs)
        self.layout = QtGui.QHBoxLayout() 
        self.form = CharacterForm(
            session=session, 
            parent=self.parent, 
            instance=instance, 
            sidebar_callback=self.update_sidebar
        )
        self.layout.addWidget(self.form.display())
        self.setLayout(self.layout) 
        self.update_sidebar()

    def update_sidebar(self):
        if self.current_sidebar is not None:
            self.layout.removeWidget(self.current_sidebar)
            self.current_sidebar.setParent(None)

        self.current_sidebar = CharacterDetail(instance=self.form.instance, parent=self)
        self.layout.addWidget(self.current_sidebar)

    def process(self, **kwargs):
        return self
Exemplo n.º 5
0
def character_creation(username):
    user = User.query.filter_by(username=current_user.username).first()
    form = CharacterForm()
    if request.method == 'POST' and form.validate():
        new_character = Character(name=form.name.data,
                                  strain=form.strain.data,
                                  class1=form.class1.data,
                                  player=current_user.id)
        db.session.add(new_character)
        db.session.commit()
        return render_template('character_selection.html',
                               user=user,
                               charactername=new_character)
    else:
        flash(form.errors)
        return render_template('character_creation.html', user=user, form=form)
Exemplo n.º 6
0
def character_update(request):
    if request.method == 'POST':
        form = CharacterForm(request.POST)
        if form.is_valid():
            character = AlbionCharacter.objects.get(user=request.user)
            character.name = request.POST['name']
            character.role = request.POST['role']
            character.secondary = request.POST['secondary']
            character.discord = request.POST['discord']
            character.save()
            return redirect('dashboard')
    else:
        character = AlbionCharacter.objects.get(user=request.user)
        initial = {}
        initial['name'] = character.name
        initial['role'] = character.role
        initial['secondary'] = character.secondary
        initial['discord'] = character.discord
        form = CharacterForm(initial=initial)
    context = {}
    context['form'] = form
    return render(request, 'characters/character_update.html', context)
Exemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     self.current_sidebar = None
     instance = kwargs.pop('instance', None)
     super(CharacterCreate, self).__init__(*args, **kwargs)
     self.layout = QtGui.QHBoxLayout() 
     self.form = CharacterForm(
         session=session, 
         parent=self.parent, 
         instance=instance, 
         sidebar_callback=self.update_sidebar
     )
     self.layout.addWidget(self.form.display())
     self.setLayout(self.layout) 
     self.update_sidebar()
Exemplo n.º 8
0
def edit_character(character_id):
    """Edits the details of a Character"""
    if 'user_id' not in session:
        flash('please login first!')
        return redirect('/login')

    character = Character.query.get_or_404(character_id)

    form = CharacterForm()

    if form.validate_on_submit():
        character.name = form.name.data
        character.c_class = form.c_class.data
        character.race = form.race.data
        character.background = form.background.data
        character.equipment = form.equipment.data
        character.origin = form.origin.data

        db.session.commit()
        return redirect("/characters")

    if character.user_id == session['user_id']:
        return render_template('character_edit.html', character=character, form=form)
Exemplo n.º 9
0
def character_creation_form():
    form = CharacterForm()
    if form.validate_on_submit():
        pass
    return render_template('character_creation.html', form=form)