Example #1
0
def init():
    try:
        print "create tables"
        metadata.drop_all(engine, checkfirst = True)
        metadata.create_all(engine)

        print "insert default value"
        DBSession.add(User(name = 'demo', password = '******'))

        for code in range(9121, 9140):
            DBSession.add(NFCData(authcode = unicode(code), company = 'RoyalDragonVodka',
                                  serial = code - 9000,
                                  ))
        f = open('country.txt', 'r')
        cs = f.readlines()
        f.close()
        for c in cs:
            n, c, iso = c.split('|')
            DBSession.add(MLocation(name = n, iso_code = iso, code = c))

        DBSession.commit()
        print "finish init!"
    except:
        traceback.print_exc()
        DBSession.rollback()
Example #2
0
def init():
    try:
        print "create tables"
        metadata.drop_all(engine, checkfirst = True)
        metadata.create_all(engine)

        DBSession.add(User(email = '*****@*****.**', password = '******'))
        DBSession.add(User(email = '*****@*****.**', password = '******'))
        DBSession.commit()

        print "finish init!"
    except:
        traceback.print_exc()
        DBSession.rollback()
Example #3
0
def init():
    try:
        print "create tables"
        metadata.drop_all(engine, checkfirst = True)

        metadata.create_all(engine)

        print "insert default value"
        #add the default value here

        uAdmin = User(name = 'admin', email = '*****@*****.**', password = '******')
#        uKinlong = User(name = u'kinlong', email = '*****@*****.**', password = '******')
#        uWeiqian = User(name = u'weiqian', email = '*****@*****.**', password = '******')
        uKefua = User(name = u'kefu1', email = '*****@*****.**', password = '******')
        uWha = User(name = u'wh1', email = '*****@*****.**', password = '******')
        uFina = User(name = u'fin1', email = '*****@*****.**', password = '******')
        uUser1 = User(name = u'罗凌云', email = '*****@*****.**', password = '******')
        uUser2 = User(name = u'陈龙', email = '*****@*****.**', password = '******')
#        uUser3 = User(name = u'邓二', email = '*****@*****.**', password = '******')
        uUser4 = User(name = u'刘坤', email = '*****@*****.**', password = '******')
        uUser5 = User(name = u'何灿明', email = '*****@*****.**', password = '******')
#        uUser6 = User(name = u'黄燕琴', email = '*****@*****.**', password = '******')
        uUser7 = User(name = u'吴丽玲', email = '*****@*****.**', password = '******')
        uUser8 = User(name = u'徐腾芳', email = '*****@*****.**', password = '******')
        uUser9 = User(name = u'黄霄莹', email = '*****@*****.**', password = '******')
        uUser10 = User(name = u'林凤', email = '*****@*****.**', password = '******')
