Subversion Repositories SmartDukaan

Rev

Rev 18609 | Rev 18735 | 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
12696 amit.gupta 10
from elixir.relationships import OneToMany, ManyToOne
1122 chandransh 11
from sqlalchemy import create_engine
12696 amit.gupta 12
from sqlalchemy.types import Integer, Integer, String, Float, DateTime, Boolean, \
13
    Enum, Numeric, BigInteger, LargeBinary, Date
130 ashish 14
import datetime
746 rajveer 15
import elixir
130 ashish 16
 
17
class Address(Entity):
18
    id = Field(Integer, primary_key=True, autoincrement=True)
19
    line_1 = Field(String(100))
20
    line_2 = Field(String(100))
21
    landmark = Field(String(100))
22
    city = Field(String(100))
23
    state = Field(String(100))
24
    pin = Field(String(10))
25
    country = Field(String(100))
26
    enabled = Field(Boolean)
27
    type = Field(Integer)
28
    added_on = Field(DateTime)
414 ashish 29
    name = Field(String(100))
30
    phone = Field(String(20))
557 chandransh 31
    user = ManyToOne("User")
32
    using_options(shortnames=True)
746 rajveer 33
    using_table_options(mysql_engine="InnoDB")
557 chandransh 34
 
35
class User(Entity):
36
    id = Field(Integer, primary_key=True, autoincrement=True)
130 ashish 37
    email = Field(String(100))
38
    password = Field(String(50))
557 chandransh 39
    name = Field(String(150))
504 rajveer 40
    default_address_id = Field(Integer)
41
    communication_email = Field(String(100))
5326 rajveer 42
    active_cart = ManyToOne("Cart")
557 chandransh 43
    jsession_id = Field(String(64))
44
    is_anonymous = Field(Boolean)
567 rajveer 45
    date_of_birth = Field(String(20))
557 chandransh 46
    sex = Field(Integer)
567 rajveer 47
    mobile_number = Field(String(20))
2020 vikas 48
    source = Field(String(200))
2815 vikas 49
    source_start_time = Field(DateTime)
3499 mandeep.dh 50
    trust_level = Field(Float)
5326 rajveer 51
    last_login = Field(DateTime)
52
    last_logout = Field(DateTime)
53
    active_since = Field(DateTime)
7883 rajveer 54
    fbusers = OneToMany("FacebookUser")
55
    addresses = OneToMany("Address")
8201 rajveer 56
    sources = OneToMany("UserSource")
7883 rajveer 57
    using_options(shortnames=True)
58
    using_table_options(mysql_engine="InnoDB")
59
 
60
class FacebookUser(Entity):
61
    user = ManyToOne("User", primary_key=True)
7825 amar.kumar 62
    facebook_access_token = Field(String(200))
63
    facebook_id = Field(String(50))
557 chandransh 64
    using_options(shortnames=True)
746 rajveer 65
    using_table_options(mysql_engine="InnoDB")
557 chandransh 66
 
8201 rajveer 67
class UserSource(Entity):
68
    user = ManyToOne("User", primary_key=True)
69
    source_id = Field(Integer)
70
    using_options(shortnames=True)
71
    using_table_options(mysql_engine="InnoDB")
72
 
557 chandransh 73
class Line(Entity):
643 chandransh 74
    cart = ManyToOne("Cart", primary_key=True)
746 rajveer 75
    item_id = Field(Integer, primary_key=True, autoincrement=False)
557 chandransh 76
    quantity = Field(Float)
77
    line_status = Field(Integer)
612 chandransh 78
    estimate = Field(Integer)
557 chandransh 79
    created_on = Field(DateTime)
80
    updated_on = Field(DateTime)
1976 varun.gupt 81
    actual_price = Field(Float)
82
    discounted_price = Field(Float)
3554 varun.gupt 83
    discounts = OneToMany('Discount')
6903 anupam.sin 84
    insurer = Field(Integer)
85
    insuranceAmount = Field(Float)
9300 kshitij.so 86
    dataProtectionInsurer =Field(Integer, default=0, server_default="0")
87
    dataProtectionAmount = Field(Float, default=0, server_default="0")
11653 amit.gupta 88
    dealText=Field(String(200))
89
    freebieId=Field(Integer)
557 chandransh 90
    using_options(shortnames=True)
746 rajveer 91
    using_table_options(mysql_engine="InnoDB")
504 rajveer 92
 
557 chandransh 93
class Cart(Entity):
130 ashish 94
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 95
    cart_status = Field(Integer)
96
    address_id = Field(Integer)
5555 rajveer 97
    pickupStoreId = Field(Integer)
690 chandransh 98
    checked_out_on = Field(DateTime)
557 chandransh 99
    created_on = Field(DateTime)
100
    updated_on = Field(DateTime)
564 chandransh 101
    lines = OneToMany("Line")
1976 varun.gupt 102
    total_price = Field(Float)
