Subversion Repositories SmartDukaan

Rev

Rev 5283 | Rev 5469 | 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)
690 chandransh 75
    checked_out_on = Field(DateTime)
557 chandransh 76
    created_on = Field(DateTime)
77
    updated_on = Field(DateTime)
564 chandransh 78
    lines = OneToMany("Line")
1976 varun.gupt 79
    total_price = Field(Float)
80
    discounted_price = Field(Float)
81
    coupon_code = Field(String(20))
5326 rajveer 82
    user = OneToMany("User")
557 chandransh 83
    using_options(shortnames=True)
746 rajveer 84
    using_table_options(mysql_engine="InnoDB")
130 ashish 85
 
3554 varun.gupt 86
class Discount(Entity):
87
    line = ManyToOne("Line", primary_key=True)
88
    discount = Field(Float, primary_key = True)
89
    quantity = Field(Float)
90
    using_options(shortnames = True)
91
    using_table_options(mysql_engine = 'InnoDB')
92
 
557 chandransh 93
#===============================================================================
1976 varun.gupt 94
# Entity generated from Promotion Service
95
#===============================================================================
96
class Promotion(Entity):
97
    id = Field(Integer, primary_key = True, autoincrement = True)
98
    name = Field(String(200))
99
    rule_execution_src = Field(String(100))
100
    start_on = Field(DateTime)
101
    end_on = Field(DateTime)
102
    coupons = OneToMany("Coupon")
103
    created_on = Field(DateTime)
104
    using_options(shortnames = True)
105
    using_table_options(mysql_engine = "InnoDB")
106
 
107
class Coupon(Entity):
108
    coupon_code = Field(String(20))
109
    promotion = ManyToOne("Promotion")
110
    arguments = Field(String(200))
111
    using_options(shortnames = True)
112
    using_table_options(mysql_engine = "InnoDB")
113
 
114
class PromotionTracker(Entity):
115
    coupon_code = Field(String(20))
116
    transaction_id = Field(Integer)
117
    user_id = Field(Integer)
118
    applied_on = Field(DateTime)
119
    using_options(shortnames = True)
120
    using_table_options(mysql_engine = "InnoDB")
121
 
122
#===============================================================================
1273 varun.gupt 123
# Entity generated from Contact Us form
124
#===============================================================================
125
class UserCommunication(Entity):
126
    id = Field(Integer, primary_key = True, autoincrement = True)
127
    user_id = Field(Integer)
128
    communication_type = Field(Integer)
129
    order_id = Field(Integer)
130
    airwaybill_no = Field(String(50))
131
    reply_to = Field(String(50))
132
    product_name = Field(String(200))
133
    subject = Field(String(200))
134
    message = Field(String(600))
1301 varun.gupt 135
    communication_timestamp = Field(DateTime)
1273 varun.gupt 136
    using_options(shortnames = True)
137
    using_table_options(mysql_engine = "InnoDB")
138
 
139
#===============================================================================
557 chandransh 140
# Different entities for the Widget service
141
#===============================================================================
142
 
2981 rajveer 143
class UserWidgetItem(Entity):
144
    userId = Field(Integer, primary_key=True)
145
    widgetId = Field(Integer, primary_key=True)
146
    itemId = Field(Integer, primary_key=True)
147
    addedOn = Field(DateTime)
557 chandransh 148
    using_options(shortnames=True)    
746 rajveer 149
    using_table_options(mysql_engine="InnoDB")
130 ashish 150
 
1845 vikas 151
class MasterAffiliate(Entity):
152
    id = Field(Integer, primary_key=True, autoincrement=True)
153
    name = Field(String(100), unique=True)
1859 vikas 154
    added_on = Field(DateTime)
1845 vikas 155
    affiliates = OneToMany("Affiliate")
156
    using_options(shortnames=True)
157
    using_table_options(mysql_engine="InnoDB")
158
 
159
class Affiliate(Entity):
160
    id = Field(Integer, primary_key=True, autoincrement=True)
161
    master_affiliate = ManyToOne("MasterAffiliate")
162
    name = Field(String(100), unique=True)
163
    url = Field(String(200))
1859 vikas 164
    added_on = Field(DateTime)
1996 vikas 165
    tracklogs = OneToMany("TrackLog")
1845 vikas 166
    using_options(shortnames=True)
167
    using_table_options(mysql_engine="InnoDB")
168
 
169
class Tracker(Entity):
170
    id = Field(Integer, primary_key=True, autoincrement=True)
2004 vikas 171
    affiliate_id = Field(Integer)
172
    added_on = Field(DateTime)
1845 vikas 173
    using_options(shortnames=True)
174
    using_table_options(mysql_engine="InnoDB")
175
 
176
class TrackLog(Entity):
177
    id = Field(Integer, primary_key=True, autoincrement=True)
1859 vikas 178
    added_on = Field(DateTime)
1996 vikas 179
    affiliate = ManyToOne("Affiliate")
1845 vikas 180
    user_id = Field(Integer)
181
    event = Field(String(100))
3378 vikas 182
    event_id = Field(Integer)
1845 vikas 183
    url = Field(String(200))
184
    data = Field(String(200))
185
    using_options(shortnames=True)
186
    using_table_options(mysql_engine="InnoDB")
187
 
2641 varun.gupt 188
class UserNote(Entity):
189
    user_id = Field(Integer)
190
    entity_id = Field(Integer)
2717 varun.gupt 191
    slide = Field(String(30))
2641 varun.gupt 192
    note = Field(String(500))
193
    using_options(shortnames=True)
194
    using_table_options(mysql_engine="InnoDB")
195
 
3187 rajveer 196
def initialize(dbname='user', db_hostname="localhost"):
772 rajveer 197
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
5283 mandeep.dh 198
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200, max_overflow=20)
1122 chandransh 199
    metadata.bind = engine
772 rajveer 200
    metadata.bind.echo = True
201
    setup_all(True)
202
 
203
if __name__=="__main__":
204
    initialize()