#        uUser11 = User(name = u'吴秋梅', email = '*****@*****.**', password = '******')
        uUser12 = User(name = u'林秀贤', email = '*****@*****.**', password = '******')
        uUser13 = User(name = u'曾德莲', email = '*****@*****.**', password = '******')
        uUser14 = User(name = u'李时坚', email = '*****@*****.**', password = '******')

        uUser15 = User(name = u'深福合力', email = '*****@*****.**', password = '******')


        pAdminManage = Permission(name = 'AMIN_MANAGE', desc = u'进入管理员控制台')
        pCreateUser = Permission(name = 'CREATE_USER', desc = u'创建新用户')
        pUpdateUser = Permission(name = 'UPDATE_USER', desc = u'更新用户信息')
        pDeleteUser = Permission(name = 'DELETE_USER', desc = u'删除用户')
        pSearchUser = Permission(name = 'SEARCH_USER', desc = u'查询用户')
        pManageUser = Permission(name = 'MANAGE_USER', desc = u'管理所有用户')
        pCreateGroup = Permission(name = 'CREATE_GROUP', desc = u'删除组')
        pUpdateGroup = Permission(name = 'UPDATE_GROUP', desc = u'更新组信息')
        pDeleteGroup = Permission(name = 'DELETE_GROUP', desc = u'删除组')
        pSearchGroup = Permission(name = 'SEARCH_GROUP', desc = u'查询所在组')
        pManageGroup = Permission(name = 'MANAGE_GROUP', desc = u'管理所有组')
        pCreatePermission = Permission(name = 'CREATE_PERMISSION', desc = u'创建新权限')
        pUpdatePermission = Permission(name = 'UPDATE_PERMISSION', desc = u'更新权限')
        pDeletePermission = Permission(name = 'DELETE_PERMISSION', desc = u'删除权限')
        pSearchPermission = Permission(name = 'SEARCH_PERMISSION', desc = u'查询所在权限')
        pManagePermission = Permission(name = 'MANAGE_PERMISSION', desc = u'管理所在权限')
        pCreateMaster = Permission(name = 'CREATE_MASTER', desc = u'创建新的系统设置')
        pUpdateMaster = Permission(name = 'UPDATE_MASTER', desc = u'更新现有的系统设置')
        pDeleteMaster = Permission(name = 'DELETE_MASTER', desc = u'删除系统设置')
        pSearchMaster = Permission(name = 'SEARCH_MASTER', desc = u'查询所有的系统设置')
        pManageMaster = Permission(name = 'MANAGE_MASTER', desc = u'进入系统设置控制台')
        pCreateOrder = Permission(name = 'CREATE_ORDER', desc = u'创建新的订单')
        pUpdateOrder = Permission(name = 'UPDATE_ORDER', desc = u'更新订单信息')
        pDeleteOrder = Permission(name = 'DELETE_ORDER', desc = u'删除订单')
        pSearchOrder = Permission(name = 'SEARCH_ORDER', desc = u'查询订单')
        pManageOrder = Permission(name = 'MANAGE_ORDER', desc = u'管理所有的订单')
        pSearchAllOrder = Permission(name = 'SEARCH_ALL_ORDER', desc = u'查询所有的订单')
        pCreateDeliver = Permission(name = 'CREATE_DELIVER', desc = u'创建新的送货单')
        pUpdateDeliver = Permission(name = 'UPDATE_DELIVER', desc = u'更新送货单信息')
        pDeleteDeliver = Permission(name = 'DELETE_DELIVER', desc = u'删除送货单信息')
        pSearchDeliver = Permission(name = 'SEARCH_DELIVER', desc = u'查询所在的送货单')
        pManageDeliver = Permission(name = 'MANAGE_DELIVER', desc = u'进入送货单管理控制台')
        pSearchAllDeliver = Permission(name = 'SEARCH_ALL_ELIVER', desc = u'查询所有的送货单')
        pCreateCustomer = Permission(name = 'CREATE_CUSTOMER', desc = u'创建新的客户')
        pUpdateCustomer = Permission(name = 'UPDATE_CUSTOMER', desc = u'更新客户信息')
        pDeleteCustomer = Permission(name = 'DELETE_CUSTOMER', desc = u'删除客户')
        pSearchCustomer = Permission(name = 'SEARCH_CUSTOMER', desc = u'查询所有的客户')
        pCreateSupplier = Permission(name = 'CREATE_SUPPLIER', desc = u'创建新的承运商')
        pUpdateSupplier = Permission(name = 'UPDATE_SUPPLIER', desc = u'更新承运商信息')
        pDeleteSupplier = Permission(name = 'DELETE_SUPPLIER', desc = u'删除承运商信息')
        pSearchSupplier = Permission(name = 'SEARCH_SUPPLIER', desc = u'查询所有的承运商信息')
        pCreateWarehouse = Permission(name = 'CREATE_WAREHOUSE', desc = u'创建新的仓存地点')
        pUpdateWarehouse = Permission(name = 'UPDATE_WAREHOUSE', desc = u'更新仓存地点信息')
        pDeleteWarehouse = Permission(name = 'DELETE_WAREHOUSE', desc = u'删除仓存地点')
        pSearchWarehouse = Permission(name = 'SEARCH_WAREHOUSE', desc = u'查询所有仓存地点')
        pManageFin = Permission(name = 'MANAGE_FIN', desc = u'进入财务管理控制台')
        pFinSearch = Permission(name = 'FIN_SEARCH', desc = u'查询订单信息')
        pFinApprove = Permission(name = 'FIN_APPROVE', desc = u'审核通过订单信息')
        pFinPaid = Permission(name = 'FIN_PAID', desc = u'确认客户是否已付款')
        pFinSupplierPaid = Permission(name = 'FIN_SUPPLIER_PAID', desc = u'确认是否已付款予承运商')



        gAdmin = Group(name = u'管理员组', display_name = u'管理员组', type = 0)
        gAdmin.permissions = [pAdminManage, pCreateUser, pUpdateUser, pDeleteUser, pSearchUser, pManageUser,
                              pCreateGroup, pUpdateGroup, pDeleteGroup, pSearchGroup, pManageGroup,
                              pCreatePermission, pUpdatePermission, pDeletePermission, pSearchPermission, pManagePermission,
                              pCreateMaster, pUpdateMaster, pDeleteMaster, pSearchMaster, pManageMaster,
                              pCreateOrder, pUpdateOrder, pDeleteOrder, pSearchOrder, pSearchAllOrder, pManageOrder,
                              pCreateDeliver, pUpdateDeliver, pDeleteDeliver, pSearchDeliver, pSearchAllDeliver, pManageDeliver,
                              pCreateCustomer, pUpdateCustomer, pDeleteCustomer, pSearchCustomer,
                              pCreateSupplier, pUpdateSupplier, pDeleteSupplier, pSearchSupplier,
                              pCreateWarehouse, pUpdateWarehouse, pDeleteWarehouse, pSearchWarehouse,
                              pManageFin, pFinSearch, pFinApprove, pFinPaid, pFinSupplierPaid
                              ]
        gAdmin.users = [uAdmin, ]
        gCustomer = Group(name = u'客户组', display_name = u'客户组', type = 0)
        gCustomer.permissions = [pCreateOrder, pUpdateOrder, pDeleteOrder, pSearchOrder, ]

        gKinlongGroup = Group(name = 'KINLONG_GROUP', display_name = 'KINLONG GROUP', type = 1)

        gWeiqianGroup = Group(name = 'WEIQIAN_GROUP', display_name = 'WEIQIAN GROUP', type = 1)

        gOfficer = Group(name = u'客服组', display_name = u'客服组', type = 0)
        gOfficer.permissions = [
                                pCreateMaster, pUpdateMaster, pDeleteMaster, pSearchMaster, pManageMaster,
                                pCreateOrder, pUpdateOrder, pDeleteOrder, pSearchOrder, pSearchAllOrder, pManageOrder,
                                pCreateDeliver, pUpdateDeliver, pDeleteDeliver, pSearchDeliver, pManageDeliver, pSearchAllDeliver,
                                ]
        gOfficer.users = [uKefua, uUser7, uUser9, uUser10, uUser13 ]

        gFin = Group(name = u'财务组', display_name = u'财务组', type = 0)
        gFin.permissions = [
                              pCreateMaster, pUpdateMaster, pDeleteMaster, pSearchMaster, pManageMaster,
                              pCreateOrder, pUpdateOrder, pDeleteOrder, pSearchOrder, pSearchAllOrder, pManageOrder,
                              pCreateDeliver, pUpdateDeliver, pDeleteDeliver, pSearchDeliver, pSearchAllDeliver, pManageDeliver,
                              pCreateCustomer, pUpdateCustomer, pDeleteCustomer, pSearchCustomer,
                              pCreateSupplier, pUpdateSupplier, pDeleteSupplier, pSearchSupplier,
                              pCreateWarehouse, pUpdateWarehouse, pDeleteWarehouse, pSearchWarehouse,
                              pManageFin, pFinSearch, pFinApprove, pFinPaid, pFinSupplierPaid
                            ]
        gFin.users = [uFina, uUser1, uUser2, uUser4, uUser5, uUser12, uUser15]

        gSupplier = Group(name = u'承运商组', display_name = u'承运商组', type = 0)
        gSupplier.permissions = [pUpdateDeliver, pSearchDeliver ]
