Subversion Repositories SmartDukaan

Rev

Rev 5326 | Rev 5555 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
130 ashish 1
'''
2
Created on 28-Apr-2010
3
 
4
@author: ashish
5
'''
6
 
7
from elixir import *
8
from elixir.entity import Entity
9
from elixir.fields import Field
1122 chandransh 10
from sqlalchemy import create_engine
130 ashish 11
from sqlalchemy.types import Integer
12
from elixir.relationships import OneToMany, ManyToOne
13
import datetime
746 rajveer 14
import elixir
130 ashish 15
 
16
class Address(Entity):
17
    id = Field(Integer, primary_key=True, autoincrement=True)
18
    line_1 = Field(String(100))
19
    line_2 = Field(String(100))
20
    landmark = Field(String(100))
21
    city = Field(String(100))
22
    state = Field(String(100))
23
    pin = Field(String(10))
24
    country = Field(String(100))
25
    enabled = Field(Boolean)
26
    type = Field(Integer)
27
    added_on = Field(DateTime)
414 ashish 28
    name = Field(String(100))
29
    phone = Field(String(20))
557 chandransh 30
    user = ManyToOne("User")
31
    using_options(shortnames=True)
746 rajveer 32
    using_table_options(mysql_engine="InnoDB")
557 chandransh 33
 
34
class User(Entity):
35
    id = Field(Integer, primary_key=True, autoincrement=True)
130 ashish 36
    email = Field(String(100))
37
    password = Field(String(50))
557 chandransh 38
    name = Field(String(150))
504 rajveer 39
    default_address_id = Field(Integer)
40
    communication_email = Field(String(100))
5326 rajveer 41
    active_cart = ManyToOne("Cart")
557 chandransh 42
    jsession_id = Field(String(64))
43
    is_anonymous = Field(Boolean)
567 rajveer 44
    date_of_birth = Field(String(20))
557 chandransh 45
    sex = Field(Integer)
567 rajveer 46
    mobile_number = Field(String(20))
2020 vikas 47
    source = Field(String(200))
2815 vikas 48
    source_start_time = Field(DateTime)
3499 mandeep.dh 49
    trust_level = Field(Float)
5326 rajveer 50
    last_login = Field(DateTime)
51
    last_logout = Field(DateTime)
52
    active_since = Field(DateTime)
130 ashish 53
    addresses = OneToMany("Address")
557 chandransh 54
    using_options(shortnames=True)
746 rajveer 55
    using_table_options(mysql_engine="InnoDB")
557 chandransh 56
 
57
class Line(Entity):
643 chandransh 58
    cart = ManyToOne("Cart", primary_key=True)
746 rajveer 59
    item_id = Field(Integer, primary_key=True, autoincrement=False)
557 chandransh 60
    quantity = Field(Float)
61
    line_status = Field(Integer)
612 chandransh 62
    estimate = Field(Integer)
557 chandransh 63
    created_on = Field(DateTime)
64
    updated_on = Field(DateTime)
1976 varun.gupt 65
    actual_price = Field(Float)
66
    discounted_price = Field(Float)
3554 varun.gupt 67
    discounts = OneToMany('Discount')
557 chandransh 68
    using_options(shortnames=True)
746 rajveer 69
    using_table_options(mysql_engine="InnoDB")
504 rajveer 70
 
557 chandransh 71
class Cart(Entity):
130 ashish 72
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 73
    cart_status = Field(Integer)
74
    address_id = Field(Integer)
690 chandransh 75
    checked_out_on = Field(DateTime)
557 chandransh 76
    created_on = Field(DateTime)
77
    updated_on = Field(DateTime)
564 chandransh 78
    lines = OneToMany("Line")
1976 varun.gupt 79
    total_price = Field(Float)
80
    discounted_price = Field(Float)
81
    coupon_code = Field(String(20))
5326 rajveer 82
    user = OneToMany("User")
557 chandransh 83
    using_options(shortnames=True)
746 rajveer 84
    using_table_options(mysql_engine="InnoDB")
130 ashish 85
 
3554 varun.gupt 86
class Discount(Entity):
87
    line = ManyToOne("Line", primary_key=True)
88
    discount = Field(Float, primary_key = True)
89
    quantity = Field(Float)
90
    using_options(shortnames = True)
91
    using_table_options(mysql_engine = 'InnoDB')
92
 
557 chandransh 93
#===============================================================================
1976 varun.gupt 94
# Entity generated from Promotion Service
95
#===============================================================================
96
class Promotion(Entity):
97
    id = Field(Integer, primary_key = True, autoincrement = True)
98
    name = Field(String(200))
99
    rule_execution_src = Field(String(100))
100
    start_on = Field(DateTime)
101
    end_on = Field(DateTime)
102
    coupons = OneToMany("Coupon")
103
    created_on = Field(DateTime)
104
    using_options(shortnames = True)
105
    using_table_options(mysql_engine = "InnoDB")
106
 
107
class Coupon(Entity):
108
    coupon_code = Field(String(20))
