Exemple #1
0
    def send_commons_to_contact(self, client, contact, now, date):
        '''
        Send pictures from last month to given contact.
        '''
        commons = CommonManager.get_owner_last_commons(
                startKey=date_util.get_db_date_from_date(now),
                endKey=date_util.get_db_date_from_date(date))

        for common in commons:
            if tags_match(common, contact):
                body = common.toJson(localized=False)

                client.post(contact, COMMON_PATH, body, self.onContactResponse)
Exemple #2
0
    def send_posts_to_contact(self, client, contact, now, date):
        '''
        Send microposts from last month to given contact.
        '''

        microposts = MicroPostManager.get_mine(
                startKey=date_util.get_db_date_from_date(now), 
                endKey=date_util.get_db_date_from_date(date))

        for micropost in microposts:
            body = micropost.toJson(localized=False)

            client.post(contact, MICROPOST_PATH, body, self.onContactResponse)
Exemple #3
0
    def send_posts_to_contact(self, client, contact, now, date):
        '''
        Send microposts from last month to given contact.
        '''
        microposts = MicroPostManager.get_mine(
                startKey=date_util.get_db_date_from_date(now),
                endKey=date_util.get_db_date_from_date(date))

        for micropost in microposts:
            if tags_match(micropost, contact):
                body = micropost.toJson(localized=False)

                client.post(contact, MICROPOST_PATH, body,
                            self.onContactResponse)
Exemple #4
0
    def send_pictures_to_contact(self, client, contact, now, date):
        '''
        Send pictures from last month to given contact.
        '''

        pictures = PictureManager.get_owner_last_pictures(
                startKey=date_util.get_db_date_from_date(now), 
                endKey=date_util.get_db_date_from_date(date))

        for picture in pictures:
            client.post_files(contact, PICTURE_PATH, 
                    { "json": str(picture.toJson(localized=False)) },
                    [("picture", str(picture.path), 
                            picture.fetch_attachment("th_" + picture.path))]
                    , self.onContactResponse)
Exemple #5
0
    def post(self, postId):
        """
        Grab from contact the file corresponding to given path and given post
        (post of which ID is equal to *postId*).
        """

        data = self.get_body_as_dict(expectedFields=["path"])

        micropost = MicroPostManager.get_micropost(postId)
        contact = ContactManager.getTrustedContact(micropost.authorKey)
        user = UserManager.getUser()
        if micropost and data and contact:
            path = data["path"]
            client = ContactClient()
            body = {"date": date_util.get_db_date_from_date(micropost.date), "contactKey": user.key, "path": path}

            client.post(
                contact, "microposts/contacts/attach/", json_encode(body), callback=(yield gen.Callback("getattach"))
            )
            response = yield gen.Wait("getattach")

            if response.error:
                self.return_failure("An error occured while retrieving picture.")
            else:
                micropost.put_attachment(response.body, data["path"])
                self.return_success("Download succeeds.")

        else:
            if not data:
                self.return_failure("Wrong data.", 400)
            elif not contact:
                self.return_failure("Contact no more available.", 400)
            else:
                self.return_failure("Micropost not found.", 404)
Exemple #6
0
def ensure_that_common_date_is_ok_with_time_zone(step):
    world.date_common = world.commons[0]

    common_db = CommonManager.get_common(world.date_common["_id"])
    date = date_util.convert_utc_date_to_timezone(common_db.date)
    date = date_util.get_db_date_from_date(date)

    assert world.date_common["date"] == date
Exemple #7
0
def ensure_that_common_date_is_ok_with_time_zone(step):
    world.date_common = world.commons[0]

    common_db = CommonManager.get_common(world.date_common["_id"])
    date = date_util.convert_utc_date_to_timezone(common_db.date)
    date = date_util.get_db_date_from_date(date)

    assert world.date_common["date"] == date
Exemple #8
0
def ensure_that_picture_date_is_ok_with_time_zone(step):
    world.date_picture = world.pictures[0]

    picture_db = PictureManager.get_picture(world.date_picture["_id"])
    date = date_util.convert_utc_date_to_timezone(picture_db.date)
    date = date_util.get_db_date_from_date(date)

    assert world.date_picture["date"] == date
