Subversion Repositories SmartDukaan

Rev

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