#        gSupplier.users = [uSupplier]

        gSupplier1 = Group(name = 'SUPPLIER_1', display_name = 'Supplier1', type = 1)
#        gSupplier1.users = [uSupplier]
        gWarehouse = Group(name = u'仓库组', display_name = u'仓库组', type = 0)
        gWarehouse.permissions = [pUpdateOrder, pSearchOrder, pSearchAllOrder, pManageOrder,
                                  pCreateDeliver, pUpdateDeliver, pSearchDeliver, pSearchAllDeliver, pManageDeliver ]
        gWarehouse.users = [uWha, uUser8, uUser14]


        DBSession.add_all([
                            uAdmin, uKefua, uFina, uWha,
#                            uKefu2, uSupplier, uWarehouse,
                            uUser1, uUser2, uUser4, uUser5, uUser7, uUser8, uUser9, uUser10, uUser12, uUser13, uUser14, uUser15,
                            pCreateUser, pUpdateUser, pDeleteUser, pSearchUser, pManageUser,
                            pCreateGroup, pUpdateGroup, pDeleteGroup, pSearchGroup, pManageGroup,
                            pCreatePermission, pUpdatePermission, pDeletePermission, pSearchPermission, pManagePermission,
                            pCreateMaster, pUpdateMaster, pDeleteMaster, pSearchMaster, pManageMaster,
                            pCreateOrder, pUpdateOrder, pDeleteOrder, pSearchOrder, pSearchAllOrder, pManageOrder,
                            pCreateDeliver, pUpdateDeliver, pDeleteDeliver, pSearchDeliver, pSearchAllDeliver, pManageDeliver,
                            pCreateCustomer, pUpdateCustomer, pDeleteCustomer, pSearchCustomer,
                            pCreateSupplier, pUpdateSupplier, pDeleteSupplier, pSearchSupplier,
                            pCreateWarehouse, pUpdateWarehouse, pDeleteWarehouse, pSearchWarehouse,
                            gAdmin, gCustomer, gOfficer, gSupplier, gWarehouse,
                            gKinlongGroup, gWeiqianGroup,
                            ])


        for n, en, tn in [(u'米', u'meter', u'米'), (u'分米', u'dm', u'分米'), (u'厘米', u'cm', u'釐米'), (u'吨', u'ton', u'噸'), (u'千克', u'kg', u'千克'), (u'克', u'g', u'克'),
                     (u'箱', u'box', u'箱'), (u'瓶', u'bottle', u'瓶'), (u'只', u'pic', u'只'), (u'打', u'dozen', u'打'), ]:
            DBSession.add(ItemUnit(name = n, english_name = en, tradition_name = tn))


        for n, en, tn in [(u'吨', u'ton', u'噸'), (u'千克', u'kg', u'千克'), (u'克', u'g', u'克'), ]:
            DBSession.add(WeightUnit(name = n, english_name = en, tradition_name = tn))

