Пример #1
0
def create_goal_evaluation_cache(
    goal_id,
    gec_achievement_date,
    gec_user_id,
    gec_achieved=undefined,
    gec_value=undefined,
):
    goal_evaluation_cache = GoalEvaluationCache()

    if gec_achieved is undefined:
        goal_evaluation_cache.gec_achieved = True
    else:
        goal_evaluation_cache.gec_achieved = gec_achieved

    if gec_value is undefined:
        goal_evaluation_cache.gec_value = 20.0
    else:
        goal_evaluation_cache.gec_value = gec_value

    goal_evaluation_cache.goal_id = goal_id
    goal_evaluation_cache.achievement_date = gec_achievement_date
    goal_evaluation_cache.user_id = gec_user_id
    goal_evaluation_cache.achieved = gec_achieved
    goal_evaluation_cache.value = gec_value
    DBSession.add(goal_evaluation_cache)
    DBSession.flush()

    return goal_evaluation_cache
Пример #2
0
def add_Achivement(request):

    achievementCategory = AchievementCategory()
    achievementCategory.name = request.POST["category"]
    DBSession.add(achievementCategory)
    DBSession.flush()

    achievement = Achievement()
    achievement.name = request.POST["achievement_name"]
    achievement.valid_start = request.POST["achievement_valid_start"]
    achievement.valid_end = request.POST["achievement_valid_end"]
    achievement.maxlevel = request.POST["achievement_maxlevel"]
    achievement.relevance = "global"
    achievement.evaluation_timezone = "UTC"
    achievement.achievementcategory_id = achievementCategory.id
    """
    achievement.lat = 0
    achievement.lng = 0
    achievement.max_distance = 0
    achievement.evaluation = "immediately"
    #to add with edit after creating groups and friends users
    achievement.relevance = "friends"
    achievement.view_permission = request.POST["achievement_view_permission"]
    """

    DBSession.add(achievement)
    DBSession.flush()
    params = {"id": achievement.id}
    #params = {"id": "7"}
    return HTTPFound(request.route_url('upload', _query=params))
Пример #3
0
def create_variable(name, increase_permission="admin"):
    variable = Variable()
    variable.name = name
    variable.increase_permission = increase_permission
    DBSession.add(variable)
    DBSession.flush()
    return variable
Пример #4
0
def add_Reward(request):
    reward = Reward()
    reward.name = request.POST["name"]
    DBSession.add(reward)
    DBSession.flush()

    return {"Achivement_Reward": "ok"}
Пример #5
0
def create_achievements():
    user_type = DBSession.query(SubjectType).filter_by(name="User").first()
    team_type = DBSession.query(SubjectType).filter_by(name="Team").first()
    country_type = DBSession.query(SubjectType).filter_by(
        name="Country").first()

    invite_users = Achievement(
        name="invite_users",
        maxlevel=100,
        hidden=False,
        evaluation="immediately",
        comparison_type="none",
        player_subjecttype_id=user_type["id"],
        view_permission="own",
        condition=
        """{"term": {"type": "literal", "variable": "invite_users"}}""",
        goal="3*level",
        operator="geq")
    DBSession.add(invite_users)
    DBSession.flush()

    cyclist_of_the_month = Achievement(
        name="cyclist_of_the_month",
        hidden=False,
        evaluation="monthly",
        comparison_type="context_subject",
        player_subjecttype_id=user_type["id"],
        view_permission="everyone",
        condition="""{"term": {"type": "literal", "variable": "cycling"}}""",
        context_subjecttype_id=country_type.id,
        operator="geq")
    cyclist_of_the_month.compared_subjecttypes.append(user_type, team_type)
    DBSession.add(cyclist_of_the_month)
    DBSession.flush()
Пример #6
0
    def test_get_achievement_properties(self):

        achievement = create_achievement(achievement_maxlevel=3)

        achievementproperty = AchievementProperty()
        achievementproperty.name = "xp"
        DBSession.add(achievementproperty)
        DBSession.flush()

        achievements_achievementproperty = AchievementAchievementProperty()
        achievements_achievementproperty.achievement_id = achievement.id
        achievements_achievementproperty.property_id = achievementproperty.id
        achievements_achievementproperty.value = "5"
        achievements_achievementproperty.from_level = 2
        DBSession.add(achievements_achievementproperty)
        DBSession.flush()

        clear_all_caches()

        result1 = Achievement.get_achievement_properties(achievement.id, 4)
        print(result1)

        result2 = Achievement.get_achievement_properties(achievement.id, 1)
        print(result2)

        self.assertNotEqual(result1, [])
        self.assertEqual(result2, [])
