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})
def lore(request): professions = Handler.get_data('professions') races = Handler.get_data('races') return render(request, 'helper/lore.html', { 'races': races, 'professions': professions })
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
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')
def home(request): if Handler.user_exists(request): email = 'Welcome, ' + request.session['email'] else: email = "" return render(request, "helper/Home.html", {'email': email})
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)
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})
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})
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() }
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})
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))
def get_secondary_statistics(obj): secondaryStatistics = Handler.get_secondary_statistics(obj) return secondaryStatistics.items()
def get_primary_statistics(obj): primaryStatistics = Handler.get_primary_statistics(obj) return primaryStatistics.items()
def remove_character(obj): print(str(obj)) return Handler.delete_character('character', obj)