Пример #1
0
 def get_from_auth_id(auth_id):
     entity = UserRepository().get_from_auth_id(auth_id)
     if entity is None:
         return None
     return obj_map(entity, UserViewModel, rules={
                                                  'photos':lambda e: map(lambda f:obj_map(f, UploadFileViewModel), e.uploadFiles)
                                                  })
Пример #2
0
 def get(self, entity_id):
     entity = self._repository.get(entity_id)
     if entity is None:
         return None
     return obj_map(entity, UserViewModel, rules={
                                                  'photos':lambda e: map(lambda f:obj_map(f, UploadFileViewModel), e.uploadFiles)
                                                  })
Пример #3
0
 def list(self, param=None):
     if (not param):
         param = CategoryQueryViewModel()
     else:
         param = CategoryQueryViewModel(param)
     if (param.listFlat):
         param.includeChildren = True
     param.user_id = self._context.user_id
     entities = self._repository.list(param)
     result = []
     mapper = {}
     mapper[Category] = CategoryViewMode
     if param.includeChildren:
         if param.listFlat:
             temp = []
             self.__class__.to_flat(entities, temp)
             for r in temp:
                 r.children = []
                 result.append(obj_map(r, CategoryViewMode, mapper=mapper))
         else:
             for e in entities:
                 result.append(obj_map(e, CategoryViewMode, mapper=mapper))
     else:
         for e in entities:
             e.children = []
             result.append(obj_map(e, CategoryViewMode))
     return result
Пример #4
0
 def save(self, viewModel):
     mapper={CommodityDetailViewModel: CommodityDetail}
     entity = obj_map(viewModel, Commodity, mapper=mapper)
     if entity.user_id > 0 and (not self.is_accessable(entity)):
         return
     entity.user_id = self._context.user_id
     return self._repository.save(entity)
Пример #5
0
 def save(self, viewModel):
     mapper = {}
     mapper[type(viewModel)] = Category
     if viewModel.children is not None:
         c = []
         for v in viewModel.children:
             c.append(CategoryViewMode(v))
         viewModel.children = c
     entity = obj_map(viewModel, Category, mapper=mapper)
     olds = self._repository.list(CategoryQueryViewModel({'includeChildren':True, 'categoryId':viewModel.id}))
     for o in olds:
         isFound = False
         for e in entity.children:
             if o.id == e.id:
                 isFound = True
                 break
         if not isFound:
             self._repository.delete(o.id)
     children = []
     for c in entity.children:
         children.append(c)
     result = []
     for e in children:
         e.parent_category_id = entity.id
         e.parent = None
         e.user_id = self._context.user_id
         result.append(self._repository.save(e))
     return result
Пример #6
0
 def list(self, param = None):
     if (not param):
         param = BrandQueryModel()
     param.user_id = self._context.user_id
     entities = self._repository.list(param)
     return map(lambda e: obj_map(e, BrandViewModel, rules={
                                                                'photos':lambda e: map(lambda f:UploadFileViewModel({'id':f.id}), e.uploadFiles),
                                                                }), entities)
Пример #7
0
 def get(self, entity_id):
     entity = self._repository.get(entity_id)
     if (entity is None) or (not self.is_accessable(entity)):
         return None
     
     mapper = {
               CommodityCustomField:CommodityCustomFieldViewModel
               }
     return obj_map(entity, CommodityMetaViewModel, mapper = mapper)
Пример #8
0
 def save(self, viewModel):
     mapper = {
               CommodityCustomFieldViewModel:CommodityCustomField
               }
     viewModel.fields = map(lambda v:CommodityCustomFieldViewModel(v), viewModel.fields)
     entity = obj_map(viewModel, CommodityMeta, mapper = mapper)
     if (entity.user_id > 0 and (not self.is_accessable(entity))):
         return
     entity.user_id = self._context.user_id
     return self._repository.save(entity)
Пример #9
0
 def list(self, param = None):
     if (not param):
         param = CommodityQueryModel()
     param.user_id = self._context.user_id
     entities = self._repository.list(param)
     return map(lambda e: obj_map(e, CommodityViewModel, rules={
                                                                'discount_price':lambda e:e.base_price,
                                                                'brand_name': lambda e:None if e.brand is None else e.brand.name,
                                                                'photos':None,
                                                                'details':None
                                                                }), entities)
Пример #10
0
 def list(self, param = None):
     if (not param):
         param = CommodityMetaQueryModel()
     param.user_id = self._context.user_id
     entities = self._repository.list(param)
     result = []
     map(lambda e:result.append(obj_map(e, CommodityMetaViewModel, 
                                                  mapper={
                                                          CommodityCustomField:CommodityCustomFieldViewModel
                                                          })),entities)
     return result
Пример #11
0
 def get(self, entity_id):
     mapper={CommodityDetail: CommodityDetailViewModel}
     entity = self._repository.get(entity_id)
     if entity is None or (not self.is_accessable(entity)):
         return None
     return obj_map(entity, CommodityViewModel, rules={
                                                       'discount_price':lambda e:e.base_price,
                                                       'brand_name': lambda e:None if e.brand is None else e.brand.name,
                                                       'photos':lambda e: map(lambda f:UploadFileViewModel({'id':f.file_id}), e.uploadFiles),
                                                       'field_name':lambda e:e.field.field_name,
                                                       'field_type':lambda e:e.field.field_type,
                                                       'node':lambda e:e.field.note
                                                       }, mapper=mapper)
Пример #12
0
 def save(self, viewModel):
     entity = obj_map(viewModel, UploadFile)
     if self._context is not None:
         entity.user_id = self._context.user_id
     return self._repository.save(entity)
Пример #13
0
 def get(self, entity_id):
     entity = self._repository.get(entity_id)
     if (entity is None) or (not self.is_accessable(entity)):
         return None
     return obj_map(entity, CategoryViewMode)
Пример #14
0
 def get(self, user_id):
     entity = self._repository.get(user_id)
     if entity is None:
         return None
     return obj_map(entity, OAuthApplicationViewModel)
Пример #15
0
 def list(self, param = None):
     if (param == None):
         param = DiscountQueryViewModel(start_date=datetime.today())
     param.user_id = self._context.user_id
     entities = self._repository.list(param)
     return map(lambda e:obj_map(e, DiscountViewModel), entities)
Пример #16
0
 def save(self, viewModel):
     entity = obj_map(viewModel, User)
     self._repository.save(entity)
Пример #17
0
 def save(self, viewModel):
     entity = obj_map(viewModel, Brand)
     if (entity.user_id > 0 and (not self.is_accessable(entity))):
         return
     return self._repository.save(entity)
Пример #18
0
 def get(self, entity_id):
     entity = self._repository.get(entity_id)
     if (entity is None or (not self.is_accessable(entity))):
         return None
     return obj_map(entity, UploadFileViewModel)