103
    discounted_price = Field(Float)
104
    coupon_code = Field(String(20))
13139 amit.gupta 105
    user = OneToMany("User")
557 chandransh 106
    using_options(shortnames=True)
746 rajveer 107
    using_table_options(mysql_engine="InnoDB")
130 ashish 108
 
3554 varun.gupt 109
class Discount(Entity):
110
    line = ManyToOne("Line", primary_key=True)
111
    discount = Field(Float, primary_key = True)
112
    quantity = Field(Float)
113
    using_options(shortnames = True)
114
    using_table_options(mysql_engine = 'InnoDB')
115
 
557 chandransh 116
#===============================================================================
1976 varun.gupt 117
# Entity generated from Promotion Service
118
#===============================================================================
119
class Promotion(Entity):
120
    id = Field(Integer, primary_key = True, autoincrement = True)
121
    name = Field(String(200))
122
    rule_execution_src = Field(String(100))
123
    start_on = Field(DateTime)
124
    end_on = Field(DateTime)
125
    coupons = OneToMany("Coupon")
126
    created_on = Field(DateTime)
6367 amit.gupta 127
    type = Field(Integer)
1976 varun.gupt 128
    using_options(shortnames = True)
129
    using_table_options(mysql_engine = "InnoDB")
11653 amit.gupta 130
 
131
class PrivateDealUser(Entity):
132
    id = Field(Integer, primary_key=True)
12696 amit.gupta 133
    counter = ManyToOne("Counter")
134
    tin = Field(String(20))
11653 amit.gupta 135
    created_on = Field(DateTime)
136
    isActive = Field(Boolean)
13400 manish.sha 137
    bulkShipmentAmountLimit = Field(Float, default=50000)
18590 manish.sha 138
    creditorAssigned = Field(Boolean)
11657 amit.gupta 139
    using_options(shortnames = True)
140
    using_table_options(mysql_engine = "InnoDB")
1976 varun.gupt 141
 
142
class Coupon(Entity):
143
    coupon_code = Field(String(20))
144
    promotion = ManyToOne("Promotion")
145
    arguments = Field(String(200))
8707 manish.sha 146
    coupon_category = Field(Enum('CUSTOMER_SATISFACTION','MARKETING','REFUND'))
1976 varun.gupt 147
    using_options(shortnames = True)
148
    using_table_options(mysql_engine = "InnoDB")
149
 
150
class PromotionTracker(Entity):
151
    coupon_code = Field(String(20))
152
    transaction_id = Field(Integer)
153
    user_id = Field(Integer)
154
    applied_on = Field(DateTime)
7987 amit.gupta 155
    promotion_id = Field(Integer)
13521 amit.gupta 156
    amount = Field(Integer)
157
    is_digital  = Field(Boolean)
1976 varun.gupt 158
    using_options(shortnames = True)
159
    using_table_options(mysql_engine = "InnoDB")
5469 rajveer 160
 
161
class RechargeVoucher(Entity):
162
    id = Field(Integer, primary_key = True, autoincrement = True)
163
    voucherCode = Field(String(30))
164
    voucherType = Field(Integer)
165
    amount = Field(Numeric(precision=8, scale=2, asdecimal=False))
166
    available = Field(Boolean)
167
    issuedOn = Field(DateTime)
168
    expiredOn = Field(DateTime)
169
    redeemed = Field(Boolean)
170
    redeemedOn = Field(DateTime)
171
    email = Field(String(100))
172
    userId = Field(Integer)
173
    using_options(shortnames = True)
174
    using_table_options(mysql_engine = "InnoDB")
1976 varun.gupt 175
 
176
#===============================================================================
1273 varun.gupt 177
# Entity generated from Contact Us form
178
#===============================================================================
179
class UserCommunication(Entity):
180
    id = Field(Integer, primary_key = True, autoincrement = True)
181
    user_id = Field(Integer)
182
    communication_type = Field(Integer)
183
    order_id = Field(Integer)
184
    airwaybill_no = Field(String(50))
185
    reply_to = Field(String(50))
186
    product_name = Field(String(200))
187
    subject = Field(String(200))
188
    message = Field(String(600))
1301 varun.gupt 189
    communication_timestamp = Field(DateTime)
1273 varun.gupt 190
    using_options(shortnames = True)
191
    using_table_options(mysql_engine = "InnoDB")
192
 
193
#===============================================================================
557 chandransh 194
# Different entities for the Widget service
195
#===============================================================================
196
 
2981 rajveer 197
class UserWidgetItem(Entity):
198
    userId = Field(Integer, primary_key=True)
199
    widgetId = Field(Integer, primary_key=True)
200
    itemId = Field(Integer, primary_key=True)
201
    addedOn = Field(DateTime)
557 chandransh 202
    using_options(shortnames=True)    
746 rajveer 203
    using_table_options(mysql_engine="InnoDB")
130 ashish 204
 
