OSDN Git Service

revise amulet search to consider of seed1 value,
[amulettoolsmh4/main.git] / model / amuletskillsholder.py
1 # -*- coding: utf-8 -*-
2
3 # お守りのスキル保持用クラス
4 # 2013/12/09 written by kei9 
5
6 import db_supports
7
8 class AmuletSkillsHolder(object):
9     u""" お守りのスキルを保持するクラス """
10     def __init__(self, skill_id_list):
11         u""" skill_id_list: list of skill id
12             if skill is unknown, element must be None
13         """
14         self.skill_id_list = list(skill_id_list)
15
16     def is_empty(self):
17         u""" すべての要素がNoneのときTrueを返す """
18         if all([x is None for x in self.skill_id_list]):
19             return True
20         else:
21             return False
22
23     def get_where_and_sql(self, remove_where=False):
24         u""" SQLのWhere文に変換する(AND結合) """
25         if any([x is not None for x in self.skill_id_list]):
26             valid_eqls = []
27             for col, skill_id in zip(db_supports.SEED2_SKILL2_COL_SKILL2_LIST, self.skill_id_list):
28                 if skill_id is not None:
29                     valid_eqls.append(u"{col}={skill_id}".format(col=col,skill_id=skill_id)) 
30             if remove_where:
31                 return u" and ".join(valid_eqls)
32             else:
33                 return u" where " + u" and ".join(valid_eqls)
34         else:
35             return ""
36
37     def get_where_in_sql(self, remove_where=False):
38         u""" SQLのWhere文に変換する(IN結合) """
39         if len(self.skill_id_list) >= 1:
40             uni_list = [u"{0}".format(x) for x in self.skill_id_list if x is not None]
41             sql = u" {col} IN({in_phrase})".format(
42                     col=db_supports.MIN_MAX_COL_SKILL_ID,
43                     in_phrase=u",".join(uni_list))
44
45             if remove_where:
46                 return sql
47             else:
48                 return u" where" + sql
49         else:
50             return ""
51