Subversion Repositories SmartDukaan

Rev

Rev 9300 | Rev 11657 | 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")
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)
134
    created_on = Field(DateTime)
135
    isActive = Field(Boolean)
1976 varun.gupt 136
 
137
class Coupon(Entity):
138
    coupon_code = Field(String(20))
139
    promotion = ManyToOne("Promotion")
140
    arguments = Field(String(200))
8707 manish.sha 141
    coupon_category = Field(Enum('CUSTOMER_SATISFACTION','MARKETING','REFUND'))
1976 varun.gupt 142
    using_options(shortnames = True)
143
    using_table_options(mysql_engine = "InnoDB")
144
 
145
class PromotionTracker(Entity):
146
    coupon_code = Field(String(20))
147
    transaction_id = Field(Integer)
148
    user_id = Field(Integer)
149
    applied_on = Field(DateTime)
7987 amit.gupta 150
    promotion_id = Field(Integer)
1976 varun.gupt 151
    using_options(shortnames = True)
152
    using_table_options(mysql_engine = "InnoDB")
5469 rajveer 153
 
154
class RechargeVoucher(Entity):
155
    id = Field(Integer, primary_key = True, autoincrement = True)
156
    voucherCode = Field(String(30))
157
    voucherType = Field(Integer)
158
    amount = Field(Numeric(precision=8, scale=2, asdecimal=False))
159
    available = Field(Boolean)
160
    issuedOn = Field(DateTime)
161
    expiredOn = Field(DateTime)
162
    redeemed = Field(Boolean)
163
    redeemedOn = Field(DateTime)
164
    email = Field(String(100))
165
    userId = Field(Integer)
166
    using_options(shortnames = True)
167
    using_table_options(mysql_engine = "InnoDB")
1976 varun.gupt 168
 
169
#===============================================================================
1273 varun.gupt 170
# Entity generated from Contact Us form
171
#===============================================================================
172
class UserCommunication(Entity):
173
    id = Field(Integer, primary_key = True, autoincrement = True)
174
    user_id = Field(Integer)
175
    communication_type = Field(Integer)
176
    order_id = Field(Integer)
177
    airwaybill_no = Field(String(50))
178
    reply_to = Field(String(50))
179
    product_name = Field(String(200))
180
    subject = Field(String(200))
181
    message = Field(String(600))
1301 varun.gupt 182
    communication_timestamp = Field(DateTime)
1273 varun.gupt 183
    using_options(shortnames = True)
184
    using_table_options(mysql_engine = "InnoDB")
185
 
186
#===============================================================================
557 chandransh 187
# Different entities for the Widget service
188
#===============================================================================
189
 
2981 rajveer 190
class UserWidgetItem(Entity):
191
    userId = Field(Integer, primary_key=True)
192
    widgetId = Field(Integer, primary_key=True)
193
    itemId = Field(Integer, primary_key=True)
194
    addedOn = Field(DateTime)
557 chandransh 195
    using_options(shortnames=True)    
746 rajveer 196
    using_table_options(mysql_engine="InnoDB")
130 ashish 197
 
1845 vikas 198
class MasterAffiliate(Entity):
199
    id = Field(Integer, primary_key=True, autoincrement=True)
200
    name = Field(String(100), unique=True)
1859 vikas 201
    added_on = Field(DateTime)
1845 vikas 202
    affiliates = OneToMany("Affiliate")
203
    using_options(shortnames=True)
204
    using_table_options(mysql_engine="InnoDB")
205
 
206
class Affiliate(Entity):
207
    id = Field(Integer, primary_key=True, autoincrement=True)
208
    master_affiliate = ManyToOne("MasterAffiliate")
209
    name = Field(String(100), unique=True)
210
    url = Field(String(200))
1859 vikas 211
    added_on = Field(DateTime)
1996 vikas 212
    tracklogs = OneToMany("TrackLog")
1845 vikas 213
    using_options(shortnames=True)
214
    using_table_options(mysql_engine="InnoDB")
215
 
216
class Tracker(Entity):
217
    id = Field(Integer, primary_key=True, autoincrement=True)
2004 vikas 218
    affiliate_id = Field(Integer)
219
    added_on = Field(DateTime)
1845 vikas 220
    using_options(shortnames=True)
221
    using_table_options(mysql_engine="InnoDB")
222
 
223
class TrackLog(Entity):
224
    id = Field(Integer, primary_key=True, autoincrement=True)
1859 vikas 225
    added_on = Field(DateTime)
1996 vikas 226
    affiliate = ManyToOne("Affiliate")
1845 vikas 227
    user_id = Field(Integer)
228
    event = Field(String(100))
3378 vikas 229
    event_id = Field(Integer)
1845 vikas 230
    url = Field(String(200))
231
    data = Field(String(200))
232
    using_options(shortnames=True)
233
    using_table_options(mysql_engine="InnoDB")
234
 
6903 anupam.sin 235
class InsuranceDetails(Entity):
236
    id = Field(Integer, primary_key=True, autoincrement=True)
237
    addressId = Field(Integer)
238
    dob = Field(String(64))
239
    guardianName = Field(String(255))
240
    using_options(shortnames=True)
241
    using_table_options(mysql_engine="InnoDB")
242
 
3187 rajveer 243
def initialize(dbname='user', db_hostname="localhost"):
772 rajveer 244
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
5283 mandeep.dh 245
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200, max_overflow=20)
1122 chandransh 246
    metadata.bind = engine
772 rajveer 247
    metadata.bind.echo = True
248
    setup_all(True)
249
 
250
if __name__=="__main__":
251
    initialize()