示例#1
0
 def to_api(self):
     db = DB_Session()
     o = super(Events, self).to_api()
     o["competition"] = self.competition.to_api()
     o["season"] = self.season.to_api()
     db.close()
     return o
示例#2
0
 def to_api(self, admin):
     db = DB_Session()
     o = super(TeamPlayer, self).to_api()
     o["player"] = self.player.to_api(admin)
     o["nation"] = self.nation.to_api(admin)
     db.close()
     return o
示例#3
0
 def to_api(self):
     o = super(Transfer, self).to_api()
     db = DB_Session()
     o["releasing_team"] = self.releasing_team.to_api(None)
     o["taking_team"] = self.taking_team.to_api(None)
     o["player"] = self.player.to_api(None)
     db.close()
     return o
示例#4
0
 def get_tranlation(self, translation):
     session = DB_Session()
     if translation is not None:
         try:
             translation = translation.one()
         except Exception:
             translation = None
     session.close()
     return translation
示例#5
0
 def to_api(self, admin):
     o = super(Player, self).to_api(admin)
     db = DB_Session()
     nation = (
         db.query(Nation)
         .join(Nationality, Nation.id == Nationality.country_id)
         .join(Player, Player.id == Nationality.player_id)
         .filter(Player.id == self.id)
         .all()
     )
     try:
         o["nationality"] = _to_api(nation)
     except Exception, e:
         o["nation"] = None
示例#6
0
 def validates(self, source=None, _validate=True, **kw):
     source = source or kw or web.input()
     out = super(LoginForm, self).validates(source=source, _validate=_validate, **kw)
     db = DB_Session()
     query = db.query(User)
     try:
         user = query.filter(User.email == source.email).one()
         if user and user.validate_password(source.password):
             session = web.config.session
             session.login = 1
             session.privilege = user.privilege
             out = True
         else:
             out = False
     except Exception, e:
         out = False
示例#7
0
    def activate_user(cls, activation_key):
        """
        Validate an activation key and activate the corresponding
        ``User`` if valid.
        
        If the key is valid and has not expired, return the ``User``
        after activating.
        
        If the key is not valid or has expired, return ``False``.
        
        If the key is valid but the ``User`` is already active,
        return ``False``.
        
        To prevent reactivation of an account which has been
        deactivated by site administrators, the activation key is
        reset to the string constant ``RegistrationProfile.ACTIVATED``
        after successful activation.

        To execute customized logic when a ``User`` is activated,
        connect a function to the signal
        ``registration.signals.user_activated``; this signal will be
        sent (with the ``User`` as the value of the keyword argument
        ``user``) after a successful activation.
        
        """
        # from registration.signals import user_activated

        # Make sure the key we're trying conforms to the pattern of a
        # SHA1 hash; if it doesn't, no point trying to look it up in
        # the database.
        db = DB_Session()
        if SHA1_RE.search(activation_key):
            query = db.query(RegistrationProfile)
            profile = query.filter(RegistrationProfile.activation_key == activation_key).one()
            if not profile:
                return False
            if not profile.activation_key_expired():
                user = profile.user
                user.is_active = 1
                profile.activation_key = RegistrationProfile.ACTIVATED
                db.flush()
                db.commit()
                db.close()
                # user_activated.send(sender=self.model, user=user)
                return user
        return False
示例#8
0
 def to_api(self):
     o = super(MatchPlayerStatistics, self).to_api()
     db = DB_Session()
     o["player"] = db.query(Player).get(self.playerId).to_api(None)
     db.close()
     return o
示例#9
0
 def to_api(self, admin):
     db = DB_Session()
     o = super(EventStandingEntries, self).to_api()
     o["team"] = self.team.to_api(admin)
     db.close()
     return o
示例#10
0
 def to_api(self, admin):
     db = DB_Session()
     o = super(EventStandings, self).to_api()
     o["event_standing_entries"] = [v.to_api() for v in self.event_standing_entries]
     db.close()
     return o
示例#11
0
 def to_api(self, admin):
     db = DB_Session()
     o = super(Team, self).to_api()
     db.close()
     return o
示例#12
0
 def create_profile(self, user):
     """
     Create a ``RegistrationProfile`` for a given
     ``User``, and return the ``RegistrationProfile``.
     
     The activation key for the ``RegistrationProfile`` will be a
     SHA1 hash, generated from a combination of the ``User``'s
     username and a random salt.
     
     """
     salt = sha.new(str(random.random())).hexdigest()[:5]
     activation_key = sha.new(salt + user.username).hexdigest()
     #        prepend "key_" to the key_name, because key_names can't start with numbers
     registrationprofile = RegistrationProfile(user=user, activation_key=activation_key)
     db = DB_Session()
     db.add(registrationprofile)
     db.flush()
     db.refresh(registrationprofile)
     db.commit()
     db.close()
     return registrationprofile
示例#13
0
    def create_inactive_user(cls, username, password, email, domain_override="", send_email=True):
        new_user = User(username=username, email=email, is_active=False)
        new_user.set_password(password)
        db = DB_Session()
        db.add(new_user)
        db.flush()
        db.refresh(new_user)
        db.commit()
        db.close()

        registration_profile = cls.create_profile(new_user)
        if send_email:
            current_site = domain_override
            #            current_site = Site.objects.get_current()

            subject = web.template.render("templates").activation_email_subject(
                {"site": current_site, "activation_key": registration_profile.activation_key}
            )
            #             render_to_string('registration/activation_email_subject.txt',
            #                                        { 'site': current_site,'activation_key': registration_profile.activation_key })
            # Email subject *must not* contain newlines
            subject = "".join(subject.__str__().splitlines())

            message = web.template.render("templates").activation_email(
                {
                    "activation_key": registration_profile.activation_key,
                    "expiration_days": settings.ACCOUNT_ACTIVATION_DAYS,
                    "site": current_site,
                }
            )
            #             render_to_string('registration/activation_email.txt',
            #                                        { 'activation_key': registration_profile.activation_key,
            #                                          'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
            #                                          'site': current_site })

            web.sendmail(settings.DEFAULT_FROM_EMAIL, new_user.email, subject, message)
        return new_user