root / mailer / model.py

Revision 136:bfdb6e432cb8, 2.1 kB (checked in by Tarek Ziad?? <tarek@…>, 12 months ago)

finalized v1

Line 
1#!/usr/bin/python
2# -*- coding: UTF-8 -*-
3#
4# Copyright (c) 2007 Tarek Ziadé
5#
6# Authors:
7#   Tarek Ziadé <tarek@ziade.org>
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation; either version 2
12# of the License, or (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23import os
24from sqlalchemy import *
25from settings import DATABASE
26
27curdir = os.path.dirname(__file__)
28if curdir == '':
29    curdir = '.'
30
31curdir = os.path.realpath(curdir)
32
33sql_db = create_engine(DATABASE)
34metadata = BoundMetaData(sql_db)
35
36mail_data = Table('mailer_mail_data', metadata,
37                   Column('id', Integer, primary_key=True, autoincrement=True),
38                   Column('subject', String(300)),
39                   Column('sender', String(300)),
40                   Column('recipients', String(300)),
41                   Column('date', DateTime()),
42                   Column('data', TEXT()))
43
44try:
45    mail_data.create()
46except exceptions.SQLError:
47    # already exists
48    pass
49
50mailed_data = Table('mailer_mailed_data', metadata,
51                   Column('id', Integer, primary_key=True, autoincrement=True),
52                   Column('subject', String(300)),
53                   Column('sender', String(300)),
54                   Column('original_id', Integer),
55                   Column('recipients', String(300)),
56                   Column('error', String(300)),
57                   Column('data', TEXT()),
58                   Column('date', DateTime()),
59                   Column('status', String(10)),)
60
61try:
62    mailed_data.create()
63except exceptions.SQLError:
64    # already exists
65    pass
Note: See TracBrowser for help on using the browser.