Subversion Repositories SmartDukaan

Rev

Rev 7987 | Rev 8707 | 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)
7883 rajveer 53
    fbusers = OneToMany("FacebookUser")
54
    addresses = OneToMany("Address")
8201 rajveer 55
    sources = OneToMany("UserSource")
7883 rajveer 56
    using_options(shortnames=True)
57
    using_table_options(mysql_engine="InnoDB")
58
 
59
class FacebookUser(Entity):
60
    user = ManyToOne("User", primary_key=True)
7825 amar.kumar 61
    facebook_access_token = Field(String(200))
62
    facebook_id = Field(String(50))
557 chandransh 63
    using_options(shortnames=True)
746 rajveer 64
    using_table_options(mysql_engine="InnoDB")
557 chandransh 65
 
8201 rajveer 66
class UserSource(Entity):
67
    user = ManyToOne("User", primary_key=True)
68
    source_id = Field(Integer)
69
    using_options(shortnames=True)
70
    using_table_options(mysql_engine="InnoDB")
71
 
557 chandransh 72
class Line(Entity):
643 chandransh 73
    cart = ManyToOne("Cart", primary_key=True)
746 rajveer 74
    item_id = Field(Integer, primary_key=True, autoincrement=False)
557 chandransh 75
    quantity = Field(Float)
76
    line_status = Field(Integer)
612 chandransh 77
    estimate = Field(Integer)
557 chandransh 78
    created_on = Field(DateTime)
79
    updated_on = Field(DateTime)
1976 varun.gupt 80
    actual_price = Field(Float)
81
    discounted_price = Field(Float)
3554 varun.gupt 82
    discounts = OneToMany('Discount')
6903 anupam.sin 83
    insurer = Field(Integer)
84
    insuranceAmount = Field(Float)
557 chandransh 85
    using_options(shortnames=True)
746 rajveer 86
    using_table_options(mysql_engine="InnoDB")
504 rajveer 87
 
557 chandransh 88
class Cart(Entity):
130 ashish 89
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 90
    cart_status = Field(Integer)
91
    address_id = Field(Integer)
5555 rajveer 92
    pickupStoreId = Field(Integer)
690 chandransh 93
    checked_out_on = Field(DateTime)
557 chandransh 94
    created_on = Field(DateTime)
95
    updated_on = Field(DateTime)
564 chandransh 96
    lines = OneToMany("Line")
1976 varun.gupt 97
    total_price = Field(Float)
98
    discounted_price = Field(Float)
99
    coupon_code = Field(String(20))
5326 rajveer 100
    user = OneToMany("User")
557 chandransh 101
    using_options(shortnames=True)
746 rajveer 102
    using_table_options(mysql_engine="InnoDB")
130 ashish 103
 
3554 varun.gupt 104
class Discount(Entity):
105
    line = ManyToOne("Line", primary_key=True)
106
    discount = Field(Float, primary_key = True)
107
    quantity = Field(Float)
108
    using_options(shortnames = True)
109
    using_table_options(mysql_engine = 'InnoDB')
110
 
557 chandransh 111
#===============================================================================
1976 varun.gupt 112
# Entity generated from Promotion Service
113
#===============================================================================
114
class Promotion(Entity):
115
    id = Field(Integer, primary_key = True, autoincrement = True)
116
    name = Field(String(200))
117
    rule_execution_src = Field(String(100))
118
    start_on = Field(DateTime)
119
    end_on = Field(DateTime)
120
    coupons = OneToMany("Coupon")
121
    created_on = Field(DateTime)
6367 amit.gupta 122
    type = Field(Integer)
1976 varun.gupt 123
    using_options(shortnames = True)
124
    using_table_options(mysql_engine = "InnoDB")
125
 
126
class Coupon(Entity):
127
    coupon_code = Field(String(20))
128
    promotion = ManyToOne("Promotion")
129
    arguments = Field(String(200))
130
    using_options(shortnames = True)
131
    using_table_options(mysql_engine = "InnoDB")
132
 
133
class PromotionTracker(Entity):
134
    coupon_code = Field(String(20))
135
    transaction_id = Field(Integer)
136
    user_id = Field(Integer)
137
    applied_on = Field(DateTime)
7987 amit.gupta 138
    promotion_id = Field(Integer)
1976 varun.gupt 139
    using_options(shortnames = True)
140
    using_table_options(mysql_engine = "InnoDB")
5469 rajveer 141
 
