Beispiel #1
0
class Session(Model):

    title = Field()
    speaker = ReferenceField(SessionLocation)
    descr = Field()
    tags = Field()
    start_at = Field()
    duration = Field()
    location = ReferenceField(SessionLocation)
Beispiel #2
0
 class MockModel(dict):
     field = Field(unicode)
     typeless = Field()
     required = Field(required=True)
     string = Field(basestring)
     reference = ReferenceField(Base)
     number = Field(float)
Beispiel #3
0
class SurveyResponse(Model):

    surveykey = Field()
    user = ReferenceField(User)
    answers = Field()

    def answer(self, key, default=None):
        return self.answers.get(key, default)
Beispiel #4
0
class Comment(Model):
    replied_to = Field(bool, default=False)
    is_troll = Field(bool, default=False)
    is_classified = Field(bool, default=False)
    object_id = Field(unicode, required=True)
    author_id = Field(unicode, required=True)
    author_name = Field(unicode, required=True)
    body = Field(unicode, required=True)
    body_html = Field(unicode, required=True)
    permalink = Field(unicode, required=True)
    submission = ReferenceField(Submission)
    date_added = Field(int, required=True)
Beispiel #5
0
class MailingRecipient(Model):
    # id              = AutoField(primary_key=True)
    # recipient_id     = models.IntegerField(db_index=True)   # ID on master
    mailing         = ReferenceField(Mailing, required=True)
    tracking_id     = Field()
    contact_data    = Field()  # Python dictionary containing all recipient fields
    email           = Field(required=True)
    mail_from       = Field(required=False)
    sender_name     = Field()
    domain_name     = Field(required=True)   # Recipient's domain name
    first_try       = Field(datetime)
    next_try        = Field(datetime) # TODO maybe a int from EPOCH would be faster
    try_count       = Field(int)
    send_status     = EnumField(recipient_status, default=RECIPIENT_STATUS.READY)
    reply_code      = Field(int)
    reply_enhanced_code = Field()
    reply_text      = Field()
    smtp_log        = Field()
    in_progress     = Field(bool, default=False)  # added in temp queue
    created         = Field(datetime, default=datetime.utcnow)
    modified        = Field(datetime, default=datetime.utcnow)
    finished        = Field(bool, default=False)  # True if this recipient have been handled (successfully or not) and should be returned back to the master.

    def __unicode__(self):
        return self.email

    def save(self, *args, **kwargs):
        self.modified = datetime.utcnow()
        return super(MailingRecipient, self).save(*args, **kwargs)

    def set_send_mail_in_progress(self):
        self.send_status = RECIPIENT_STATUS.IN_PROGRESS
        if self.try_count is None:
            self.try_count = 0
        self.try_count += 1
        self.in_progress = True
        if not self.first_try:
            self.first_try = datetime.utcnow()
        self.next_try = datetime.utcnow()
        self.save()

    def update_send_status(self, send_status, smtp_code=None, smtp_e_code=None, smtp_message=None, in_progress=False,
                           smtp_log=None, target_ip=None):
        """
        Updates the contact status.
        """
        LiveStats.add_log(mailing_id = self.mailing.id, domain_name=self.domain_name,
                          mail_from=self.mail_from, mail_to=self.email,
                          send_status=send_status, reply_code=smtp_code, reply_enhanced_code=smtp_e_code,
                          reply_text=smtp_message, target_ip=target_ip)
        self.send_status = send_status
        if send_status == RECIPIENT_STATUS.FINISHED:
            self.next_try = datetime.utcnow()
        self.reply_code = smtp_code and smtp_code or None
        self.reply_enhanced_code = smtp_e_code and smtp_e_code or None
        self.reply_text = smtp_message and unicode(smtp_message, errors='replace') or None
        self.smtp_log = smtp_log and unicode(smtp_log, errors='replace') or None
        self.in_progress = in_progress
        self.save()
        #if send_status in (RECIPIENT_STATUS.ERROR, RECIPIENT_STATUS.GENERAL_ERROR):
            #self.contact.status = CONTACT_STATUS.ERROR
            #self.contact.save()
        #elif send_status == RECIPIENT_STATUS.FINISHED:
            #self.contact.status = CONTACT_STATUS.VALID
            #self.contact.save()

    def set_send_mail_next_time(self):
        """
        This implement the mailing specific strategy for retries and mark this entry as removable from queue.
        """
        self.in_progress = False
        if self.try_count < 3:
            self.next_try = datetime.utcnow() + timedelta(minutes=10)
        elif self.try_count < 10:
            self.next_try = datetime.utcnow() + timedelta(minutes=60)
        else:
            self.next_try = datetime.utcnow() + timedelta(hours=6)
        self.finished = True
        self.save()

    def mark_as_finished(self):
        self.finished = True
        self.save()
