Subversion Repositories SmartDukaan

Rev

Rev 11657 | Rev 12697 | 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
 
12696 amit.gupta 7
from checkbox.properties import Bool
130 ashish 8
from elixir import *
9
from elixir.entity import Entity
10
from elixir.fields import Field
12696 amit.gupta 11
from elixir.relationships import OneToMany, ManyToOne
1122 chandransh 12
from sqlalchemy import create_engine
12696 amit.gupta 13
from sqlalchemy.types import Integer, Integer, String, Float, DateTime, Boolean, \
14
    Enum, Numeric, BigInteger, LargeBinary, Date
130 ashish 15
import datetime
746 rajveer 16
import elixir
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)
9300 kshitij.so 87
    dataProtectionInsurer =Field(Integer, default=0, server_default="0")
88
    dataProtectionAmount = Field(Float, default=0, server_default="0")
11653 amit.gupta 89
    dealText=Field(String(200))
90
    freebieId=Field(Integer)
557 chandransh 91
    using_options(shortnames=True)
746 rajveer 92
    using_table_options(mysql_engine="InnoDB")
504 rajveer 93
 
557 chandransh 94
class Cart(Entity):
130 ashish 95
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 96
    cart_status = Field(Integer)
97
    address_id = Field(Integer)
5555 rajveer 98
    pickupStoreId = Field(Integer)
690 chandransh 99
    checked_out_on = Field(DateTime)
557 chandransh 100
    created_on = Field(DateTime)
101
    updated_on = Field(DateTime)
564 chandransh 102
    lines = OneToMany("Line")
1976 varun.gupt 103
    total_price = Field(Float)
104
    discounted_price = Field(Float)
105
    coupon_code = Field(String(20))
5326 rajveer 106
    user = OneToMany("User")
557 chandransh 107
    using_options(shortnames=True)
746 rajveer 108
    using_table_options(mysql_engine="InnoDB")
130 ashish 109
 
3554 varun.gupt 110
class Discount(Entity):
111
    line = ManyToOne("Line", primary_key=True)
112
    discount = Field(Float, primary_key = True)
113
    quantity = Field(Float)
114
    using_options(shortnames = True)
115
    using_table_options(mysql_engine = 'InnoDB')
116
 
557 chandransh 117
#===============================================================================
1976 varun.gupt 118
# Entity generated from Promotion Service
119
#===============================================================================
120
class Promotion(Entity):
121
    id = Field(Integer, primary_key = True, autoincrement = True)
122
    name = Field(String(200))
123
    rule_execution_src = Field(String(100))
124
    start_on = Field(DateTime)
125
    end_on = Field(DateTime)
126
    coupons = OneToMany("Coupon")
127
    created_on = Field(DateTime)
6367 amit.gupta 128
    type = Field(Integer)
1976 varun.gupt 129
    using_options(shortnames = True)
130
    using_table_options(mysql_engine = "InnoDB")
11653 amit.gupta 131
 
132
class PrivateDealUser(Entity):
133
    id = Field(Integer, primary_key=True)
12696 amit.gupta 134
    counter = ManyToOne("Counter")
135
    tin = Field(String(20))
11653 amit.gupta 136
    created_on = Field(DateTime)
137
    isActive = Field(Boolean)
11657 amit.gupta 138
    using_options(shortnames = True)
139
    using_table_options(mysql_engine = "InnoDB")
1976 varun.gupt 140
 
141
class Coupon(Entity):
142
    coupon_code = Field(String(20))
143
    promotion = ManyToOne("Promotion")
144
    arguments = Field(String(200))
8707 manish.sha 145
    coupon_category = Field(Enum('CUSTOMER_SATISFACTION','MARKETING','REFUND'))
1976 varun.gupt 146
    using_options(shortnames = True)
147
    using_table_options(mysql_engine = "InnoDB")
148
 
149
class PromotionTracker(Entity):
150
    coupon_code = Field(String(20))
151
    transaction_id = Field(Integer)
152
    user_id = Field(Integer)
153
    applied_on = Field(DateTime)
7987 amit.gupta 154
    promotion_id = Field(Integer)
1976 varun.gupt 155
    using_options(shortnames = True)
156
    using_table_options(mysql_engine = "InnoDB")
5469 rajveer 157
 
158
class RechargeVoucher(Entity):
159
    id = Field(Integer, primary_key = True, autoincrement = True)
160
    voucherCode = Field(String(30))
161
    voucherType = Field(Integer)
162
    amount = Field(Numeric(precision=8, scale=2, asdecimal=False))
163
    available = Field(Boolean)
164
    issuedOn = Field(DateTime)
165
    expiredOn = Field(DateTime)
166
    redeemed = Field(Boolean)
167
    redeemedOn = Field(DateTime)
168
    email = Field(String(100))