Пример #7
0
    def test_evaluate_achievement_for_participate(self):

        achievement = create_achievement(
            achievement_name="participate_achievement",
            achievement_relevance="own",
            achievement_maxlevel=4)

        user = create_user()

        achievement_date = Achievement.get_datetime_for_evaluation_type(
            achievement.evaluation_timezone, achievement.evaluation)

        current_level = 1
        achievement_user = AchievementSubject()
        achievement_user.user_id = user.id
        achievement_user.achievement_id = achievement.id
        achievement_user.achievement_date = achievement_date
        achievement_user.level = current_level
        DBSession.add(achievement_user)
        DBSession.flush()

        variable = create_variable("participate", variable_group="day")
        Value.increase_value(variable_name=variable.name,
                             user=user,
                             value=1,
                             key="5")

        create_goals(
            achievement,
            goal_condition=
            """{"term": {"key": ["5","7"], "type": "literal", "key_operator": "IN", "variable": "participate"}}""",
            goal_group_by_key=True,
            goal_operator="geq",
            goal_goal="1*level")

        clear_all_caches()

        level = Achievement.evaluate(user, achievement.id,
                                     achievement_date).get("level")

        Value.increase_value(variable_name="participate",
                             user=user,
                             value=1,
                             key="7",
                             at_datetime=achievement_date)
        level2 = Achievement.evaluate(user, achievement.id,
                                      achievement_date).get("level")

        Value.increase_value(variable_name="participate",
                             user=user,
                             value=5,
                             key="5",
                             at_datetime=achievement_date)
        level1 = Achievement.evaluate(user, achievement.id,
                                      achievement_date).get("level")

        self.assertEqual(level, 1)
        self.assertEqual(level2, 1)
        self.assertEqual(level1, 4)
Пример #8
0
def get_or_create_role(DBSession, name):
    from gengine.app.model import AuthRole

    auth_role = DBSession.query(AuthRole).filter_by(name=name).first()
    if not auth_role:
        auth_role = AuthRole(name=name)
        DBSession.add(auth_role)
    return auth_role
Пример #9
0
def create_variables():
    invite_users = Variable(name="invite_users", increase_permission="own")
    DBSession.add(invite_users)

    cycling = Variable(name="cycling", increase_permission="own")
    DBSession.add(cycling)

    DBSession.flush()
Пример #10
0
def get_or_create_language(name):
    lang = DBSession.query(Language).filter_by(name=name).first()
    if not lang:
        lang = Language()
        lang.name = name
        DBSession.add(lang)
        DBSession.flush()
    return lang
Пример #11
0
def add_Achivement_Properties(request):

    achievementProperty = AchievementProperty()
    achievementProperty.name = request.POST["name"]
    DBSession.add(achievementProperty)
    DBSession.flush()

    return {"Achivement_Properties": "ok"}
Пример #12
0
def add_Variable(request):

    variable = Variable()
    variable.name = request.POST["variable_name"]
    variable.group = request.POST["variable_group"]
    DBSession.add(variable)
    DBSession.flush()

    return {"variable": "ok"}
Пример #13
0
    def test_verify_password(self):
        auth_user = AuthUser()
        auth_user.password = "******"
        auth_user.active = True
        auth_user.email = "*****@*****.**"
        DBSession.add(auth_user)

        iscorrect = auth_user.verify_password("test12345")

        self.assertEqual(iscorrect, True)
Пример #14
0
def create_achievement_user(user, achievement, achievement_date, level):
    achievement_user = AchievementSubject()
    achievement_user.user_id = user.id
    achievement_user.achievement_id = achievement.id
    achievement_user.achievement_date = achievement_date
    achievement_user.level = level
    DBSession.add(achievement_user)
    DBSession.flush()

    return achievement_user
Пример #15
0
    def test_get_reward_and_properties_for_achievement(self):

        user = create_user()

        achievement = create_achievement(
            achievement_name="invite_users_achievement",
            achievement_relevance="friends",
            achievement_maxlevel=3)

        achievementproperty = AchievementProperty()
        achievementproperty.name = "xp"
        DBSession.add(achievementproperty)
        DBSession.flush()

        achievements_achievementproperty = AchievementAchievementProperty()
        achievements_achievementproperty.achievement_id = achievement.id
        achievements_achievementproperty.property_id = achievementproperty.id
        achievements_achievementproperty.value = "5"
        achievements_achievementproperty.from_level = None
        DBSession.add(achievements_achievementproperty)
        DBSession.flush()

        create_achievement_rewards(achievement=achievement)

        achievement_date = Achievement.get_datetime_for_evaluation_type(
            achievement.evaluation_timezone, achievement.evaluation)

        create_achievement_user(user=user,
                                achievement=achievement,
                                achievement_date=achievement_date,
                                level=1)

        create_variable("invite_users", "none")
        Value.increase_value(variable_name="invite_users",
                             user=user,
                             value=4,
                             key="5",
                             at_datetime=achievement_date)

        create_goals(
            achievement=achievement,
            goal_condition=
            """{"term": {"type": "literal", "variable": "invite_users"}}""",
            goal_group_by_key=True,
            goal_operator="geq",
            goal_goal="1*level")

        clear_all_caches()
        result = Achievement.evaluate(user, achievement.id, achievement_date)
        print("reward_achievement_result:", result)

        self.assertEqual(len(result["new_levels"]["2"]["rewards"]), 0)
        self.assertEqual(len(result["new_levels"]["3"]["rewards"]), 1)
        self.assertEqual(len(result["new_levels"]["2"]["properties"]), 1)
        self.assertEqual(len(result["new_levels"]["3"]["properties"]), 1)
