Subversion Repositories SmartDukaan

Rev

Rev 1859 | Rev 1996 | 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 SocialService(Entity):
17
    id = Field(Integer, primary_key=True, autoincrement=True)
18
    name = Field(String(100))
19
    handles = OneToMany("SocialHandle")
557 chandransh 20
    using_options(shortnames=True)
746 rajveer 21
    using_table_options(mysql_engine="InnoDB")
22
 
130 ashish 23
class SocialHandle(Entity):
24
    id = Field(Integer, primary_key=True, autoincrement=True)
25
    handle = Field(String(100))
26
    service = ManyToOne("SocialService")
557 chandransh 27
    user = ManyToOne("User")
28
    using_options(shortnames=True)
746 rajveer 29
    using_table_options(mysql_engine="InnoDB")
557 chandransh 30
 
130 ashish 31
class Address(Entity):
32
    id = Field(Integer, primary_key=True, autoincrement=True)
33
    line_1 = Field(String(100))
34
    line_2 = Field(String(100))
35
    landmark = Field(String(100))
36
    city = Field(String(100))
37
    state = Field(String(100))
38
    pin = Field(String(10))
39
    country = Field(String(100))
40
    enabled = Field(Boolean)
41
    type = Field(Integer)
42
    added_on = Field(DateTime)
414 ashish 43
    name = Field(String(100))
44
    phone = Field(String(20))
557 chandransh 45
    user = ManyToOne("User")
46
    using_options(shortnames=True)
746 rajveer 47
    using_table_options(mysql_engine="InnoDB")
557 chandransh 48
 
130 ashish 49
class Phone(Entity):
50
    id = Field(Integer, primary_key=True, autoincrement=True)
51
    country_code = Field(String(5))
52
    area_code = Field(String(10))
53
    number = Field(String(20))
54
    extension = Field(String(10))
55
    type = Field(Integer)
557 chandransh 56
    user = ManyToOne("User")
57
    using_options(shortnames=True)
746 rajveer 58
    using_table_options(mysql_engine="InnoDB")
130 ashish 59
 
557 chandransh 60
class InternalInfo(Entity):
130 ashish 61
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 62
    geo_zone = Field(Integer)
63
    shipment_zone = Field(Integer)
64
    tax_zone = Field(Integer)
65
    rank_score = Field(Float)
66
    user = ManyToOne("User")
67
    using_options(shortnames=True)
746 rajveer 68
    using_table_options(mysql_engine="InnoDB")
557 chandransh 69
 
130 ashish 70
class IPMap(Entity):
71
    id = Field(Integer, primary_key=True, autoincrement=True)
72
    timestamp = Field(DateTime)
73
    ip = Field(String(30))
557 chandransh 74
    user_state = ManyToOne("UserState")
75
    using_options(shortnames=True)
746 rajveer 76
    using_table_options(mysql_engine="InnoDB")
557 chandransh 77
 
78
class UserState(Entity):
130 ashish 79
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 80
    last_login = Field(DateTime)
81
    last_logout = Field(DateTime)
82
    email_verification_sent_on = Field(DateTime)
83
    sms_verification_sent_on = Field(DateTime)
84
    is_email_verified = Field(Boolean)
85
    is_sms_verified =Field(Boolean)
86
    active_since = Field(DateTime)
87
    account_status = Field(Integer)
88
    ip_list = OneToMany("IPMap")
89
    user = ManyToOne("User")
90
    using_options(shortnames=True)
746 rajveer 91
    using_table_options(mysql_engine="InnoDB")
557 chandransh 92
 
93
class User(Entity):
94
    id = Field(Integer, primary_key=True, autoincrement=True)
130 ashish 95
    email = Field(String(100))
96
    password = Field(String(50))
557 chandransh 97
    name = Field(String(150))
504 rajveer 98
    default_address_id = Field(Integer)
99
    communication_email = Field(String(100))
557 chandransh 100
    active_cart_id = Field(Integer)
101
    jsession_id = Field(String(64))
102
    is_anonymous = Field(Boolean)
