Subversion Repositories SmartDukaan

Rev

Rev 2815 | Rev 3187 | 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))
2020 vikas 106
    source = Field(String(200))
2815 vikas 107
    source_start_time = Field(DateTime)
130 ashish 108
    addresses = OneToMany("Address")
109
    social_handles = OneToMany("SocialHandle")
557 chandransh 110
    using_options(shortnames=True)
746 rajveer 111
    using_table_options(mysql_engine="InnoDB")
557 chandransh 112
 
113
class Line(Entity):
643 chandransh 114
    cart = ManyToOne("Cart", primary_key=True)
746 rajveer 115
    item_id = Field(Integer, primary_key=True, autoincrement=False)
557 chandransh 116
    quantity = Field(Float)
117
    line_status = Field(Integer)
612 chandransh 118
    estimate = Field(Integer)
557 chandransh 119
    created_on = Field(DateTime)
120
    updated_on = Field(DateTime)
1976 varun.gupt 121
    actual_price = Field(Float)
122
    discounted_price = Field(Float)
557 chandransh 123
    using_options(shortnames=True)
746 rajveer 124
    using_table_options(mysql_engine="InnoDB")
504 rajveer 125
 
557 chandransh 126
class Cart(Entity):
130 ashish 127
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 128
    user_id = Field(Integer)
129
    cart_status = Field(Integer)
130
    address_id = Field(Integer)
690 chandransh 131
    checked_out_on = Field(DateTime)
557 chandransh 132
    created_on = Field(DateTime)
133
    updated_on = Field(DateTime)
564 chandransh 134
    lines = OneToMany("Line")
1976 varun.gupt 135
    total_price = Field(Float)
136
    discounted_price = Field(Float)
137
    coupon_code = Field(String(20))
557 chandransh 138
    using_options(shortnames=True)
746 rajveer 139
    using_table_options(mysql_engine="InnoDB")
130 ashish 140
 
557 chandransh 141
#===============================================================================
1976 varun.gupt 142
# Entity generated from Promotion Service
143
#===============================================================================
144
class Promotion(Entity):
145
    id = Field(Integer, primary_key = True, autoincrement = True)
146
    name = Field(String(200))
147
    rule_execution_src = Field(String(100))
148
    start_on = Field(DateTime)
149
    end_on = Field(DateTime)
150
    coupons = OneToMany("Coupon")
151
    created_on = Field(DateTime)
152
    using_options(shortnames = True)
153
    using_table_options(mysql_engine = "InnoDB")
154
 
155
class Coupon(Entity):
156
    coupon_code = Field(String(20))
157
    promotion = ManyToOne("Promotion")
158
    arguments = Field(String(200))
159
    using_options(shortnames = True)
160
    using_table_options(mysql_engine = "InnoDB")
161
 
162
class PromotionTracker(Entity):
163
    coupon_code = Field(String(20))
164
    transaction_id = Field(Integer)
165
    user_id = Field(Integer)
166
    applied_on = Field(DateTime)
167
    using_options(shortnames = True)
168
    using_table_options(mysql_engine = "InnoDB")
169
 
170
#===============================================================================
1273 varun.gupt 171
# Entity generated from Contact Us form
172
#===============================================================================
173
class UserCommunication(Entity):
174
    id = Field(Integer, primary_key = True, autoincrement = True)
175
    user_id = Field(Integer)
176
    communication_type = Field(Integer)
177
    order_id = Field(Integer)
178
    airwaybill_no = Field(String(50))
179
    reply_to = Field(String(50))
180
    product_name = Field(String(200))
181
    subject = Field(String(200))
182
    message = Field(String(600))
1301 varun.gupt 183
    communication_timestamp = Field(DateTime)
1273 varun.gupt 184
    using_options(shortnames = True)
185
    using_table_options(mysql_engine = "InnoDB")
186
 
187
#===============================================================================
557 chandransh 188
# Different entities for the Widget service
189
#===============================================================================
190
 
2981 rajveer 191
class UserWidgetItem(Entity):
192
    userId = Field(Integer, primary_key=True)
193
    widgetId = Field(Integer, primary_key=True)
194
    itemId = Field(Integer, primary_key=True)
195
    addedOn = Field(DateTime)
557 chandransh 196
    using_options(shortnames=True)    
746 rajveer 197
    using_table_options(mysql_engine="InnoDB")
130 ashish 198
 
1845 vikas 199
class MasterAffiliate(Entity):
200
    id = Field(Integer, primary_key=True, autoincrement=True)
201
    name = Field(String(100), unique=True)
1859 vikas 202
    added_on = Field(DateTime)
1845 vikas 203
    affiliates = OneToMany("Affiliate")
204
    using_options(shortnames=True)
205
    using_table_options(mysql_engine="InnoDB")
206
 
207
class Affiliate(Entity):
208
    id = Field(Integer, primary_key=True, autoincrement=True)
209
    master_affiliate = ManyToOne("MasterAffiliate")
210
    name = Field(String(100), unique=True)
211
    url = Field(String(200))
1859 vikas 212
    added_on = Field(DateTime)
1996 vikas 213
    tracklogs = OneToMany("TrackLog")
1845 vikas 214
    using_options(shortnames=True)
215
    using_table_options(mysql_engine="InnoDB")
216
 
217
class Tracker(Entity):
218
    id = Field(Integer, primary_key=True, autoincrement=True)
2004 vikas 219
    affiliate_id = Field(Integer)
220
    added_on = Field(DateTime)
1845 vikas 221
    using_options(shortnames=True)
222
    using_table_options(mysql_engine="InnoDB")
223
 
224
class TrackLog(Entity):
225
    id = Field(Integer, primary_key=True, autoincrement=True)
1859 vikas 226
    added_on = Field(DateTime)
1996 vikas 227
    affiliate = ManyToOne("Affiliate")
1845 vikas 228
    user_id = Field(Integer)
229
    event = Field(String(100))
230
    url = Field(String(200))
231
    data = Field(String(200))
232
    using_options(shortnames=True)
233
    using_table_options(mysql_engine="InnoDB")
234
 
2641 varun.gupt 235
class UserNote(Entity):
236
    user_id = Field(Integer)
237
    entity_id = Field(Integer)
2717 varun.gupt 238
    slide = Field(String(30))
2641 varun.gupt 239
    note = Field(String(500))
240
    using_options(shortnames=True)
241
    using_table_options(mysql_engine="InnoDB")
242
 
1249 chandransh 243
def initialize(dbname='user'):
772 rajveer 244
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
1249 chandransh 245
    engine = create_engine('mysql://root:shop2020@localhost/' + dbname, pool_recycle=7200)
1122 chandransh 246
    metadata.bind = engine
772 rajveer 247
    metadata.bind.echo = True
248
    setup_all(True)
249
 
250
if __name__=="__main__":
251
    initialize()