Пример #16
0
def create_variable(
    variable_name=undefined,
    variable_group=undefined,
):
    variable = Variable()
    variable.name = variable_name
    variable.group = variable_group
    DBSession.add(variable)
    DBSession.flush()

    return variable
Пример #17
0
    def test_create_token(self):
        user = create_user()
        auth_user = AuthUser()
        auth_user.user_id = user.id
        auth_user.password = "******"
        auth_user.active = True
        auth_user.email = "*****@*****.**"
        DBSession.add(auth_user)

        if auth_user.verify_password("test12345"):
            token = auth_user.get_or_create_token()

        self.assertNotEqual(token, None)
Пример #18
0
def change_password(request):
    try:
        doc = request.json_body
    except:
        raise APIError(400, "invalid_json", "no valid json body")

    email = doc.get("email")
    old_password = doc.get("old_password")
    new_password = doc.get("new_password")

    if not email or not old_password or not new_password:
        raise APIError(
            400,
            "change_password.email_and_old_password_and_new_password_required",
            "You need to send your email, the old password and a new password."
        )

    user = DBSession.query(AuthUser).filter_by(email=email).first()

    if not user or not user.verify_password(old_password):
        raise APIError(
            401, "change_password.email_or_old_password_invalid",
            "Either the email address or the old password is wrong.")

    if not user.active:
        raise APIError(400, "user_is_not_activated",
                       "Your user is not activated.")

    if new_password == old_password:
        raise APIError(400, "change_password.may_not_be_the_same",
                       "The new password may not be the same as the old one.")

    if not AuthUser.check_password_strength(new_password):
        raise APIError(
            400, "change_password.invalid_new_password",
            "The new password is too weak. Minimum length is 8 characters.")

    user.password = new_password
    user.force_password_change = False
    DBSession.add(user)

    token = AuthToken.generate_token()
    tokenObj = AuthToken(auth_user_id=user.id, token=token)
    DBSession.add(tokenObj)

    DBSession.flush()

    return {
        "token": token,
        "subject": Subject.full_output(user.subject_id),
    }
Пример #19
0
def create_achievement_rewards(achievement):
    reward = Reward()
    reward.name = "badge"
    DBSession.add(reward)
    DBSession.flush()

    achievement_reward = AchievementReward()
    achievement_reward.achievement_id = achievement.id
    achievement_reward.reward_id = reward.id
    achievement_reward.value = "https://www.gamification-software.com/img/trophy_{level1}.png"
    achievement_reward.from_level = achievement.maxlevel
    DBSession.add(achievement_reward)
    DBSession.flush()

    return achievement_reward
Пример #20
0
def create_value(
    user_id=undefined,
    variable_id=undefined,
    var_value=undefined,
    key="",
):

    value = Value()
    value.user_id = user_id
    value.variable_id = variable_id
    value.value = var_value
    value.key = key
    DBSession.add(value)
    DBSession.flush()

    return value
Пример #21
0
def create_user(DBSession, user, password):
    from gengine.app.model import (AuthUser, Subject, AuthRole,
                                   AuthRolePermission, SubjectType,
                                   t_auth_roles_permissions)
    with transaction.manager:
        subjecttype_user = DBSession.query(SubjectType).filter_by(
            name="User").first()
        if not subjecttype_user:
            subjecttype_user = SubjectType(name="User")
            DBSession.add(subjecttype_user)

        existing = DBSession.query(AuthUser).filter_by(email=user).first()
        DBSession.flush()
        if not existing:
            user1 = Subject(lat=10,
                            lng=50,
                            timezone="Europe/Berlin",
                            subjecttype_id=subjecttype_user.id)
            DBSession.add(user1)
            DBSession.flush()

            auth_user = AuthUser(subject=user1,
                                 email=user,
                                 password=password,
                                 active=True)
            DBSession.add(auth_user)

            auth_role = get_or_create_role(DBSession=DBSession,
                                           name="Global Admin")

            for perm in yield_all_perms():
                if not exists_by_expr(
                        t_auth_roles_permissions,
                        and_(
                            t_auth_roles_permissions.c.auth_role_id
                            == auth_role.id, t_auth_roles_permissions.c.name
                            == perm[0])):
                    DBSession.add(
                        AuthRolePermission(role=auth_role, name=perm[0]))

            auth_user.roles.append(auth_role)

            DBSession.add(auth_user)

            DBSession.flush()
