Subversion Repositories SmartDukaan

Rev

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