Login

Get email and push on couchdb - Model

Author:
magik_cypress
Posted:
March 1, 2012
Language:
Python
Version:
1.3
Score:
0 (after 0 ratings)

view/admin.py

` def reactor(request):

context = {
    'email': read_mailbox()
}
return render_to_response(_lookup_template('dashboard'), context,
                          context_instance=RequestContext(request))

`

_Design all.js

function (doc) { if (doc.doc_type == 'MailArchive') { emit(doc._id, doc); } }

reduce.js

_count

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from django import forms
from django.forms import fields
from django.db import models
from django.db.models import permalink
from django.conf import settings
import re, datetime

from couchdbkit.ext.django.schema import *
from couchdbkit.ext.django.forms import *
from couchdbkit.exceptions import ResourceNotFound

from django.utils.translation import gettext_lazy as _

MARKUP_LANGUAGE = getattr(settings, 'MARKUP_LANGUAGE', None)

def markup(text, small_headings=False, no_follow=True, escape=False,
           scale_headings=True):
    """Markup text using the markup language specified in the settings.
    """
    if MARKUP_LANGUAGE == 'markdown':
        import markdown
        safe_mode = 'escape' if escape else None
        try:
            import pygments
            options = ['codehilite', 'extra', 'toc']
            if scale_headings:
                options.append('headerid(level=3, forceid=False)')
            text = markdown.markdown(text, options, safe_mode=safe_mode)

        except ImportError:
            options = ['extra', 'toc']
            if scale_headings:
                options.append('headerid(level=3, forceid=False)')
            text = markdown.markdown(text, options, safe_mode=safe_mode)

    if small_headings:
        text = re.sub('<(/?h)[1-6]', '<\g<1>5', text)

    if no_follow:
        text = re.sub('<a (?![^>]*nofollow)', '<a rel="nofollow" ', text)

    return text

class MailArchive(Document):
    head_to = StringProperty()
    head_from = StringProperty()
    head_subject = StringProperty()
    head_date = StringProperty()
    message_id = StringProperty()
    header = StringProperty()
    body = StringProperty()
    body_text = StringProperty()
    body_html = StringProperty()
    flag = StringProperty()
    publish_date = DateTimeProperty(required=True, default=datetime.datetime.now)
    is_admin = BooleanProperty(required=True, default=True)    
    is_superuser = BooleanProperty(required=True, default=True)
    # _attachments = ListProperty(required=False, default=None)

    def save(self):
        super(MailArchive, self).save()

    def save_docs(self):
        super(MailArchive, self).save_docs()

    def delete(self):
        super(MailArchive, self).delete()

    class Meta:
        ordering = ['publish_date']
        app_label = "mailreactor"

    def __unicode__(self):
        return self.header

    def _get_id(self):
        return self._id

    id = property(_get_id)

    @classmethod
    def get_email(self, id):
        param = {"key": id}      
        design = MailArchive._meta.app_label
        r = MailArchive.view('%s/%s-email_by_id' % (design, design),
                     include_docs=True,
                     **param).first()
        if r:
            return r
        return None 

    @classmethod
    def all_mails(self, limit=10000000000, descending=True, reduce=True):
        param = {"limit": limit}
        design = MailArchive._meta.app_label
        r = MailArchive.view('%s/%s-all' % (design, design),
                include_docs=True,
                descending=True,
                reduce=False,
                limit=limit
            )
        if r:
            return r.iterator()
        return None

    @classmethod
    def count(self):
        design = MailArchive._meta.app_label
        r = MailArchive.view('%s/%s-all' % (design, design),
                reduce=True,
            )
        if r:
            return r.first()['value']
        return '0'

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

Please login first before commenting.