Subversion Repositories SmartDukaan

Rev

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