567 rajveer 103
    date_of_birth = Field(String(20))
557 chandransh 104
    sex = Field(Integer)
567 rajveer 105
    mobile_number = Field(String(20))
130 ashish 106
    addresses = OneToMany("Address")
107
    social_handles = OneToMany("SocialHandle")
557 chandransh 108
    using_options(shortnames=True)
746 rajveer 109
    using_table_options(mysql_engine="InnoDB")
557 chandransh 110
 
111
class Line(Entity):
643 chandransh 112
    cart = ManyToOne("Cart", primary_key=True)
746 rajveer 113
    item_id = Field(Integer, primary_key=True, autoincrement=False)
557 chandransh 114
    quantity = Field(Float)
115
    line_status = Field(Integer)
612 chandransh 116
    estimate = Field(Integer)
557 chandransh 117
    created_on = Field(DateTime)
118
    updated_on = Field(DateTime)
1976 varun.gupt 119
    actual_price = Field(Float)
120
    discounted_price = Field(Float)
557 chandransh 121
    using_options(shortnames=True)
746 rajveer 122
    using_table_options(mysql_engine="InnoDB")
504 rajveer 123
 
557 chandransh 124
class Cart(Entity):
130 ashish 125
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 126
    user_id = Field(Integer)
127
    cart_status = Field(Integer)
128
    address_id = Field(Integer)
690 chandransh 129
    checked_out_on = Field(DateTime)
557 chandransh 130
    created_on = Field(DateTime)
131
    updated_on = Field(DateTime)
564 chandransh 132
    lines = OneToMany("Line")
1976 varun.gupt 133
    total_price = Field(Float)
134
    discounted_price = Field(Float)
135
    coupon_code = Field(String(20))
557 chandransh 136
    using_options(shortnames=True)
746 rajveer 137
    using_table_options(mysql_engine="InnoDB")
130 ashish 138
 
557 chandransh 139
#===============================================================================
1976 varun.gupt 140
# Entity generated from Promotion Service
141
#===============================================================================
142
class Promotion(Entity):
143
    id = Field(Integer, primary_key = True, autoincrement = True)
144
    name = Field(String(200))
145
    rule_execution_src = Field(String(100))
146
    start_on = Field(DateTime)
147
    end_on = Field(DateTime)
148
    coupons = OneToMany("Coupon")
149
    created_on = Field(DateTime)
150
    using_options(shortnames = True)
151
    using_table_options(mysql_engine = "InnoDB")
152
 
153
class Coupon(Entity):
154
    coupon_code = Field(String(20))
155
    promotion = ManyToOne("Promotion")
156
    arguments = Field(String(200))
157
    using_options(shortnames = True)
158
    using_table_options(mysql_engine = "InnoDB")
159
 
160
class PromotionTracker(Entity):
161
    coupon_code = Field(String(20))
162
    transaction_id = Field(Integer)
163
    user_id = Field(Integer)
164
    applied_on = Field(DateTime)
165
    using_options(shortnames = True)
166
    using_table_options(mysql_engine = "InnoDB")
167
 
168
#===============================================================================
1273 varun.gupt 169
# Entity generated from Contact Us form
170
#===============================================================================
171
class UserCommunication(Entity):
172
    id = Field(Integer, primary_key = True, autoincrement = True)
173
    user_id = Field(Integer)
174
    communication_type = Field(Integer)
175
    order_id = Field(Integer)
176
    airwaybill_no = Field(String(50))
177
    reply_to = Field(String(50))
178
    product_name = Field(String(200))
179
    subject = Field(String(200))
180
    message = Field(String(600))
1301 varun.gupt 181
    communication_timestamp = Field(DateTime)
1273 varun.gupt 182
    using_options(shortnames = True)
183
    using_table_options(mysql_engine = "InnoDB")
184
 
185
#===============================================================================
557 chandransh 186
# Different entities for the Widget service
187
#===============================================================================
188
 
189
class Widget(Entity):
130 ashish 190
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 191
    type = Field(Integer)
772 rajveer 192
    user_id = Field(Integer)