1845 vikas 205
class MasterAffiliate(Entity):
206
    id = Field(Integer, primary_key=True, autoincrement=True)
207
    name = Field(String(100), unique=True)
1859 vikas 208
    added_on = Field(DateTime)
1845 vikas 209
    affiliates = OneToMany("Affiliate")
210
    using_options(shortnames=True)
211
    using_table_options(mysql_engine="InnoDB")
212
 
213
class Affiliate(Entity):
214
    id = Field(Integer, primary_key=True, autoincrement=True)
215
    master_affiliate = ManyToOne("MasterAffiliate")
216
    name = Field(String(100), unique=True)
217
    url = Field(String(200))
1859 vikas 218
    added_on = Field(DateTime)
1996 vikas 219
    tracklogs = OneToMany("TrackLog")
1845 vikas 220
    using_options(shortnames=True)
221
    using_table_options(mysql_engine="InnoDB")
222
 
223
class Tracker(Entity):
224
    id = Field(Integer, primary_key=True, autoincrement=True)
2004 vikas 225
    affiliate_id = Field(Integer)
226
    added_on = Field(DateTime)
1845 vikas 227
    using_options(shortnames=True)
228
    using_table_options(mysql_engine="InnoDB")
229
 
230
class TrackLog(Entity):
231
    id = Field(Integer, primary_key=True, autoincrement=True)
1859 vikas 232
    added_on = Field(DateTime)
1996 vikas 233
    affiliate = ManyToOne("Affiliate")
1845 vikas 234
    user_id = Field(Integer)
235
    event = Field(String(100))
3378 vikas 236
    event_id = Field(Integer)
1845 vikas 237
    url = Field(String(200))
238
    data = Field(String(200))
239
    using_options(shortnames=True)
240
    using_table_options(mysql_engine="InnoDB")
241
 
6903 anupam.sin 242
class InsuranceDetails(Entity):
243
    id = Field(Integer, primary_key=True, autoincrement=True)
244
    addressId = Field(Integer)
245
    dob = Field(String(64))
246
    guardianName = Field(String(255))
247
    using_options(shortnames=True)
248
    using_table_options(mysql_engine="InnoDB")
12696 amit.gupta 249
 
250
class Counter(Entity):
251
    id = Field(Integer, primary_key=True, autoincrement=True)
252
    code = Field(String(10),unique=True)
253
    dealUsers = OneToMany("PrivateDealUser")
254
    name = Field(String(128))
255
    ownerName = Field(String(100))
256
    email = Field(String(80))
257
    mobile = Field(String(10))
258
    alternateMobile = Field(String(10))
259
    addressId = Field(Integer)
260
    striker = Field(Boolean)
261
    tin = Field(String(20), unique=True)
262
    spCounterSize = Field(Integer)
263
    fpCounterSize = Field(Integer)
12722 amit.gupta 264
    dob = Field(String(20))
12696 amit.gupta 265
    createdOn = Field(DateTime)
12730 amit.gupta 266
    lastPurchasedOn = Field(DateTime)
18530 manish.sha 267
    documentVerified = Field(Boolean)
268
    verificationType = Field(Integer)
269
    verifiedOn = Field(DateTime)
12696 amit.gupta 270
    using_options(shortnames=True)
271
    using_table_options(mysql_engine="InnoDB")
15251 manish.sha 272
 
18530 manish.sha 273
class CounterOnlineInfo(Entity):
274
    counterId = Field(Integer, primary_key=True)
275
    tinNumber = Field(String(30))
276
    cstNumber = Field(String(30))
277
    dealerName = Field(String(100))
278
    dealerAddress = Field(Text)
279
    state = Field(String(20))
280
    pan = Field(String(20))
281
    registrationDate = Field(DateTime)
282
    registrationStatus = Field(Boolean)
283
    validatedTill = Field(DateTime)
18634 manish.sha 284
    created = Field(DateTime,default = datetime.datetime.now)
18530 manish.sha 285
    using_options(shortnames=True)
286
    using_table_options(mysql_engine="InnoDB")
287
 
15251 manish.sha 288
class AccessTokenizer(Entity):
289
    id = Field(Integer, primary_key=True, autoincrement=True)
290
    userId = Field(Integer)
291
    source = Field(String(50))
292
    tokenString = Field(String(50))
293
    expiredTime = Field(DateTime)
294
    expired = Field(Boolean)
295
    using_options(shortnames=True)
296
    using_table_options(mysql_engine="InnoDB")
6903 anupam.sin 297
 
3187 rajveer 298
def initialize(dbname='user', db_hostname="localhost"):
772 rajveer 299
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
5283 mandeep.dh 300
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200, max_overflow=20)
1122 chandransh 301
    metadata.bind = engine
12730 amit.gupta 302
    metadata.bind.echo = True
772 rajveer 303
    setup_all(True)
304
 
305
if __name__=="__main__":
306
    initialize()