169
    userId = Field(Integer)
170
    using_options(shortnames = True)
171
    using_table_options(mysql_engine = "InnoDB")
1976 varun.gupt 172
 
173
#===============================================================================
1273 varun.gupt 174
# Entity generated from Contact Us form
175
#===============================================================================
176
class UserCommunication(Entity):
177
    id = Field(Integer, primary_key = True, autoincrement = True)
178
    user_id = Field(Integer)
179
    communication_type = Field(Integer)
180
    order_id = Field(Integer)
181
    airwaybill_no = Field(String(50))
182
    reply_to = Field(String(50))
183
    product_name = Field(String(200))
184
    subject = Field(String(200))
185
    message = Field(String(600))
1301 varun.gupt 186
    communication_timestamp = Field(DateTime)
1273 varun.gupt 187
    using_options(shortnames = True)
188
    using_table_options(mysql_engine = "InnoDB")
189
 
190
#===============================================================================
557 chandransh 191
# Different entities for the Widget service
192
#===============================================================================
193
 
2981 rajveer 194
class UserWidgetItem(Entity):
195
    userId = Field(Integer, primary_key=True)
196
    widgetId = Field(Integer, primary_key=True)
197
    itemId = Field(Integer, primary_key=True)
198
    addedOn = Field(DateTime)
557 chandransh 199
    using_options(shortnames=True)    
746 rajveer 200
    using_table_options(mysql_engine="InnoDB")
130 ashish 201
 
1845 vikas 202
class MasterAffiliate(Entity):
203
    id = Field(Integer, primary_key=True, autoincrement=True)
204
    name = Field(String(100), unique=True)
1859 vikas 205
    added_on = Field(DateTime)
1845 vikas 206
    affiliates = OneToMany("Affiliate")
207
    using_options(shortnames=True)
208
    using_table_options(mysql_engine="InnoDB")
209
 
210
class Affiliate(Entity):
211
    id = Field(Integer, primary_key=True, autoincrement=True)
212
    master_affiliate = ManyToOne("MasterAffiliate")
213
    name = Field(String(100), unique=True)
214
    url = Field(String(200))
1859 vikas 215
    added_on = Field(DateTime)
1996 vikas 216
    tracklogs = OneToMany("TrackLog")
1845 vikas 217
    using_options(shortnames=True)
218
    using_table_options(mysql_engine="InnoDB")
219
 
220
class Tracker(Entity):
221
    id = Field(Integer, primary_key=True, autoincrement=True)
2004 vikas 222
    affiliate_id = Field(Integer)
223
    added_on = Field(DateTime)
1845 vikas 224
    using_options(shortnames=True)
225
    using_table_options(mysql_engine="InnoDB")
226
 
227
class TrackLog(Entity):
228
    id = Field(Integer, primary_key=True, autoincrement=True)
1859 vikas 229
    added_on = Field(DateTime)
1996 vikas 230
    affiliate = ManyToOne("Affiliate")
1845 vikas 231
    user_id = Field(Integer)
232
    event = Field(String(100))
3378 vikas 233
    event_id = Field(Integer)
1845 vikas 234
    url = Field(String(200))
235
    data = Field(String(200))
236
    using_options(shortnames=True)
237
    using_table_options(mysql_engine="InnoDB")
238
 
6903 anupam.sin 239
class InsuranceDetails(Entity):
240
    id = Field(Integer, primary_key=True, autoincrement=True)
241
    addressId = Field(Integer)
242
    dob = Field(String(64))
243
    guardianName = Field(String(255))
244
    using_options(shortnames=True)
245
    using_table_options(mysql_engine="InnoDB")
12696 amit.gupta 246
 
247
class Counter(Entity):
248
    id = Field(Integer, primary_key=True, autoincrement=True)
249
    code = Field(String(10),unique=True)
250
    dealUsers = OneToMany("PrivateDealUser")
251
    name = Field(String(128))
252
    ownerName = Field(String(100))
253
    email = Field(String(80))
254
    mobile = Field(String(10))
255
    alternateMobile = Field(String(10))
256
    addressId = Field(Integer)
257
    striker = Field(Boolean)
258
    tin = Field(String(20), unique=True)
259
    spCounterSize = Field(Integer)
260
    fpCounterSize = Field(Integer)
261
    createdOn = Field(DateTime)
262
    using_options(shortnames=True)
263
    using_table_options(mysql_engine="InnoDB")
6903 anupam.sin 264
 
3187 rajveer 265
def initialize(dbname='user', db_hostname="localhost"):
772 rajveer 266
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
5283 mandeep.dh 267
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200, max_overflow=20)
1122 chandransh 268
    metadata.bind = engine
772 rajveer 269
    metadata.bind.echo = True
270
    setup_all(True)
271
 
272
if __name__=="__main__":
273
    initialize()