Пример #1
0
def character_delete(request, name, userUID):

    if request.method == 'POST':
        Handler.delete_character('Character', name, userUID)
        return redirect('/helper/profile')

    return render(request, 'helper/profile.html', {'obj': obj})
Пример #2
0
def lore(request):
    professions = Handler.get_data('professions')
    races = Handler.get_data('races')

    return render(request, 'helper/lore.html', {
        'races': races,
        'professions': professions
    })
Пример #3
0
 def get_context_data(self, **kwargs):
     context = super(CreatorWizard, self).get_context_data(**kwargs)
     if self.race:
         self.primaryStatistics[
             'primaryStats'] = Handler.get_merged_primary(self.race)
         self.secondaryStatistics[
             'secondaryStats'] = Handler.get_merged_secondary(
                 self.race, self.primaryStatistics['primaryStats'])
         context.update(self.primaryStatistics)
         context.update(self.secondaryStatistics)
     return context
Пример #4
0
 def done(self, form_list, **kwargs):
     data = self.get_all_cleaned_data()
     data['primary_statistics'] = self.primaryStatistics['primaryStats']
     data['secondary_statistics'] = self.secondaryStatistics[
         'secondaryStats']
     try:
         data['userUID'] = self.request.session['uid']
     except:
         pass
     data.update(
         Handler.get_inventory(form_list[1].cleaned_data['profession']))
     Handler.push_data(data, 'character')
     messages.info(
         self.request,
         'Character with name ' + data['name'] + ' has been created!')
     return redirect('/helper/template')
Пример #5
0
def home(request):
    if Handler.user_exists(request):
        email = 'Welcome, ' + request.session['email']
    else:
        email = ""

    return render(request, "helper/Home.html", {'email': email})
Пример #6
0
 def render_template(self,
                     request,
                     form,
                     previous_fields,
                     step,
                     context=None):
     if step == 1:
         race = request.POST.get('0-race')
         form.fields['professions'] = forms.ChoiceField(
             widget=RadioSelect(), choices=[])
         form.fields['professions'].choices = [
             Handler.get_all_allowed_professions(
                 Handler.get_data('Professions'), race)
         ]
     return super(CreatorWizard,
                  self).render_template(request, form, previous_fields,
                                        step, context)
Пример #7
0
def characters(request):
    user_characters = Handler.get_data('character')
    obj = []
    if user_characters:
        for entity in user_characters:
            character = Character(**entity)
            obj.append(character)

    return render(request, 'helper/characters.html', {'obj': obj})
Пример #8
0
def profile(request):
    if not Handler.user_exists(request):
        messages.info(request, 'Please log in to see your characters')
        return redirect('/helper/home')
    user_characters = Handler.get_data_by_uid(request, 'character')
    obj = []
    if user_characters:
        for entity in user_characters:
            character = Character(**entity)
            obj.append(character)
    if (request.GET.get('mybtn')):
        character = ast.literal_eval(request.GET.get('mytextbox'))
        buffer = creatorpdf.createPDF(character)
        return FileResponse(buffer,
                            as_attachment=True,
                            filename='WH_character_sheet.pdf')

    return render(request, 'helper/profile.html', {'obj': obj})
Пример #9
0
 class Meta:
     model = Character
     fields = '__all__'
     exclude = ('profession', 'weapon', 'equipment', 'armor')
     widgets = {
         'race':
         forms.Select(choices=Handler.get_data_in_list('Races')),
         'star_sign':
         forms.Select(choices=Handler.get_data_in_list('Starsigns')),
         'sex':
         forms.Select(choices=Handler.get_data_in_list('Sex')),
         'userUID':
         forms.HiddenInput(),
         'primary_statistics':
         forms.HiddenInput(),
         'secondary_statistics':
         forms.HiddenInput(),
         #'keyid' : forms.HiddenInput()
         #'date' : forms.HiddenInput()
     }
Пример #10
0
def login(request):
    if Handler.user_exists(request):
        messages.info(request, 'You are already logged in')
        return redirect('/helper/home')
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data["email"]
            password = form.cleaned_data["password"]
            try:
                user = authe.sign_in_with_email_and_password(email=email,
                                                             password=password)
                messages.info(request, 'Successfully logged in!')
                print(user['email'] + " logged in")
                Handler.session_handler(request, user)
                return redirect('/helper/home')
            except:
                messages.info(request, 'Invalid email or password!')
                form = LoginForm()
    else:
        form = LoginForm()

    return render(request, 'helper/login.html', {'form': form})
Пример #11
0
 def __init__(self, race, *args, **kwargs):
     super(CreatorForm2, self).__init__(*args, **kwargs)
     self.fields['profession'] = forms.ChoiceField(
         widget=forms.RadioSelect(),
         choices=Handler.get_all_allowed_professions(
             Handler.get_data('Professions'), race))
Пример #12
0
def get_secondary_statistics(obj):
    secondaryStatistics = Handler.get_secondary_statistics(obj)
    return secondaryStatistics.items()
Пример #13
0
def get_primary_statistics(obj):
    primaryStatistics = Handler.get_primary_statistics(obj)
    return primaryStatistics.items()
Пример #14
0
def remove_character(obj):
    print(str(obj))
    return Handler.delete_character('character', obj)