109
    promotion = ManyToOne("Promotion")
110
    arguments = Field(String(200))
111
    using_options(shortnames = True)
112
    using_table_options(mysql_engine = "InnoDB")
113
 
114
class PromotionTracker(Entity):
115
    coupon_code = Field(String(20))
116
    transaction_id = Field(Integer)
117
    user_id = Field(Integer)
118
    applied_on = Field(DateTime)
119
    using_options(shortnames = True)
120
    using_table_options(mysql_engine = "InnoDB")
5469 rajveer 121
 
122
class RechargeVoucher(Entity):
123
    id = Field(Integer, primary_key = True, autoincrement = True)
124
    voucherCode = Field(String(30))
125
    voucherType = Field(Integer)
126
    amount = Field(Numeric(precision=8, scale=2, asdecimal=False))
127
    available = Field(Boolean)
128
    issuedOn = Field(DateTime)
129
    expiredOn = Field(DateTime)
130
    redeemed = Field(Boolean)
131
    redeemedOn = Field(DateTime)
132
    email = Field(String(100))
133
    userId = Field(Integer)
134
    using_options(shortnames = True)
135
    using_table_options(mysql_engine = "InnoDB")
1976 varun.gupt 136
 
137
#===============================================================================
1273 varun.gupt 138
# Entity generated from Contact Us form
139
#===============================================================================
140
class UserCommunication(Entity):
141
    id = Field(Integer, primary_key = True, autoincrement = True)
142
    user_id = Field(Integer)
143
    communication_type = Field(Integer)
144
    order_id = Field(Integer)
145
    airwaybill_no = Field(String(50))
146
    reply_to = Field(String(50))
147
    product_name = Field(String(200))
148
    subject = Field(String(200))
149
    message = Field(String(600))
1301 varun.gupt 150
    communication_timestamp = Field(DateTime)
1273 varun.gupt 151
    using_options(shortnames = True)
152
    using_table_options(mysql_engine = "InnoDB")
153
 
154
#===============================================================================
557 chandransh 155
# Different entities for the Widget service
156
#===============================================================================
157
 
2981 rajveer 158
class UserWidgetItem(Entity):
159
    userId = Field(Integer, primary_key=True)
160
    widgetId = Field(Integer, primary_key=True)
161
    itemId = Field(Integer, primary_key=True)
162
    addedOn = Field(DateTime)
557 chandransh 163
    using_options(shortnames=True)    
746 rajveer 164
    using_table_options(mysql_engine="InnoDB")
130 ashish 165
 
1845 vikas 166
class MasterAffiliate(Entity):
167
    id = Field(Integer, primary_key=True, autoincrement=True)
168
    name = Field(String(100), unique=True)
1859 vikas 169
    added_on = Field(DateTime)
1845 vikas 170
    affiliates = OneToMany("Affiliate")
171
    using_options(shortnames=True)
172
    using_table_options(mysql_engine="InnoDB")
173
 
174
class Affiliate(Entity):
175
    id = Field(Integer, primary_key=True, autoincrement=True)
176
    master_affiliate = ManyToOne("MasterAffiliate")
177
    name = Field(String(100), unique=True)
178
    url = Field(String(200))
1859 vikas 179
    added_on = Field(DateTime)
1996 vikas 180
    tracklogs = OneToMany("TrackLog")
1845 vikas 181
    using_options(shortnames=True)
182
    using_table_options(mysql_engine="InnoDB")
183
 
184
class Tracker(Entity):
185
    id = Field(Integer, primary_key=True, autoincrement=True)
2004 vikas 186
    affiliate_id = Field(Integer)
187
    added_on = Field(DateTime)
1845 vikas 188
    using_options(shortnames=True)
189
    using_table_options(mysql_engine="InnoDB")
190
 
191
class TrackLog(Entity):
192
    id = Field(Integer, primary_key=True, autoincrement=True)
1859 vikas 193
    added_on = Field(DateTime)
1996 vikas 194
    affiliate = ManyToOne("Affiliate")
1845 vikas 195
    user_id = Field(Integer)
196
    event = Field(String(100))
3378 vikas 197
    event_id = Field(Integer)
1845 vikas 198
    url = Field(String(200))
199
    data = Field(String(200))
200
    using_options(shortnames=True)
201
    using_table_options(mysql_engine="InnoDB")
202
 
2641 varun.gupt 203
class UserNote(Entity):
204
    user_id = Field(Integer)
205
    entity_id = Field(Integer)
2717 varun.gupt 206
    slide = Field(String(30))
2641 varun.gupt 207
    note = Field(String(500))
208
    using_options(shortnames=True)
209
    using_table_options(mysql_engine="InnoDB")
210
 
3187 rajveer 211
def initialize(dbname='user', db_hostname="localhost"):
772 rajveer 212
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
5283 mandeep.dh 213
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200, max_overflow=20)
1122 chandransh 214
    metadata.bind = engine
772 rajveer 215
    metadata.bind.echo = True
216
    setup_all(True)
217
 
218
if __name__=="__main__":
219
    initialize()