Subversion Repositories SmartDukaan

Rev

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