#        location1 = InventoryLocation(name = u"深圳仓库", address = u"仓库地址 1", manager = "李先生", full_path = u"深圳仓库")
#        location1_A = InventoryLocation(name = u"A区", address = u"仓库地址 1", manager = "李先生", full_path = u"A区", parent = location1)
#        location1_B = InventoryLocation(name = u"B区", address = u"仓库地址 1", manager = "李先生", full_path = u"B区", parent = location1)
#        location1_C = InventoryLocation(name = u"C区", address = u"仓库地址 1", manager = "李先生", full_path = u"C区", parent = location1)
#        location2 = InventoryLocation(name = u"东莞仓库", address = u"仓库地址 2", manager = "林先生", full_path = u"东莞仓库")
#        location2_A = InventoryLocation(name = u"A区", address = u"仓库地址 2", manager = "林先生", full_path = u"A区", parent = location2)
#        location2_B = InventoryLocation(name = u"B区", address = u"仓库地址 2", manager = "林先生", full_path = u"B区", parent = location2)
#        location2_C = InventoryLocation(name = u"C区", address = u"仓库地址 2", manager = "林先生", full_path = u"C区", parent = location2)
#
#        DBSession.add_all([location1, location1_A, location1_B, location1_C,
#                           location2, location2_A, location2_B, location2_C,
#                           ])
#        location1.full_path_ids = location1.id
#        location2.full_path_ids = location2.id

        DBSession.flush()

        DBSession.add(ShipmentType(name = u"陆运"))