Пример #22
0
def create_achievement(request, *args, **kw):
    context = request.context

    if not request.has_perm(perm_global_manage_achievements):
        raise APIError(403, "forbidden")

    try:
        name = request.validated_params.body.get("name", None)
        player_subjecttype_id = request.validated_params.body.get("player_subjecttype_id")
        context_subjecttype_id = request.validated_params.body.get("context_subjecttype_id")
        domain_subject_ids = request.validated_params.body.get("domain_subject_ids")
        condition = request.validated_params.body.get("condition")
        evaluation = request.validated_params.body.get("evaluation")
        evaluation_timezone = request.validated_params.body.get("evaluation_timezone")
        evaluation_shift = request.validated_params.body.get("evaluation_shift")
        valid_start = request.validated_params.body.get("valid_start")
        valid_end = request.validated_params.body.get("valid_end")
        comparison_type = request.validated_params.body.get("comparison_type")

        ach = Achievement(
            name = name,
            player_subjecttype_id = player_subjecttype_id,
            context_subjecttype_id = context_subjecttype_id,
            domain_subject_ids = domain_subject_ids,
            condition = json.dumps(condition),
            comparison_type = comparison_type,
            evaluation = evaluation,
            evaluation_timezone = evaluation_timezone,
            evaluation_shift = evaluation_shift,
            valid_start = valid_start,
            valid_end = valid_end,
        )

        DBSession.add(ach)
        DBSession.flush()

        return r_status.output({
            "status": "ok"
        })

    except:
        raise APIError(500, message="Error creating achievement")
Пример #23
0
def auth_login(request):
    try:
        doc = request.json_body
    except:
        raise APIError(400, "invalid_json", "no valid json body")

    user = request.user
    email = doc.get("email")
    password = doc.get("password")

    if user:
        #already logged in
        token = user.get_or_create_token().token
    else:
        if not email or not password:
            raise APIError(400, "login.email_and_password_required",
                           "You need to send your email and password.")

        user = DBSession.query(AuthUser).filter_by(email=email).first()

        if not user or not user.verify_password(password):
            raise APIError(
                401, "login.email_or_password_invalid",
                "Either the email address or the password is wrong.")

        if not user.active:
            raise APIError(400, "user_is_not_activated",
                           "Your user is not activated.")

        if user.force_password_change:
            raise APIError(400, "user_has_to_change_password",
                           "You have to change your password.")

        token = AuthToken.generate_token()
        tokenObj = AuthToken(auth_user_id=user.id, token=token)

        DBSession.add(tokenObj)

    return {
        "token": token,
        "subject": Subject.full_output(user.subject_id),
    }
Пример #24
0
def create_subjecttypes():
    subjecttype_country = SubjectType(name="Country")
    DBSession.add(subjecttype_country)

    subjecttype_city = SubjectType(name="City")
    subjecttype_city.part_of_types.append(subjecttype_country)
    DBSession.add(subjecttype_city)

    subjecttype_position = SubjectType(name="Position")
    DBSession.add(subjecttype_position)

    subjecttype_team = SubjectType(name="Team")
    subjecttype_team.part_of_types.append(subjecttype_city)
    DBSession.add(subjecttype_team)

    subjecttype_user = SubjectType(name="User")
    subjecttype_user.part_of_types.append(subjecttype_city)
    subjecttype_user.part_of_types.append(subjecttype_team)
    subjecttype_user.part_of_types.append(subjecttype_position)
    DBSession.add(subjecttype_team)
    DBSession.flush()
Пример #25
0
def create_goal_properties(goal_id):

    goal_property = GoalProperty()
    goal_property.name = "participate"
    goal_property.is_variable = True
    DBSession.add(goal_property)
    DBSession.flush()

    translation_variable = TranslationVariable()
    translation_variable.name = "invite_users_goal_name"
    DBSession.add(translation_variable)
    DBSession.flush()

    goals_goal_property = GoalGoalProperty()
    goals_goal_property.goal_id = goal_id
    goals_goal_property.property_id = goal_property.id
    goals_goal_property.value = "7"
    goals_goal_property.value_translation_id = translation_variable.id
    goals_goal_property.from_level = 2
    DBSession.add(goals_goal_property)
    DBSession.flush()

    goals_goal_property_result = DBSession.execute(
        t_goals_goalproperties.select().where(
            t_goals_goalproperties.c.goal_id == goal_id)).fetchone()

    return goals_goal_property_result