Exemple #9
0
def ensure_that_picture_date_is_ok_with_time_zone(step):
    world.date_picture = world.pictures[0]

    picture_db = PictureManager.get_picture(world.date_picture["_id"])
    date = date_util.convert_utc_date_to_timezone(picture_db.date)
    date = date_util.get_db_date_from_date(date)

    assert world.date_picture["date"] == date
Exemple #10
0
def when_i_send_a_delete_retry_request(step):
    date = world.activity.errors[0]["extra"] 
    date = date_util.get_db_date_from_date(date)
    idsDict = { "contactId": world.contact.key, 
                "activityId" : world.activity._id,
                "extra": date }

    world.browser.put(world.picture.get_path() + "retry/",
                      json_encode(idsDict))
Exemple #11
0
def when_i_send_a_delete_retry_request(step):
    date = world.activity.errors[0]["extra"]
    date = date_util.get_db_date_from_date(date)
    idsDict = {"contactId": world.contact.key,
               "activityId": world.activity._id,
               "extra": date}

    world.browser.put(world.picture.get_path() + "retry/",
                      json_encode(idsDict))
Exemple #12
0
    def send_pictures_to_contact(self, client, contact, now, date):
        '''
        Send pictures from last month to given contact.
        '''
        pictures = PictureManager.get_owner_last_pictures(
                startKey=date_util.get_db_date_from_date(now),
                endKey=date_util.get_db_date_from_date(date))

        for picture in pictures:
            if tags_match(picture, contact):
                client.post_files(
                    contact,
                    PICTURE_PATH,
                    {"json": str(picture.toJson(localized=False))},
                    [("picture",
                      str(picture.path),
                      picture.fetch_attachment("th_" + picture.path))
                    ],
                    self.onContactResponse)