#        DBSession.add(ShipmentType(name = u"水运"))
#        DBSession.add(ShipmentType(name = u"空运"))

        payment1 = Payment(name = u"月付")
        payment2 = Payment(name = u"到付")
        payment3 = Payment(name = u"现付")
        DBSession.add_all([payment1, payment2, payment3])

        DBSession.add(Ratio(type = "QTY", value = 10))
        DBSession.add(Ratio(type = "VOL", value = 0.33))
        DBSession.add(Ratio(type = "WEIGHT", value = 0.5))

        DBSession.add(PickupType(name = u"自提"))
        DBSession.add(PickupType(name = u"送货"))
        DBSession.add(PickupType(name = u"司机直送"))
        DBSession.add(PickupType(name = u"送货上门"))
        DBSession.add(PickupType(name = u"送货上楼"))

        DBSession.add(PackType(name = u"纸箱"))
        DBSession.add(PackType(name = u"袋装"))
        DBSession.add(PackType(name = u"桶装"))
        DBSession.add(PackType(name = u"林架"))

        DBSession.add(Item(name = u"五金"))
        DBSession.add(Item(name = u"食品"))
        DBSession.add(Item(name = u"器材"))
        DBSession.add(Item(name = u"木料"))
        DBSession.add(Item(name = u"器具"))
        DBSession.add(Item(name = u"家具"))

        print 'insert diqu'
        province_f = open('sys2do/sql/master_province.sql')
        province_sql = "".join(province_f.readlines())
        province_f.close()

        city_f = open('sys2do/sql/master_city.sql')
        city_sql = "".join(city_f.readlines())
        city_f.close()

        conn = DBSession.connection()
        conn.execute(province_sql)
        conn.execute(city_sql)

        DBSession.commit()


        receiver1 = Receiver(code = u'粤BIP092', name = u'黄司机', tel = None, mobile = '15976884544',)
        receiver2 = Receiver(code = u'粤BQ4225', name = '叶司机', tel = None, mobile = '13682553458',)
        receiver3 = Receiver(code = u'粤BJU706', name = u'张司机', tel = None, mobile = '15813808186',)
        receiver4 = Receiver(code = u'粤BJX667', name = u'李司机', tel = None, mobile = '13590435287',)
        receiver5 = Receiver(code = u'粤BPY286', name = u'杨司机', tel = None, mobile = '13554881765',)
        receiver6 = Receiver(code = u'粤BVQ582', name = u'杨司机', tel = None, mobile = '13724255912',)
        receiver7 = Receiver(code = u'粤B2X846', name = u'巍司机', tel = None, mobile = '13410189026',)

        DBSession.add_all([receiver1, receiver2, receiver3, receiver4, receiver5, receiver6, receiver7])

        note1 = Note(code = '0001191-1', name = u'坚朗', province_id = 19, city_id = 290, apply_person_id = 1, apply_time = '2012-08-23',
                     begin_no = '1188000', end_no = '1188599', remark = u'坚朗专用二本')

        note2 = Note(code = '1001191-1', name = u'味千', province_id = 19, city_id = 290, apply_person_id = 1, apply_time = '2012-08-23',
                     begin_no = '2188000', end_no = '2188599', remark = u'味千专用一本')

        DBSession.add_all([
                           note1,
                           ])



        kinlong = Customer(name = u"广东坚朗五金制品股份有限公司", display_name = u'坚朗', province_id = 19, city_id = 304,
                           address = u"塘厦镇大坪村工业区卢地坑路3号", phone = "0769-82166666", contact_person = u'陈先生',
                           mobile = '12800138999', note = note1)

        kinlong_source1 = CustomerSource(customer = kinlong, name = u"坚朗一厂", province_id = 19, city_id = 304, payment = payment1)  #东莞
        kinlong_source2 = CustomerSource(customer = kinlong, name = u"坚朗二厂", province_id = 19, city_id = 304, payment = payment1)  #东莞
        kinlong_source3 = CustomerSource(customer = kinlong, name = u"坚朗三厂", province_id = 19, city_id = 304, payment = payment1)  #东莞


        DBSession.add_all([
                           kinlong, kinlong_source1, kinlong_source2, kinlong_source3,
                           ])

        DBSession.flush()


        kinlong_source1_c1 = CustomerContact(customer = kinlong, type = 'S', refer_id = kinlong_source1.id, name = u'李小明', mobile = u'13880138111', phone = u'1234561', address = u'厚街', is_default = 1)
        kinlong_source1_c2 = CustomerContact(customer = kinlong, type = 'S', refer_id = kinlong_source1.id, name = u'张三', mobile = u'13880138112', phone = u'1234562', address = u'长安',)

        kinlong_source2_c1 = CustomerContact(customer = kinlong, type = 'S', refer_id = kinlong_source2.id, name = u'王二', mobile = u'13880138113', phone = u'1234563', address = u'常平',)
        kinlong_source2_c2 = CustomerContact(customer = kinlong, type = 'S', refer_id = kinlong_source2.id, name = u'王小川', mobile = u'13880138114', phone = u'1234563', address = u'虎门',)

        kinlong_source3_c2 = CustomerContact(customer = kinlong, type = 'S', refer_id = kinlong_source3.id, name = u'钟远', mobile = u'13880138116', phone = u'1234563', address = u'大岭山',)

        DBSession.add_all([
                           kinlong_source1_c1, kinlong_source1_c2, kinlong_source2_c1, kinlong_source2_c2, kinlong_source3_c2,
                           ])

        #import the kinlong target contact
        import_kinlong_target(kinlong)
        #import the supplier
        import_supplier(payment1)


        weiqian = Customer(name = u"味千(中国)控投有限公司", display_name = u'味千', province_id = 19, city_id = 290,
                           address = u"福田区金田路3037号金中环商务大厦主楼23号", phone = "0755-8280 5333", contact_person = None,
                           mobile = None, note = note2)

        weiqian_source1 = CustomerSource(customer = weiqian, name = u"味千一厂", province_id = 19, city_id = 290, payment = payment1)

        DBSession.add_all([
                           weiqian, weiqian_source1
                           ])

        DBSession.flush()

        weiqian_source1_c1 = CustomerContact(customer = weiqian, type = 'S', refer_id = weiqian_source1.id, name = u'陆先生', mobile = u'13880138111', phone = u'1234561', address = u'福田', is_default = 1)
        DBSession.add_all([
                           weiqian_source1_c1,
                           ])

        import_weiqian_targets(weiqian)

        DBSession.commit()
        print "finish init!"
    except:
        traceback.print_exc()
        DBSession.rollback()