Пример #26
0
def create_subject(
    name,
    type,
    lat=None,
    lng=None,
    timezone=None,
    language=None,
    additional_public_data={},
):

    type_obj = DBSession.query(SubjectType).filter_by(name=type).first()
    language_obj = get_or_create_language(name=language) if language else None

    subject = Subject()
    subject.name = name
    subject.lat = lat
    subject.lng = lng
    subject.timezone = timezone
    subject.language = language_obj
    subject.additional_public_data = additional_public_data
    subject.type = type_obj
    DBSession.add(subject)
    return subject
Пример #27
0
 def add_translation(variable, lang, text):
     tr = Translation(translationvariable=variable, text=text, language=lang)
     DBSession.add(tr)
     return tr
Пример #28
0
 def add_translation_variable(name):
     t = TranslationVariable(name=name)
     DBSession.add(t)
     return t
Пример #29
0
def populate_demo(DBSession):
    from gengine.app.model import (
        Achievement,
        AchievementCategory,
        Variable,
        Subject,
        Language,
        TranslationVariable,
        Translation,
        Reward,
        AchievementProperty,
        AchievementAchievementProperty,
        AchievementReward,
        AuthUser,
        AuthRole,
        AuthRolePermission,
        SubjectType,
        t_auth_roles_permissions
    )

    def add_translation_variable(name):
        t = TranslationVariable(name=name)
        DBSession.add(t)
        return t

    def add_translation(variable, lang, text):
        tr = Translation(translationvariable=variable, text=text, language=lang)
        DBSession.add(tr)
        return tr

    with transaction.manager:
        subjecttype_country = SubjectType(name="Country")
        DBSession.add(subjecttype_country)

        subjecttype_region = SubjectType(name="Region")
        subjecttype_region.part_of_types.append(subjecttype_country)
        DBSession.add(subjecttype_region)

        subjecttype_city = SubjectType(name="City")
        subjecttype_city.part_of_types.append(subjecttype_region)
        DBSession.add(subjecttype_city)

        subjecttype_position = SubjectType(name="Position")
        DBSession.add(subjecttype_position)

        subjecttype_team = SubjectType(name="Team")
        DBSession.add(subjecttype_team)

        subjecttype_user = DBSession.query(SubjectType).filter_by(name="User").first()
        if not subjecttype_user:
            subjecttype_user = SubjectType(name="User")
            DBSession.add(subjecttype_user)
        subjecttype_user.part_of_types.append(subjecttype_city)
        subjecttype_user.part_of_types.append(subjecttype_team)
        subjecttype_user.part_of_types.append(subjecttype_position)
        DBSession.add(subjecttype_user)

        subject_germany = Subject(type=subjecttype_country, name="Germany")
        DBSession.add(subject_germany)
        subject_france = Subject(type=subjecttype_country, name="France")
        DBSession.add(subject_france)
        subject_india = Subject(type=subjecttype_country, name="India")
        DBSession.add(subject_india)

        subject_germany_north = Subject(type=subjecttype_region, name="Germany-North")
        DBSession.add(subject_germany_north)
        subject_germany_west = Subject(type=subjecttype_region, name="Germany-West")
        DBSession.add(subject_germany_west)
        subject_germany_east = Subject(type=subjecttype_region, name="Germany-East")
        DBSession.add(subject_germany_east)
        subject_germany_south = Subject(type=subjecttype_region, name="Germany-South")
        DBSession.add(subject_germany_south)

        subject_paderborn = Subject(type=subjecttype_city, name="Paderborn")
        DBSession.add(subject_paderborn)
        subject_bielefeld = Subject(type=subjecttype_city, name="Bielefeld")
        DBSession.add(subject_bielefeld)
        subject_detmold = Subject(type=subjecttype_city, name="Detmold")
        DBSession.add(subject_detmold)
        subject_berlin = Subject(type=subjecttype_city, name="Berlin")
        DBSession.add(subject_berlin)

        subject_sales = Subject(type=subjecttype_team, name="Sales")
        DBSession.add(subject_sales)

        subject_tech = Subject(type=subjecttype_team, name="Tech")
        DBSession.add(subject_tech)

        subject_junior_developer = Subject(type=subjecttype_position, name="Junior Developer")
        DBSession.add(subject_junior_developer)

        subject_senior_developer = Subject(type=subjecttype_position, name="Senior Developer")
        DBSession.add(subject_senior_developer)

        subject_manager = Subject(type=subjecttype_position, name="Manager")
        DBSession.add(subject_manager)

        subject_promoter = Subject(type=subjecttype_position, name="Promoter")
        DBSession.add(subject_promoter)
        DBSession.flush()

        lang_de = Language(name="de")
        lang_en = Language(name="en")
        DBSession.add(lang_de)
        DBSession.add(lang_en)

        var_invited_users = Variable(name="invite_users")
        DBSession.add(var_invited_users)

        var_invited_users = Variable(name="participate",
                                     group="none")
        DBSession.add(var_invited_users)

        achievementcategory_community = AchievementCategory(name="community")
        DBSession.add(achievementcategory_community)

        achievement_invite = Achievement(name='invite_users',
                                         evaluation="immediately",
                                         maxtimes=20,
                                         achievementcategory=achievementcategory_community,
                                         condition='{"term": {"type": "literal", "variable": "invite_users"}}',
                                         goal="5*level",
                                         operator="geq",
                                         player_subjecttype=subjecttype_user
                                         )
        DBSession.add(achievement_invite)

        achievementcategory_sports = AchievementCategory(name="sports")
        DBSession.add(achievementcategory_sports)

        achievement_fittest = Achievement(name='fittest',
                                          relevance="friends",
                                          maxlevel=100,
                                          achievementcategory=achievementcategory_sports,
                                          condition='{"term": {"key": ["5","7","9"], "type": "literal", "key_operator": "IN", "variable": "participate"}}',
                                          evaluation="weekly",
                                          goal="5*level",
                                          player_subjecttype=subjecttype_user
                                          )
        DBSession.add(achievement_fittest)

        property_name = AchievementProperty(name='name')
        DBSession.add(property_name)

        property_xp = AchievementProperty(name='xp')
        DBSession.add(property_xp)

        property_icon = AchievementProperty(name='icon')
        DBSession.add(property_icon)

        reward_badge = Reward(name='badge', rewarded_subjecttype=subjecttype_user)
        DBSession.add(reward_badge)

        reward_image = Reward(name='backgroud_image', rewarded_subjecttype=subjecttype_user)
        DBSession.add(reward_image)

        transvar_invite_name = add_translation_variable(name="invite_users_achievement_name")
        add_translation(transvar_invite_name, lang_en, 'Invite ${5*level} Users')
        add_translation(transvar_invite_name, lang_de, 'Lade ${5*level} Freunde ein')

        DBSession.add(AchievementAchievementProperty(achievement=achievement_invite, property=property_name,
                                                     value_translation=transvar_invite_name))
        DBSession.add(AchievementAchievementProperty(achievement=achievement_invite, property=property_xp,
                                                     value='${100 * level}'))
        DBSession.add(AchievementAchievementProperty(achievement=achievement_invite, property=property_icon,
                                                     value="https://www.gamification-software.com/img/running.png"))

        DBSession.add(AchievementReward(achievement=achievement_invite, reward=reward_badge,
                                        value="https://www.gamification-software.com/img/trophy.png", from_level=5))
        DBSession.add(AchievementReward(achievement=achievement_invite, reward=reward_image,
                                        value="https://www.gamification-software.com/img/video-controller-336657_1920.jpg",
                                        from_level=5))

        transvar_fittest_name = add_translation_variable(name="fittest_achievement_name")
        add_translation(transvar_fittest_name, lang_en, 'Do the most sport activities among your friends')
        add_translation(transvar_fittest_name, lang_de, 'Mache unter deinen Freunden am meisten Sportaktivitäten')

        DBSession.add(AchievementAchievementProperty(achievement=achievement_fittest, property=property_name,
                                                     value_translation=transvar_fittest_name))
        DBSession.add(AchievementAchievementProperty(achievement=achievement_fittest, property=property_xp,
                                                     value='${50 + (200 * level)}'))
        DBSession.add(AchievementAchievementProperty(achievement=achievement_fittest, property=property_icon,
                                                     value="https://www.gamification-software.com/img/colorwheel.png"))

        DBSession.add(AchievementReward(achievement=achievement_fittest, reward=reward_badge,
                                        value="https://www.gamification-software.com/img/easel.png", from_level=1))
        DBSession.add(AchievementReward(achievement=achievement_fittest, reward=reward_image,
                                        value="https://www.gamification-software.com/img/game-characters-622654.jpg",
                                        from_level=1))

        DBSession.flush()

        user1 = Subject(lat=10, lng=50, timezone="Europe/Berlin", name="Fritz", type=subjecttype_user)
        user2 = Subject(lat=10, lng=50, timezone="US/Eastern", name="Ludwig", type=subjecttype_user)
        user3 = Subject(lat=10, lng=50, name="Helene", type=subjecttype_user)

        user1.friends.append(user2)
        user1.friends.append(user3)

        user2.friends.append(user1)
        user2.friends.append(user3)

        user3.friends.append(user1)
        user3.friends.append(user2)

        user1.part_of_subjects.append(subject_bielefeld)
        user1.part_of_subjects.append(subject_sales)
        user1.part_of_subjects.append(subject_manager)

        user2.part_of_subjects.append(subject_bielefeld)
        user2.part_of_subjects.append(subject_sales)
        user2.part_of_subjects.append(subject_promoter)

        user3.part_of_subjects.append(subject_paderborn)
        user3.part_of_subjects.append(subject_sales)
        user3.part_of_subjects.append(subject_promoter)

        DBSession.add(user2)
        DBSession.add(user3)
        DBSession.flush()

        try:
            auth_user = DBSession.query(AuthUser).filter_by(email="*****@*****.**").first()

            if not auth_user:
                auth_user = AuthUser(subject=user1, email="*****@*****.**", password="******",
                                     active=True)
                DBSession.add(auth_user)

            auth_role = DBSession.query(AuthRole).filter_by(name="Global Admin").first()

            if not auth_role:
                auth_role = AuthRole(name="Global Admin")
                DBSession.add(auth_role)

            DBSession.flush()

            for perm in yield_all_perms():
                if not exists_by_expr(t_auth_roles_permissions, and_(
                        t_auth_roles_permissions.c.auth_role_id == auth_role.id,
                        t_auth_roles_permissions.c.name == perm[0]
                )):
                    DBSession.add(AuthRolePermission(role=auth_role, name=perm[0]))

            auth_user.roles.append(auth_role)
            DBSession.add(auth_user)
        except ImportError as e:
            print("[auth] feature not installed - not importing auth demo data")