557 chandransh 193
    name = Field(String(100))
772 rajveer 194
    enabled = Field(Boolean)
557 chandransh 195
    items = OneToMany("WidgetItem")
196
    using_options(shortnames=True)
746 rajveer 197
    using_table_options(mysql_engine="InnoDB")
130 ashish 198
 
557 chandransh 199
class WidgetItem(Entity):
130 ashish 200
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 201
    added_on = Field(DateTime)
202
    item = ManyToOne("Item")
203
    widget = ManyToOne("Widget")
204
    using_options(shortnames=True)    
746 rajveer 205
    using_table_options(mysql_engine="InnoDB")
130 ashish 206
 
557 chandransh 207
class Item(Entity):
208
    id = Field(Integer, primary_key=True, autoincrement=True)
209
    item_id = Field(Integer)
772 rajveer 210
    enabled = Field(Boolean)
557 chandransh 211
    widget_items=OneToMany("WidgetItem")
212
    using_options(shortnames=True)
746 rajveer 213
    using_table_options(mysql_engine="InnoDB")
557 chandransh 214
 
1845 vikas 215
class MasterAffiliate(Entity):
216
    id = Field(Integer, primary_key=True, autoincrement=True)
217
    name = Field(String(100), unique=True)
1859 vikas 218
    added_on = Field(DateTime)
1845 vikas 219
    affiliates = OneToMany("Affiliate")
220
    using_options(shortnames=True)
221
    using_table_options(mysql_engine="InnoDB")
222
 
223
class Affiliate(Entity):
224
    id = Field(Integer, primary_key=True, autoincrement=True)
225
    master_affiliate = ManyToOne("MasterAffiliate")
226
    name = Field(String(100), unique=True)
227
    url = Field(String(200))
1859 vikas 228
    added_on = Field(DateTime)
1845 vikas 229
    trackers = OneToMany("Tracker")
230
    using_options(shortnames=True)
231
    using_table_options(mysql_engine="InnoDB")
232
 
233
class Tracker(Entity):
234
    id = Field(Integer, primary_key=True, autoincrement=True)
1859 vikas 235
    added_on = Field(DateTime)
1845 vikas 236
    affiliate = ManyToOne("Affiliate")
237
    tracklogs = OneToMany("TrackLog")
238
    using_options(shortnames=True)
239
    using_table_options(mysql_engine="InnoDB")
240
 
241
class TrackLog(Entity):
242
    id = Field(Integer, primary_key=True, autoincrement=True)
1859 vikas 243
    added_on = Field(DateTime)
1845 vikas 244
    tracker = ManyToOne("Tracker")
245
    user_id = Field(Integer)
246
    event = Field(String(100))
247
    url = Field(String(200))
248
    data = Field(String(200))
249
    using_options(shortnames=True)
250
    using_table_options(mysql_engine="InnoDB")
251
 
1249 chandransh 252
def initialize(dbname='user'):
772 rajveer 253
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
1249 chandransh 254
    engine = create_engine('mysql://root:shop2020@localhost/' + dbname, pool_recycle=7200)
1122 chandransh 255
    metadata.bind = engine
772 rajveer 256
    metadata.bind.echo = True
257
    setup_all(True)
258
 
259
if __name__=="__main__":
260
    initialize()
261
 
262
 
263
'''
557 chandransh 264
class Ratings(Entity):
265
    id = Field(Integer, primary_key=True, autoincrement=True)
266
    item_id = Field(Integer)
267
    type = Field(Integer)
268
    rating = Field(Float)
269
    using_options(shortnames=True)
746 rajveer 270
    using_table_options(mysql_engine="InnoDB")
557 chandransh 271
 
272
class UserRatings(Entity):
273
    id = Field(Integer, primary_key=True, autoincrement=True)
274
    item_id = Field(Integer)
275
    rating = Field(Float)
276
    user_id = Field(Integer)
277
    using_options(shortnames=True)
746 rajveer 278
    using_table_options(mysql_engine="InnoDB")
772 rajveer 279
'''