-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inline formsettejä ja geneerisempää templatea.
- Loading branch information
Frans Korhonen
committed
Apr 19, 2009
1 parent
1acc1cc
commit 2a2d631
Showing
14 changed files
with
201 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% extends "tupa/base.html" %} | ||
{% block content %} | ||
|
||
<A href='{{taakse}}'>taakse</A><br> | ||
|
||
<h1> {{ heading }}</h1> | ||
|
||
<form method="POST" action=""> | ||
|
||
{% if forms %} | ||
{% for form in forms%} | ||
{{form}} <br> | ||
{% endfor%} | ||
{% endif %} | ||
{% if formsets %} | ||
{% for formset in formsets %} | ||
<h2>{{formset.label}}</h2> | ||
{{ formset.management_form }} | ||
{% for form in formset.forms %} | ||
{{ form }} <br> | ||
{% endfor %} | ||
{% endfor%} | ||
{% endif %} | ||
<br> | ||
{% include "tupa/tallenna.html" %} | ||
</form> | ||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,9 @@ | ||
{% extends "tupa/base.html" %} | ||
{% block content %} | ||
|
||
<A href='../../'>taakse</A> <br> | ||
|
||
<h2>Tehtävien määritys</h2> | ||
<h3>Valitse sarja ja tehtävä</h3> | ||
|
||
{% if sarja_tehtavat %} | ||
<ul id="sarjatabs" class="shadetabs"> | ||
{% for sarja in sarja_tehtavat%} | ||
{% ifequal sarja sarja_tehtavat.0 %} | ||
<li><a href="#" rel="sarja{{ sarja.0.id }}" class="selected">{{ sarja.0.nimi }}</a></li> | ||
{% else %} | ||
<li><a href="#" rel="sarja{{ sarja.0.id }}">{{ sarja.0.nimi }}</a></li> | ||
{% endifequal %} | ||
{% endfor %} | ||
</ul> | ||
|
||
<div style="border:1px solid gray; width:800px; margin-bottom: 1em; padding: 10px"> | ||
|
||
{% for sarja in sarja_tehtavat %} | ||
<div id="sarja{{ sarja.0.id }}" class="tabcontent"> | ||
<ul id="tehtavatabs" class=""> | ||
{% for tehtava in sarja.1 %} | ||
<li><a href="/tupa/{{sarja.0.kisa.nimi}}/maarita/tehtava/{{ tehtava.id }}">{{ tehtava.numero }} {{ tehtava.nimi }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
<h3><a href="/tupa/{{sarja.0.kisa.nimi}}/maarita/tehtava/uusi/sarja/{{ sarja.0.id }}/">lisää tehtävä</a> </h3> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
|
||
{% else %} | ||
<p>Ei määriteltyjä sarjoja tai tehtäviä.</p> | ||
{% endif %} | ||
|
||
{% endblock %} | ||
{% extends "tupa/valitse.html" %} | ||
|
||
{% block sarake %} | ||
{% for taulu in sarake %} | ||
<li><a href="{{taulu.linkki}}"> {{taulu.nimi}}</a></li> | ||
{% endfor %} | ||
<h3><a href="uusi/sarja/{{ sarake.id }}/">lisää tehtävä</a> </h3> | ||
{% endblock%} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<input name="Reset" type="reset" class="btn" onmouseover="this.className='btn btnhov'" onmouseout="this.className='btn'" value="Peru"/> | ||
<input name="Submit" type="submit" class="btn" onmouseover="this.className='btn btnhov'" onmouseout="this.className='btn'" value="Tallenna ->"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{% extends "tupa/base.html" %} | ||
{% block content %} | ||
|
||
<A href='{{taakse}}'>taakse</A><br> | ||
<h1> {{ heading }}</h1> | ||
|
||
{% if taulukko %} | ||
<ul id="sarjatabs" class="shadetabs"> | ||
{% for sarake in taulukko %} | ||
{% ifequal sarake taulukko.0 %} | ||
<li><a href="#" rel="sarake{{ sarake.id }}" class="selected">{{ sarake.otsikko }}</a></li> | ||
{% else %} | ||
<li><a href="#" rel="sarake{{ sarake.id }}">{{ sarake.otsikko }}</a></li> | ||
{% endifequal %} | ||
{% endfor %} | ||
</ul> | ||
|
||
<div style="border:1px solid gray; width:800px; margin-bottom: 1em; padding: 10px"> | ||
|
||
{% for sarake in taulukko%} | ||
<div id="sarake{{ sarake.id }}" class="tabcontent"> | ||
<ul id="tehtavatabs" class=""> | ||
{% block sarake%} {{sarake}} {% endblock %} | ||
</ul> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{%endif%} | ||
|
||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% extends "tupa/valitse.html" %} | ||
|
||
{% block sarake %} | ||
{{ sarake.management_form }} | ||
{% for form in sarake.forms %} | ||
{{ form }} <br> | ||
{% endfor %} | ||
{% endblock%} | ||
{% block content %} | ||
<form method="POST" action=""> | ||
{{ block.super }} | ||
{% include "tupa/tallenna.html" %} | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% extends "tupa/valitse.html" %} | ||
|
||
{% block sarake %} | ||
{% for taulu in sarake %} | ||
<li><a href="{{taulu.linkki}}"> {{taulu.nimi}}</a></li> | ||
{% endfor %} | ||
{% endblock%} | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,48 @@ | ||
# coding: latin-1 | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.forms.models import modelformset_factory | ||
from django.forms.util import ValidationError | ||
from django import forms | ||
from TulosLaskin import * | ||
from models import * | ||
from django.forms import ModelForm | ||
from django.forms.models import inlineformset_factory | ||
|
||
KaavaFormSet = inlineformset_factory(Tehtava,OsapisteKaava,extra=3 ) | ||
MaariteFormSet = inlineformset_factory(Tehtava,SyoteMaarite,extra=3 ) | ||
VartioFormSet = inlineformset_factory(Sarja,Vartio,extra=10,fields=('nro','nimi') ) | ||
SarjaFormSet = inlineformset_factory(Kisa,Sarja,extra=4 ) | ||
|
||
|
||
class TehtavaForm(ModelForm): | ||
def __init__(self,post,instance=None,sarja=None) : | ||
self.sarja=sarja | ||
super(ModelForm,self).__init__(post,instance=instance) | ||
def save(self): | ||
tehtava = super(ModelForm,self).save(commit=False) | ||
tehtava.sarja=self.sarja | ||
tehtava.save() | ||
return tehtava | ||
class Meta: | ||
model = Tehtava | ||
fields = ('nimi', 'jarjestysnro','kaava') | ||
|
||
model = Tehtava | ||
fields = ('nimi', 'jarjestysnro','kaava') | ||
|
||
class PisteSyoteForm(ModelForm): | ||
arvo = forms.FloatField(required=False) | ||
def __init__(self,maarite=None,vartio=None,*argv,**argkw) : | ||
super(ModelForm,self).__init__(*argv,**argkw) | ||
self.maarite=maarite | ||
self.vartio=vartio | ||
def save(self): | ||
syote = super(ModelForm,self).save(commit=False) | ||
syote.maarite=self.maarite | ||
syote.vartio=self.vartio | ||
if self.cleaned_data['arvo'] : | ||
syote.save() | ||
elif syote.id : | ||
syote.delete() | ||
class Meta: | ||
exclude = ('maarite','vartio') | ||
model = Syote | ||
|
||
def luoKaavaFormit(tehtavalle=None,post=None,tyhjia=0): | ||
KaavaFormSet = modelformset_factory( OsapisteKaava,extra=tyhjia,can_delete=True,exclude=('tehtava',)) | ||
return KaavaFormSet(post,queryset=OsapisteKaava.objects.filter(tehtava=tehtavalle) ) | ||
|
||
def luoMaariteFormit(tehtavalle=None,post=None,tyhjia=0): | ||
MaariteFormSet = modelformset_factory( SyoteMaarite,extra=tyhjia,can_delete=True,exclude=('tehtava',)) | ||
return MaariteFormSet(post,queryset=SyoteMaarite.objects.filter(tehtava=tehtavalle) ) | ||
|
||
def luoVartioFormit(sarjalle,post=None,tyhjia=0): | ||
VartioFormSet = modelformset_factory( Vartio,fields=('nro', 'nimi'),extra=tyhjia,can_delete=True) | ||
return VartioFormSet(post,queryset=Vartio.objects.filter(sarja=sarjalle),prefix=sarjalle.nimi ) | ||
|
||
class KisaForm(ModelForm): | ||
class Meta: | ||
model = Kisa | ||
|
||
def luoSarjaFormit(kisalle,post=None,tyhjia=0): | ||
SarjaFormSet = modelformset_factory( Sarja,exclude=('kisa',),extra=tyhjia,can_delete=True ) | ||
formit=SarjaFormSet(post, queryset=Sarja.objects.filter(kisa=kisalle) ) | ||
return formit | ||
|
||
class AikaSyoteForm(forms.Form) : | ||
h = forms.IntegerField(required=False,widget=forms.TextInput(attrs={'size':'1'})) | ||
min = forms.IntegerField(required=False,widget=forms.TextInput(attrs={'size':'1'})) | ||
s = forms.IntegerField(required=False,widget=forms.TextInput(attrs={'size':'1'})) | ||
|
||
def __init__(self,maarite,vartio,post=None) : | ||
""" | ||
Pakolliset parametrit ovat: | ||
-Syötteen määrite jota formi edustaa | ||
-Vartio jota formi edustaa | ||
Optionaaliset: | ||
-Sivun post data jossa kentään syödetyt tiedot. | ||
""" | ||
self.maarite=maarite | ||
syotteet = Syote.objects.filter(vartio = vartio ).filter(maarite=maarite) | ||
self.syote=None | ||
if syotteet: | ||
self.syote=syotteet[0] | ||
self.vartio=vartio | ||
prefix = "aika_syote_" + str(self.maarite.id) + "_" + str(self.vartio.id) | ||
initial ={} | ||
if self.syote and self.syote.arvo: | ||
tunnit=divmod(Decimal(self.syote.arvo) , 60*60)[0] | ||
minuutit=divmod(Decimal(self.syote.arvo) , 60)[0]- tunnit*60 | ||
sekuntit= Decimal(self.syote.arvo) - tunnit*60*60 -minuutit*60 | ||
h = tunnit | ||
min = minuutit | ||
s = sekuntit | ||
initial= { "h" : h, "min" : min , "s" : s } | ||
super(forms.Form, self).__init__(post,prefix=prefix,initial=initial) | ||
|
||
def save(self) : | ||
if self.is_valid() : | ||
tunnit= self.cleaned_data["h"] | ||
minuutit= self.cleaned_data["min"] | ||
sekuntit= self.cleaned_data["s"] | ||
|
||
if not tunnit==None or not minuutit==None or not sekuntit==None : | ||
arvo=Decimal(0) | ||
if tunnit : | ||
arvo=arvo + tunnit*60*60 | ||
if minuutit: | ||
arvo=arvo + minuutit*60 | ||
if sekuntit: | ||
arvo= arvo + sekuntit | ||
|
||
if not self.syote: | ||
self.syote=Syote() | ||
self.syote.maarite=self.maarite | ||
self.syote.vartio=self.vartio | ||
self.syote.arvo = str(arvo) | ||
self.syote.save() | ||
else: | ||
if self.syote: | ||
self.syote.delete() | ||
self.syote = None | ||
|
Oops, something went wrong.