142
class RechargeVoucher(Entity):
143
    id = Field(Integer, primary_key = True, autoincrement = True)
144
    voucherCode = Field(String(30))
145
    voucherType = Field(Integer)
146
    amount = Field(Numeric(precision=8, scale=2, asdecimal=False))
147
    available = Field(Boolean)
148
    issuedOn = Field(DateTime)
149
    expiredOn = Field(DateTime)
150
    redeemed = Field(Boolean)
151
    redeemedOn = Field(DateTime)
152
    email = Field(String(100))
153
    userId = Field(Integer)
154
    using_options(shortnames = True)
155
    using_table_options(mysql_engine = "InnoDB")
1976 varun.gupt 156
 
157
#===============================================================================
1273 varun.gupt 158
# Entity generated from Contact Us form
159
#===============================================================================
160
class UserCommunication(Entity):
161
    id = Field(Integer, primary_key = True, autoincrement = True)
162
    user_id = Field(Integer)
163
    communication_type = Field(Integer)
164
    order_id = Field(Integer)
165
    airwaybill_no = Field(String(50))
166
    reply_to = Field(String(50))
167
    product_name = Field(String(200))
168
    subject = Field(String(200))
169
    message = Field(String(600))
1301 varun.gupt 170
    communication_timestamp = Field(DateTime)
1273 varun.gupt 171
    using_options(shortnames = True)
172
    using_table_options(mysql_engine = "InnoDB")
173
 
174
#===============================================================================
557 chandransh 175
# Different entities for the Widget service
176
#===============================================================================
177
 
2981 rajveer 178
class UserWidgetItem(Entity):
179
    userId = Field(Integer, primary_key=True)
180
    widgetId = Field(Integer, primary_key=True)
181
    itemId = Field(Integer, primary_key=True)
182
    addedOn = Field(DateTime)
557 chandransh 183
    using_options(shortnames=True)    
746 rajveer 184
    using_table_options(mysql_engine="InnoDB")
130 ashish 185
 
1845 vikas 186
class MasterAffiliate(Entity):
187
    id = Field(Integer, primary_key=True, autoincrement=True)
188
    name = Field(String(100), unique=True)
1859 vikas 189
    added_on = Field(DateTime)
1845 vikas 190
    affiliates = OneToMany("Affiliate")
191
    using_options(shortnames=True)
192
    using_table_options(mysql_engine="InnoDB")
193
 
194
class Affiliate(Entity):
195
    id = Field(Integer, primary_key=True, autoincrement=True)
196
    master_affiliate = ManyToOne("MasterAffiliate")
197
    name = Field(String(100), unique=True)
198
    url = Field(String(200))
1859 vikas 199
    added_on = Field(DateTime)
1996 vikas 200
    tracklogs = OneToMany("TrackLog")
1845 vikas 201
    using_options(shortnames=True)
202
    using_table_options(mysql_engine="InnoDB")
203
 
204
class Tracker(Entity):
205
    id = Field(Integer, primary_key=True, autoincrement=True)
2004 vikas 206
    affiliate_id = Field(Integer)
207
    added_on = Field(DateTime)
1845 vikas 208
    using_options(shortnames=True)
209
    using_table_options(mysql_engine="InnoDB")
210
 
211
class TrackLog(Entity):
212
    id = Field(Integer, primary_key=True, autoincrement=True)
1859 vikas 213
    added_on = Field(DateTime)
1996 vikas 214
    affiliate = ManyToOne("Affiliate")
1845 vikas 215
    user_id = Field(Integer)
216
    event = Field(String(100))
3378 vikas 217
    event_id = Field(Integer)
1845 vikas 218
    url = Field(String(200))
219
    data = Field(String(200))
220
    using_options(shortnames=True)
221
    using_table_options(mysql_engine="InnoDB")
222
 
6903 anupam.sin 223
class InsuranceDetails(Entity):
224
    id = Field(Integer, primary_key=True, autoincrement=True)
225
    addressId = Field(Integer)
226
    dob = Field(String(64))
227
    guardianName = Field(String(255))
228
    using_options(shortnames=True)
229
    using_table_options(mysql_engine="InnoDB")
230
 
3187 rajveer 231
def initialize(dbname='user', db_hostname="localhost"):
772 rajveer 232
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
5283 mandeep.dh 233
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200, max_overflow=20)
1122 chandransh 234
    metadata.bind = engine
772 rajveer 235
    metadata.bind.echo = True
236
    setup_all(True)
237
 
238
if __name__=="__main__":
239
    initialize()