from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants from string import digits class IdPage(Page): form_model = models.Player form_fields = ['DecisionLabId', 'VirtualLabId'] def vars_for_template(self): pdone = round(self.player.participant._index_in_pages / self.player.participant._max_page_index * 100) return { "pdone" : pdone} def DecisionLabId_error_message(self, value): # Exactly 7 digits if len( value ) < 7: return "Eingabe zu kurz! Die Decision Lab Id sollte genau sieben Stellen haben!" # Only digits if any( [c not in digits for c in value] ): return "Bitte nur Ziffern eingeben!" # Last two digits are the sum of all other digits sm = sum( [int(c) for c in value[0:5]] ) if not sm == int( value[5:]): return "Fehlerhafte Decision Lab ID!" if value == "0000000": return "Fehlerhafe Decision Lab ID!" for p in self.subsession.get_players(): if ("DecisionLabId" in p.participant.vars) and (p.participant.vars["DecisionLabId"] == value): return "Decision Lab ID bereits verwendet!" def VirtualLabId_error_message(self, value): # Empty value is ok! if len( value ) == 0: return if len( value ) < 5: return "Eingabe zu kurz! Die Id sollte genau fünf Stellen haben!" value = value.upper() if any( [c in digits for c in value[0:4]] ): return "Bitte kontrollieren sie die eigegebene Id!" if any( [c not in digits for c in value[4:]] ): return "Bitte kontrollieren sie die eigegebene Id!" def before_next_page(self): self.player.participant.vars["DecisionLabId"] = self.player.DecisionLabId self.player.participant.vars["VirtualLabId"] = self.player.VirtualLabId.upper() page_sequence = [ IdPage ]