Пример #30
0
def create_subjects():
    germany = create_subject(name="Germany", type="Country")
    DBSession.add(germany)

    france = create_subject(name="France", type="Country")
    DBSession.add(france)

    bielefeld = create_subject(name="Bielefeld", type="City")
    DBSession.add(bielefeld)
    DBSession.flush()
    Subject.join_subject(subject_id=bielefeld.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    paderborn = create_subject(name="Paderborn", type="City")
    DBSession.add(paderborn)
    DBSession.flush()
    Subject.join_subject(subject_id=paderborn.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    lyon = create_subject(name="Lyon", type="City")
    DBSession.add(lyon)
    DBSession.flush()
    Subject.join_subject(subject_id=lyon.id,
                         part_of_id=france.id,
                         join_date=default_dt())

    junior_developer = create_subject(name="Junior Developer", type="Position")
    DBSession.add(junior_developer)

    senior_developer = create_subject(name="Senior Developer", type="Position")
    DBSession.add(senior_developer)

    project_manager = create_subject(name="Project Manager", type="Position")
    DBSession.add(project_manager)

    dev_team_bielefeld = create_subject(name="Developer Team Bielefeld",
                                        type="Team")
    DBSession.add(dev_team_bielefeld)
    DBSession.flush()
    Subject.join_subject(subject_id=dev_team_bielefeld.id,
                         part_of_id=bielefeld.id,
                         join_date=default_dt())

    dev_team_paderborn = create_subject(name="Developer Team Paderborn",
                                        type="Team")
    DBSession.add(dev_team_paderborn)
    DBSession.flush()
    Subject.join_subject(subject_id=dev_team_paderborn.id,
                         part_of_id=paderborn.id,
                         join_date=default_dt())

    dev_team_lyon = create_subject(name="Developer Team Lyon", type="Team")
    DBSession.add(dev_team_lyon)
    DBSession.flush()
    Subject.join_subject(subject_id=dev_team_lyon.id,
                         part_of_id=lyon.id,
                         join_date=default_dt())

    klaus = create_subject(name="Klaus", type="User")
    DBSession.add(klaus)
    DBSession.flush()
    Subject.join_subject(subject_id=klaus.id,
                         part_of_id=bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=klaus.id,
                         part_of_id=junior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=klaus.id,
                         part_of_id=dev_team_bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=klaus.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    clara = create_subject(name="Clara", type="User")
    DBSession.add(clara)
    DBSession.flush()
    Subject.join_subject(subject_id=clara.id,
                         part_of_id=bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=clara.id,
                         part_of_id=junior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=clara.id,
                         part_of_id=dev_team_bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=clara.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    manfred = create_subject(name="Manfred", type="User")
    DBSession.add(manfred)
    DBSession.flush()
    Subject.join_subject(subject_id=manfred.id,
                         part_of_id=bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=manfred.id,
                         part_of_id=junior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=manfred.id,
                         part_of_id=dev_team_bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=manfred.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    otto = create_subject(name="Otto", type="User")
    DBSession.add(otto)
    DBSession.flush()
    Subject.join_subject(subject_id=otto.id,
                         part_of_id=bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=otto.id,
                         part_of_id=junior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=otto.id,
                         part_of_id=dev_team_bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=otto.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    max = create_subject(name="Max", type="User")
    DBSession.add(max)
    DBSession.flush()
    Subject.join_subject(subject_id=max.id,
                         part_of_id=bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=max.id,
                         part_of_id=senior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=max.id,
                         part_of_id=dev_team_bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=max.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    ronny = create_subject(name="Ronny", type="User")
    DBSession.add(ronny)
    DBSession.flush()
    Subject.join_subject(subject_id=ronny.id,
                         part_of_id=bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=ronny.id,
                         part_of_id=senior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=ronny.id,
                         part_of_id=dev_team_bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=ronny.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    sonja = create_subject(name="Sonja", type="User")
    DBSession.add(sonja)
    DBSession.flush()
    Subject.join_subject(subject_id=sonja.id,
                         part_of_id=bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=sonja.id,
                         part_of_id=project_manager.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=sonja.id,
                         part_of_id=dev_team_bielefeld.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=sonja.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    #Paderborn

    liam = create_subject(name="Liam", type="User")
    DBSession.add(liam)
    DBSession.flush()
    Subject.join_subject(subject_id=liam.id,
                         part_of_id=paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=liam.id,
                         part_of_id=junior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=liam.id,
                         part_of_id=dev_team_paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=liam.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    tim = create_subject(name="Tim", type="User")
    DBSession.add(tim)
    DBSession.flush()
    Subject.join_subject(subject_id=tim.id,
                         part_of_id=paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=tim.id,
                         part_of_id=junior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=tim.id,
                         part_of_id=dev_team_paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=tim.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    robin = create_subject(name="Robin", type="User")
    DBSession.add(robin)
    DBSession.flush()
    Subject.join_subject(subject_id=robin.id,
                         part_of_id=paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=robin.id,
                         part_of_id=junior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=robin.id,
                         part_of_id=dev_team_paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=robin.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    alina = create_subject(name="Alina", type="User")
    DBSession.add(alina)
    DBSession.flush()
    Subject.join_subject(subject_id=alina.id,
                         part_of_id=paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=alina.id,
                         part_of_id=junior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=alina.id,
                         part_of_id=dev_team_paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=alina.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    charlotte = create_subject(name="Charlotte", type="User")
    DBSession.add(charlotte)
    DBSession.flush()
    Subject.join_subject(subject_id=charlotte.id,
                         part_of_id=paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=charlotte.id,
                         part_of_id=senior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=charlotte.id,
                         part_of_id=dev_team_paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=charlotte.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    ida = create_subject(name="Ida", type="User")
    DBSession.add(ida)
    DBSession.flush()
    Subject.join_subject(subject_id=ida.id,
                         part_of_id=paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=ida.id,
                         part_of_id=senior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=ida.id,
                         part_of_id=dev_team_paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=ida.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    carolin = create_subject(name="Carolin", type="User")
    DBSession.add(carolin)
    DBSession.flush()
    Subject.join_subject(subject_id=carolin.id,
                         part_of_id=paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=carolin.id,
                         part_of_id=project_manager.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=carolin.id,
                         part_of_id=dev_team_paderborn.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=carolin.id,
                         part_of_id=germany.id,
                         join_date=default_dt())

    #Lyon

    lola = create_subject(name="Lola", type="User")
    DBSession.add(lola)
    DBSession.flush()
    Subject.join_subject(subject_id=lola.id,
                         part_of_id=lyon.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=lola.id,
                         part_of_id=junior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=lola.id,
                         part_of_id=dev_team_lyon.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=lola.id,
                         part_of_id=france.id,
                         join_date=default_dt())

    lina = create_subject(name="Lina", type="User")
    DBSession.add(lina)
    DBSession.flush()
    Subject.join_subject(subject_id=lina.id,
                         part_of_id=lyon.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=lina.id,
                         part_of_id=senior_developer.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=lina.id,
                         part_of_id=dev_team_lyon.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=lina.id,
                         part_of_id=france.id,
                         join_date=default_dt())

    ethan = create_subject(name="Ethan", type="User")
    DBSession.add(ethan)
    DBSession.flush()
    Subject.join_subject(subject_id=ethan.id,
                         part_of_id=lyon.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=ethan.id,
                         part_of_id=project_manager.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=ethan.id,
                         part_of_id=dev_team_lyon.id,
                         join_date=default_dt())
    Subject.join_subject(subject_id=ethan.id,
                         part_of_id=france.id,
                         join_date=default_dt())