def get_not_recommended_count_by_shop(shop): try: return UserShopRelationMethods.get_by_shop(shop).filter( is_recommended=UserShopRelationMethods.NOT_RECOMMENDED).count() except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return 0
def get_user_image(user): result = dict() if user: if user.userextension.big_image: user_image = files.BASE_URL_4_IMAGE + user.userextension.big_image.name # Logs.print_log("user_image", user_image) else: if user.userextension.gender == "M": user_image = USER_DEFAULT_MALE_ICON else: user_image = USER_DEFAULT_FEMALE_ICON else: user_image = USER_DEFAULT_ICON memory_file = files.Files.get_memory_file(user_image) user_image_path = "/".join(user_image.split("/")[:-1]) user_image_name = user_image.split("/")[-1] big_user_image_name = ".".join(user_image_name.split(".")[:-1]) + "_big." + user_image_name.split(".")[-1] small_user_image_name = ".".join(user_image_name.split(".")[:-1]) + "_small." + user_image_name.split(".")[-1] big_user_image = user_image_path + "/" + big_user_image_name small_user_image = user_image_path + "/" + small_user_image_name try: Images.resize_image(memory_file, big_user_image, 240) Images.resize_image(memory_file, small_user_image, 96) result["big_user_image"] = big_user_image result["small_user_image"] = small_user_image except Exception as ex: Logs.print_current_function_name_and_line_number(ex) if user.userextension.gender == "M": result["big_user_image"] = USER_DEFAULT_MALE_ICON result["small_user_image"] = USER_DEFAULT_MALE_ICON else: result["big_user_image"] = USER_DEFAULT_FEMALE_ICON result["small_user_image"] = USER_DEFAULT_FEMALE_ICON return result
def get_attribute_by_user_and_publish(user_id, publish_id): try: upr = UserPublishRelations.objects.get(user_id=user_id, publish_id=publish_id) return upr.attribute except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return -1
def to_utc(dt): try: dt = Datetimes.transfer_datetime(dt, is_utc=False) return dt.replace(tzinfo=utc) except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def set_node_text(node, text): try: node.text = text return node except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def get_memory_file(url): try: # Logs.print_log("get memory file url", url) return cStringIO.StringIO(urllib2.urlopen(url, data=None, timeout=10).read()) except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def get_file_content(path): try: f = open(path, "r") return f.read() except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def get_publishes_by_device(device_id): try: publishes = Publish.objects.filter(device_id=device_id) return publishes except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def get(name): try: # Logs.print_log("name", name) return Company.objects.get(name=name) except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def get_info(red_envelope): try: result = Objects.get_object_info(red_envelope) return result except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return dict()
def set_node_attribute(node, attribute_key, attribute_value): try: node.set(attribute_key, attribute_value) return node except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def get_user_extension(username): try: u = UserExtension.objects.get(user__username=username) return u except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return Users.get_none()
def get_user_by_id(user_id): try: u = User.objects.get(id=user_id) return u except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return Users.get_none()
def get_category_id(name): try: category = ShopCategory.objects.get(name=name) return category.id except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return 0
def get_file_name(url): try: names = url.split("/") return names[-1] except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def get_articles(user_id, status): try: ufs = UserForumArticle.objects.filter(user_id=user_id, status=status, count__gt=0) return ufs except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return UserForumArticleMethod.get_none()
def set_shop_has_detector(shop, has_detector): try: shop.has_detector = has_detector shop.save() return shop except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return Shops.get_none()
def activate_detector_relation(detector_relation): try: detector_relation.state = True detector_relation.save() return detector_relation except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def get_count_by_user(user_id, status): try: ufs = UserForumArticle.objects.filter(user_id=user_id, status=status) counts = [o.count for o in ufs] return reduce(operator.add, counts, 0) except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return 0
def update(user_forum_article, increment=1): try: user_forum_article.count += increment user_forum_article.save() return user_forum_article except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return UserForumArticleMethod.get_none()
def add(user_id, article_id, status): try: ufa = UserForumArticle(user_id=user_id, article_id=article_id, status=status) ufa.save() return ufa except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return UserForumArticleMethod.get_none()
def update_unread(comment): try: comment.is_read = True comment.save() return True except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return False
def create_directory_path(path): if not Files.exists(path): try: Files.makedirs(path) except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None return path
def update_shop(shop, shop_dict): try: for (key, value) in shop_dict.items(): Objects.set_value(shop, key, value) shop.save() return shop except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return Shops.get_none()
def get(username, start_datetime, end_datetime): try: start_datetime = Datetimes.string_to_utc(start_datetime) end_datetime = Datetimes.string_to_utc(end_datetime) return Game.objects.filter(username=username, created_at__gte=start_datetime, created_at__lte=end_datetime).order_by("id") except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def save_image(memory_file, path): data = {} try: img = Image.open(memory_file) img.save(path) return True except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return False
def update(publish, publish_dict): try: for (key, value) in publish_dict.items(): Objects.set_value(publish, key, value) publish.save() return publish except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return None
def static_update(address, address_dict): try: for (key, value) in address_dict.items(): Objects.set_value(address, key, value) address.save() return address except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return Address.get_none()
def get_some_node_text(node, node_name): try: some_node = Xmls.get_the_first_node(node, node_name) if some_node is not None: return Xmls.get_node_text(some_node) else: return "" except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return ""
def reset(address): try: if not isinstance(address, Address): raise ValueError("object in addresses must be an Address!") address.audit = 1 address.save() return address except Exception as ex: Logs.print_current_function_name_and_line_number(ex) return Addresses.get_none()