Exemple #13
0
def and_i_add_one_deletion_activity_for_first_common_with_one_error(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.common = CommonManager.get_last_commons().first()

    world.activity = Activity(author=author.name,
                              verb="deletes",
                              docType="common",
                              docId=world.common._id,
                              method="PUT")
    date = date_util.get_db_date_from_date(world.common.date)
    world.activity.add_error(world.contact, extra=date)
    world.activity.save()
Exemple #14
0
def and_add_one_deletion_activity_for_first_micropost_with_one_error(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.micropost = MicroPostManager.get_list().first()

    world.activity = Activity(author=author.name,
                              verb="deletes",
                              docType="micropost",
                              docId=world.micropost._id,
                              method="PUT")
    date = date_util.get_db_date_from_date(world.micropost.date)
    world.activity.add_error(world.contact, extra=date)
    world.activity.save()
Exemple #15
0
def and_add_one_deletion_activity_for_first_micropost_with_one_error(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.micropost = MicroPostManager.get_list().first()
    
    world.activity = Activity(
        author = author.name,
        verb = "deletes",
        docType = "micropost",
        docId = world.micropost._id,
        method = "PUT"
    )
    date = date_util.get_db_date_from_date(world.micropost.date)
    world.activity.add_error(world.contact, extra=date)
    world.activity.save()
Exemple #16
0
def and_i_add_one_deletion_activity_for_first_picture_with_one_error(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.picture = PictureManager.get_last_pictures().first()
    
    world.activity = Activity(
        author = author.name,
        verb = "deletes",
        docType = "picture",
        docId = world.picture._id,
        method = "PUT"
    )
    date = date_util.get_db_date_from_date(world.picture.date)
    world.activity.add_error(world.contact, extra=date)
    world.activity.save()
Exemple #17
0
    def toDict(self, localized=True):
        '''
        Return a dict representation of the document (copy).

        Removes _rev key and convert date field and last modified field
        to local timezone if *localized* is set to True.
        '''

        docDict = NewebeDocument.toDict(self, localized)

        if localized and "lastModified" in docDict:
            
            utc_date = get_date_from_db_date(docDict.get("lastModified"))
            date = convert_utc_date_to_timezone(utc_date)
            docDict["lastModified"] = get_db_date_from_date(date)

        return docDict
Exemple #18
0
    def toDict(self, localized=True):
        """
        Return a dict representation of the document (copy).

        Removes _rev key and convert date field and request date field
        to local timezone if *localized* is set to True.
        """

        docDict = NewebeDocument.toDict(self, localized)

        if localized and docDict.get("requestDate", ""):

            utc_date = date_util.get_date_from_db_date(docDict.get("requestDate"))
            date = date_util.convert_utc_date_to_timezone(utc_date)
            docDict["requestDate"] = date_util.get_db_date_from_date(date)

        return docDict
Exemple #19
0
    def toDict(self, localized=True):
        '''
        Return a dict representation of the document (copy).

        Removes _rev key and convert date field and last modified field
        to local timezone if *localized* is set to True.
        '''

        docDict = NewebeDocument.toDict(self, localized)

        if localized and "lastModified" in docDict:

            utc_date = get_date_from_db_date(docDict.get("lastModified"))
            date = convert_utc_date_to_timezone(utc_date)
            docDict["lastModified"] = get_db_date_from_date(date)

        return docDict
Exemple #20
0
    def toDict(self, localized=True):
        '''
        Return a dict representation of the document (copy).

        Removes _rev key.
        '''

        docDict = self.__dict__["_doc"].copy()

        if "_rev" in docDict:
            del docDict["_rev"]

        if localized and docDict.get("date", None):

            utc_date = get_date_from_db_date(docDict.get("date"))
            docDict["date"] = get_db_date_from_date(utc_date)

        return docDict
Exemple #21
0
    def toDict(self, localized=True):
        '''
        Return a dict representation of the document (copy).

        Removes _rev key and convert date field and request date field
        to local timezone if *localized* is set to True.
        '''

        docDict = NewebeDocument.toDict(self, localized)

        if localized and docDict.get("requestDate", ""):

            utc_date = date_util.get_date_from_db_date(
                docDict.get("requestDate"))
            date = date_util.convert_utc_date_to_timezone(utc_date)
            docDict["requestDate"] = date_util.get_db_date_from_date(date)

        return docDict
Exemple #22
0
    def send_deletion_to_contacts(self, path, doc):
        '''
        Send a delete request (PUT because Tornado don't handle DELETE request
        with a body) to all trusted contacts.

        Request body contains object to delete at JSON format.
        '''

        contacts = ContactManager.getTrustedContacts()
        client = ContactClient(self.activity)
        date = date_util.get_db_date_from_date(doc.date)

        for contact in contacts:
            try:
                client.delete(contact, path, doc.toJson(localized=False), date)
            except HTTPError:
                import pdb
                pdb.set_trace()
                self.activity.add_error(contact, extra=date)
                self.activity.save()
Exemple #23
0
    def toDict(self, localized=True):
        '''
        Return a dict representation of the document (copy).

        Removes _rev key and convert date field to local timezone
        if *localized* is set to True.
        '''

        docDict = self.__dict__["_doc"].copy()

        if "_rev" in docDict:
            del docDict["_rev"]

        if localized and docDict.get("date", None):

            utc_date = get_date_from_db_date(docDict.get("date"))
            date = convert_utc_date_to_timezone(utc_date)
            docDict["date"] = get_db_date_from_date(date)

        return docDict
Exemple #24
0
    def send_deletion_to_contacts(self, path, doc):
        '''
        Send a delete request (PUT because Tornado don't handle DELETE request
        with a body) to all trusted contacts.

        Request body contains object to delete at JSON format.
        '''

        contacts = ContactManager.getTrustedContacts()
        client = ContactClient(self.activity)
        date = date_util.get_db_date_from_date(doc.date)

        for contact in contacts:
            try:
                client.delete(contact, path, doc.toJson(localized=False), date)
            except HTTPError:
                import pdb
                pdb.set_trace()
                self.activity.add_error(contact, extra=date)
                self.activity.save()
Exemple #25
0
    def toDict(self, localized=True):
        '''
        Return a dict representation of the document (copy).

        Removes _rev key and convert date field to local timezone
        if *localized* is set to True.
        '''

        docDict = self.__dict__["_doc"].copy()

        if "_rev" in docDict:
            del docDict["_rev"]

        if localized and docDict.get("date", None):

            utc_date = get_date_from_db_date(docDict.get("date"))
            date = convert_utc_date_to_timezone(utc_date)
            docDict["date"] = get_db_date_from_date(date)

        return docDict
Exemple #26
0
    def post(self, postId):
        '''
        Grab from contact the file corresponding to given path and given post
        (post of which ID is equal to *postId*).
        '''

        data = self.get_body_as_dict(expectedFields=["path"])

        micropost = MicroPostManager.get_micropost(postId)
        contact = ContactManager.getTrustedContact(micropost.authorKey)
        user = UserManager.getUser()
        if micropost and data and contact:
            path = data["path"]
            client = ContactClient()
            body = {
                "date": date_util.get_db_date_from_date(micropost.date),
                "contactKey": user.key,
                "path": path
            }

            client.post(contact,
                        "microposts/contacts/attach/",
                        json_encode(body),
                        callback=(yield gen.Callback("getattach")))
            response = yield gen.Wait("getattach")

            if response.error:
                self.return_failure(
                    "An error occured while retrieving picture.")
            else:
                micropost.put_attachment(response.body, data["path"])
                self.return_success("Download succeeds.")

        else:
            if not data:
                self.return_failure("Wrong data.", 400)
            elif not contact:
                self.return_failure("Contact no more available.", 400)
            else:
                self.return_failure("Micropost not found.", 404)
Exemple #27
0
def when_i_get_first_from_its_date_and_author(step):
    common = world.commons[0]
    world.common = CommonManager.get_contact_common(
        common.authorKey, date_util.get_db_date_from_date(common.date))
Exemple #28
0
def when_i_get_first_from_its_date_and_author(step):
    picture = world.pictures[0]
    world.picture = PictureManager.get_contact_picture(picture.authorKey,
                                date_util.get_db_date_from_date(picture.date))
Exemple #29
0
import sys

sys.path.append("../")
from newebe.news.models import MicroPostManager
from newebe.lib.date_util import get_db_date_from_date
from newebe.lib.indexer import Indexer

indexer = Indexer()

print "indexation starts...."

# Fill index with posts from DB
posts = MicroPostManager.get_list()
while len(posts) > 9:

    print "indexing %d" % len(posts)
    if len(posts) > 0:
        lastPost = list(posts)[-1]
    indexer.index_microposts(posts)

    if lastPost:
        date = get_db_date_from_date(lastPost.date)
        print date
        posts = MicroPostManager.get_list(startKey=date)
    else:
        posts = []

print "indexation finished"
Exemple #30
0
import sys

sys.path.append("../")
from newebe.news.models import MicroPostManager
from newebe.lib.date_util import get_db_date_from_date
from newebe.lib.indexer import Indexer

indexer = Indexer()

print "indexation starts...."

# Fill index with posts from DB
posts = MicroPostManager.get_list()
while len(posts) > 9:

    print "indexing %d" % len(posts)
    if len(posts) > 0:
        lastPost = list(posts)[-1]
    indexer.index_microposts(posts)

    if lastPost:
        date = get_db_date_from_date(lastPost.date)
        print date
        posts = MicroPostManager.get_list(startKey=date)
    else:
        posts = []


print "indexation finished"
Exemple #31
0
def when_i_get_first_from_its_date_and_author(step):
    common = world.commons[0]
    world.common = CommonManager.get_contact_common(common.authorKey,
                                date_util.get_db_date_from_date(common.date))
Exemple #32
0
def when_i_get_first_from_its_date_and_author(step):
    picture = world.pictures[0]    
    world.picture = PictureManager.get_contact_picture(picture.authorKey, 
                                date_util.get_db_date_from_date(picture.date))