Пример #1
0
def mock_mentions(times_to_mock=5):
    for _ in range(times_to_mock):
        m = Mention()
        m.alert_id = _gen_uuid()
        m.url = "http://unifide.sg"
        m.title = loremipsum.sentence(max_char=choice(range(20, 30)))
        m.summary = loremipsum.sentence(max_char=choice(range(20, 30)))
        m.keyword = _gen_uuid()
        Mention.collection().save(m.serialize())
Пример #2
0
def generate_token(user_obj, account_activity):
    """
    Generates a lasting token for a specific account activity.
    (EG: Email verification of a new account)

    Removes an existing if it already exists, and then replace
    it with a new one that this will generate.
    """
    user_obj.tokens[account_activity] = _gen_uuid()
    user_obj.save()
    return user_obj.tokens[account_activity]
Пример #3
0
    def __init__(self, **kwargs):
        super(Comment, self).__init__()

        self._id = _gen_uuid()
        self.user_id = None
        self.comment = None
        self.obj_id = None
        self.coll_name = None

        for k, v in kwargs.iteritems():
            setattr(self, k, v)
Пример #4
0
    def __init__(self, **kwargs):
        self._id = _gen_uuid()
        self.username = None
        self.first_name = ""
        self.middle_name = ""
        self.last_name = ""
        self.email = None
        self.address = None
        self.passwd_hash = None

        #facebook oauth
        self.fb_id = None
        self.gender = None
        self.link = None

        #account meta
        self.groups = []
        self.account_status = None
        self.tokens = {}

        for k, v in kwargs.iteritems():
            setattr(self, k, v)
Пример #5
0
def save_image(image_stream, storage=None):
    if storage is None:
        storage = MediaStorage.LOCAL

    #store locally first
    filename = _gen_uuid()
    file_path = _store_locally(filename, image_stream)


    #get pil img obj
    pil_img = PILImage.open(file_path)
    width, height = pil_img.size

    #save document record
    img_obj = _new_img_obj(filename, height, storage, width)

    if storage == MediaStorage.S3:
        t = multiprocessing.Process(target=_defer_store_s3, args=(file_path, filename, img_obj))
        t.daemon = False
        t.start()

    return img_obj
Пример #6
0
def save_media(media_stream, storage=None):
    if storage is None:
        storage = MediaStorage.LOCAL

    #store locally first
    filename = _gen_uuid()
    file_path = _store_locally(filename, media_stream)

    #save document record (as local first)
    media_obj = Media()
    media_obj.file_name = filename
    media_obj.storage = MediaStorage.LOCAL
    media_obj.file_type = MediaType.OTHERS
    media_obj._id = save(media_obj)

    #upload to s3, deferred/threaded
    if storage == MediaStorage.S3:
        t = multiprocessing.Process(target=_defer_store_s3, args=(file_path, filename, media_obj))
        t.daemon = False
        t.start()

    return media_obj
Пример #7
0
    def __init__(self, **kwargs):
        super(Order, self).__init__()

        self._id = _gen_uuid()
        self.user_id = None
        self.status = None
        self.items = [] # {obj_id: None, quantity:None}
        self.shipping_rule_id = None
        self.ship_to_address = None
        self.request_notes = None
        self.admin_notes = None
        self.admin_id = None

        #extra stuff like taxes, shipping, discounts, etc
        self.debits = [] # {obj_id: None, coll_name: None, amount=None}
        self.credits = [] # {obj_id: None, coll_name: None, amount=None}

        #convenience attr
        self.nett_total = 0

        for k, v in kwargs.iteritems():
            setattr(self, k, v)
Пример #8
0
def __resize(img_obj, new_height, new_width, resized_obj):
    #download + resize
    filename = _gen_uuid()
    temp_file_path = os.path.join(UPLOAD_FOLDER, filename)
    urllib.urlretrieve(url_for(img_obj), temp_file_path)
    img = PILImage.open(temp_file_path)
    img = _resize_img(_rotate_upright(img), new_width, new_height)
    img.save(temp_file_path, "JPEG")

    #upload
    f = open(temp_file_path, 'r')
    if img_obj.storage == MediaStorage.S3:
        _store_s3(filename, f)
    f.close()

    #create obj
    resized_obj = _new_img_obj(filename, new_height, img_obj.storage, new_width)

    #cleanup
    if img_obj.storage != MediaStorage.LOCAL:
        os.remove(temp_file_path)

    return resized_obj