Beispiel #6
0
class Person(Model):
    _name = "people"
    company = ReferenceField(Company)
    name = Field(str)
    email = Field(str)
Beispiel #7
0
ALTDB = "_mogotest2"
DELETE = True


class Foo(Model):
    bar = Field(unicode)
    typeless = Field()
    dflt = Field(unicode, default=u'dflt')
    callme = Field(unicode, default=lambda: u'funtimes')
    dtnow = Field(datetime, default=lambda: datetime.now())

    def __unicode__(self):
        return "FOOBAR"


Foo.ref = ReferenceField(Foo)


class FooWithNew(Model):
    bar = Field(unicode)

    @classmethod
    def new(cls):
        return cls(bar=u"whatever")


class Company(Model):
    name = Field(str)

    @property
    def people(self):
Beispiel #8
0
class MailingRecipient(Model):
    # id              = AutoField(primary_key=True)
    mailing = ReferenceField(Mailing, required=True)
    tracking_id = Field()
    contact = Field()  # Python dictionary containing all recipient fields
    email = Field(required=True)
    domain_name = Field(required=True)  # Recipient's domain name
    first_try = Field(datetime)
    next_try = Field(
        datetime, required=True)  # TODO maybe a int from EPOCH would be faster
    try_count = Field(int)
    send_status = EnumField(recipient_status, default=RECIPIENT_STATUS.READY)
    reply_code = Field(int)
    reply_enhanced_code = Field()
    reply_text = Field()
    smtp_log = Field()
    dsn = Field()  # Delivery Status Notification (if received) RFC-3464
    in_progress = Field(bool,
                        default=False)  # added to a satellite for sending
    report_ready = Field(bool,
                         default=False)  # data ready to report to API client
    cloud_client = Field()  # help_text="Client used to send the email (serial)
    date_delegated = Field(
        datetime)  # When this recipient has been delegated to the client.
    primary = Field(
        bool, default=False
    )  # if true, this recipient should be addressed in priority
    created = Field(datetime, default=datetime.utcnow)
    modified = Field(datetime, default=datetime.utcnow)

    # class Meta:
    #     database = DATABASE
    #     collection = "mailing_recipient"
    #
    #     indices = (
    #         Index("serial"),
    #     )

    def __str__(self):
        return self.email

    def save(self, *args, **kwargs):
        self.modified = datetime.utcnow()
        return super(MailingRecipient, self).save(*args, **kwargs)

    def update_send_status(self,
                           send_status,
                           smtp_code=None,
                           smtp_e_code=None,
                           smtp_message=None,
                           in_progress=False,
                           smtp_log=None):
        self.send_status = send_status
        if send_status == RECIPIENT_STATUS.FINISHED:
            self.next_try = datetime.utcnow()
        self.reply_code = smtp_code and smtp_code or None
        self.reply_enhanced_code = smtp_e_code and smtp_e_code or None
        self.reply_text = smtp_message and smtp_message or None
        self.smtp_log = smtp_log and smtp_log or None
        self.in_progress = in_progress

    def set_send_mail_next_time(self):
        """
        This implement the mailing specific strategy for retries.
        """
        self.in_progress = False
        if self.try_count < 3:
            self.next_try = datetime.utcnow() + timedelta(minutes=10)
        elif self.try_count < 10:
            self.next_try = datetime.utcnow() + timedelta(minutes=60)
        else:
            self.next_try = datetime.utcnow() + timedelta(hours=6)