Example #4
0
def init():
    try:
        metadata.drop_all(engine)
        metadata.create_all(engine)

        #add the HK holiday 
        for d in ["0102", "0123", "0124", "012", "0404", "0406", "0407", "0409", "0428",
              "0501", "0623", "0702", "1001", "1002", "1023", "1225", "1226"]:
            DBSession.add(Holiday(year = 2012, month = d[:2], day = d[2:], region = 'HK'))

        permissions = ["ORDER_ADD", "ORDER_VIEW", "ORDER_CANCEL", "ORDER_UPDATE", "ORDER_VIEW_ALL",
                   "CLINIC_ADD", "CLINIC_VIEW", "CLINIC_VIEW_ALL", "CLINIC_UPDATE", "CLINIC_DELETE",
                   "DOCTOR_ADD", "DOCTOR_UPDATE", "DOCTOR_DELETE",
                   "NURSE_ADD", "NURSE_UPDATE", "NURSER_DELETE",
                   ]
        permissions_mapping = {}
        for p in permissions:
            obj = Permission(name = p)
            DBSession.add(obj)
            permissions_mapping[p] = obj

        groups = [
                 ("ADMINISTRATOR", "Administrator"), ("CLINIC_MANAGER", "Clinic Manager"),
                 ("DOCTOR", "Doctor"), ("NURSE", "Nurse"),
                 ("NORMALUSER", "Normal User"), ("TEMPUSER", "Temp User")
                 ]
        group_mapping = {}
        for g in groups:
            obj = Group(name = g[0], display_name = g[1])
            DBSession.add(obj)
            group_mapping[g[0]] = obj


        users = [
             ("*****@*****.**", "Admin",),
             ("*****@*****.**", "Clinic Manager 1",),
             ("*****@*****.**", "Clinic Manager 2",),
             ("*****@*****.**", "User 1"),
             ("*****@*****.**", "User 2"),
             ]

        users_mapping = {}
        for u in users:
            obj = User(email = u[0], password = '******', display_name = u[1])
            DBSession.add(obj)
            users_mapping[u[0]] = obj

        group_mapping['ADMINISTRATOR'].permissions = permissions_mapping.values()
        group_mapping['ADMINISTRATOR'].users = [users_mapping['*****@*****.**'], ]
        group_mapping['CLINIC_MANAGER'].permissions = [
                                                   permissions_mapping["CLINIC_VIEW"],
                                                   permissions_mapping["CLINIC_UPDATE"],
                                                   permissions_mapping["DOCTOR_ADD"],
                                                   permissions_mapping["DOCTOR_UPDATE"],
                                                   permissions_mapping["DOCTOR_DELETE"],
                                                   permissions_mapping["NURSE_ADD"],
                                                   permissions_mapping["NURSE_UPDATE"],
                                                   permissions_mapping["NURSER_DELETE"],
                                                   permissions_mapping["ORDER_VIEW"],
                                                   permissions_mapping["ORDER_CANCEL"],
                                                   permissions_mapping["ORDER_UPDATE"],
                                                   ]
        group_mapping['CLINIC_MANAGER'].users = [users_mapping['*****@*****.**'], users_mapping['*****@*****.**'], ]
        group_mapping['DOCTOR'].permissions = [
                                               permissions_mapping["ORDER_VIEW"],
                                               permissions_mapping["ORDER_CANCEL"],
                                               permissions_mapping["ORDER_UPDATE"],
                                               ]
        group_mapping['NURSE'].permissions = [
                                               permissions_mapping["ORDER_VIEW"],
                                               permissions_mapping["ORDER_CANCEL"],
                                               permissions_mapping["ORDER_UPDATE"],
                                              ]

        group_mapping['NORMALUSER'].permissions = [
                                               permissions_mapping["ORDER_ADD"],
                                               permissions_mapping["ORDER_VIEW"],
                                               permissions_mapping["ORDER_CANCEL"],
                                               ]
        group_mapping['NORMALUSER'].uses = [users_mapping['*****@*****.**'], users_mapping['*****@*****.**'], ]


        from clinic_list import clinics
        clinics_mapping = {}
        for (code, name, address, address_tc, tel, area_id, coordinate) in clinics:
            obj = Clinic(code = unicode(code.strip()), name = unicode(name.strip()),
                         address = unicode(address.strip()), address_tc = unicode(address_tc.strip()),
                         tel = unicode(tel.strip()), area_id = area_id or None,
                         coordinate = coordinate.strip()
                         )
            DBSession.add(obj)
            clinics_mapping[code] = obj



        default_worktime = {
                          "MONDAY" : [ ],
                          "TUESDAY" : [],
                          "WEDNESDAY" : [],
                          "THURSDAY" : [],
                          "FRIDAY" : [],
                          "SATURDAY" : [],
                          "SUNDAY" : [],
                          "HOLIDAY" : [],
                          "SPECIAL" : [],
                          }


        from doctors_list import doctors
        doctors_count = {}
        for (code, first_name, last_name, worktime) in doctors:

            if code in doctors_count : doctors_count[code] += 1
            else : doctors_count[code] = 1

            email = u"*****@*****.**" % (code, doctors_count[code])

            obj = User(email = email, password = u'aa', display_name = email)
            obj.groups = [group_mapping['DOCTOR']]
            DBSession.add(obj)
            DBSession.flush()

            tempWorkTime = default_worktime.copy()
            tempWorkTime.update(worktime)
            wt = {}
            for k, v in tempWorkTime.items():
                wt[k] = map(lambda o:{"times" : o, "seats" : 4}, v)

            objprofile = DoctorProfile(user_id = obj.id, worktime_setting = wt)
            if code in clinics_mapping : objprofile.clinics = [clinics_mapping[code]]
            DBSession.add(objprofile)

        area = {
            ('香港島', 'Hong Kong') : [('上環', 'Sheung Wan'), '大坑', '山頂', ('中環', 'Central') , '蘇豪', '蘭桂坊', ('天后', 'Tin Hau'), ('太古', 'Tai Koo'), ('北角', 'North Point'), '半山', '石澳', ('西環', 'Sai Wan'), '赤柱', '金鐘', ('柴灣', 'Chai Wan'), ('灣仔', 'Wan Chai') , ('西灣河', 'Sai Wan Ho'), ('杏花村', 'Heng Fa Chuen'), '香港仔', '淺水灣', '深水灣', ('跑馬地', 'Happy Valley'), ('筲箕灣', 'Shau Kei Wan'), ('銅鑼灣', 'Causeway Bay') , ('鴨脷洲', 'Ap Lei Chau'), '薄扶林', '數碼港', ('鰂魚涌', 'Quarry Bay')],
            ('九龍', 'Kowloon') : [('太子', 'Prince Edward'), ('佐敦', 'Jordan'), ('旺角', 'Mong Kok'), '油塘', ('紅磡', 'Hung Hom'), ('美孚', 'Mei Foo'), ('彩虹', 'Choi Hung'), ('樂富', 'Lok Fu'), ('藍田', 'Lam Tin'), ('觀塘', 'Kwun Tong'), ('九龍城', 'Kowloon City'), '九龍塘', ('九龍灣', 'Kowloon Bay'), ('土瓜灣', 'To Kwa Wan'), ('大角咀', 'Tai Kok Tsui'), ('牛頭角', 'Ngau Tau Kok'), ('石硤尾', 'Shek Kip Mei'), ('尖沙咀', 'Tsim Sha Tsui'), '諾士佛臺', ('何文田', 'Ho Man Tin'), ('油麻地', 'Yau Ma Tei'), ('長沙灣', 'Cheung Sha Wan'), ('荔枝角', 'Lai Chi Kok'), ('深水埗', 'Sham Shui Po'), ('黃大仙', 'Wong Tai Sin'), ('慈雲山', 'Tsz Wan Shan'), ('新蒲崗', 'San Po Kong'), ('鯉魚門', 'Lei Yue Mun'), ('鑽石山', 'Diamond Hill')],
            ('新界', 'New Territories') : [('上水', 'Sheung Shui'), ('大埔', 'Tai Po'), ('大圍', 'Tai Wai'), ('元朗', 'Yuen Long'), ('太和', 'Tai Wo'), ('屯門', 'Tuen Mun'), '火炭', ('西貢', 'Sai Kung'), ('沙田', 'Sha Tin'), ('青衣', 'Tsing Yi'), ('粉嶺', 'Fanling'), ('荃灣', 'Tsuen Wan'), '馬灣', ('深井', 'Sham Tseng'), ('葵芳', 'Kwai Fong'), ('葵涌', 'Kwai Chung'), '羅湖', ('天水圍', 'Tin Shui Wai'), '流浮山', ('馬鞍山', 'Ma On Shan'), ('將軍澳', 'Tseung Kwan O'), '落馬洲'],
            ('離島', 'Outlying Islands') : ['大澳', '坪洲', ('東涌', 'Tung Chung'), '長洲', '大嶼山', ('赤鱲角', 'Chek Lap Kok'), '南丫島', '愉景灣', '蒲苔島'],
        }

        for k, v in area.items():
            dis = District(name = unicode(k[1]), name_tc = unicode(k[0]))
            DBSession.add(dis)
            for d in v :
                if type(d) == tuple:
                    DBSession.add(Area(name = unicode(d[0]), name_tc = unicode(d[1]), district = dis))
                else:
                    DBSession.add(Area(name = unicode(d), district = dis))




        DBSession.commit()
    except:
        traceback.print_exc()
        DBSession.rollback()