Subversion Repositories SmartDukaan

Rev

Rev 1273 | Rev 1845 | 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)
119
    using_options(shortnames=True)
746 rajveer 120
    using_table_options(mysql_engine="InnoDB")
504 rajveer 121
 
557 chandransh 122
class Cart(Entity):
130 ashish 123
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 124
    user_id = Field(Integer)
125
    cart_status = Field(Integer)
126
    address_id = Field(Integer)
690 chandransh 127
    checked_out_on = Field(DateTime)
557 chandransh 128
    created_on = Field(DateTime)
129
    updated_on = Field(DateTime)
564 chandransh 130
    lines = OneToMany("Line")
557 chandransh 131
    using_options(shortnames=True)
746 rajveer 132
    using_table_options(mysql_engine="InnoDB")
130 ashish 133
 
557 chandransh 134
#===============================================================================
1273 varun.gupt 135
# Entity generated from Contact Us form
136
#===============================================================================
137
class UserCommunication(Entity):
138
    id = Field(Integer, primary_key = True, autoincrement = True)
139
    user_id = Field(Integer)
140
    communication_type = Field(Integer)
141
    order_id = Field(Integer)
142
    airwaybill_no = Field(String(50))
143
    reply_to = Field(String(50))
144
    product_name = Field(String(200))
145
    subject = Field(String(200))
146
    message = Field(String(600))
1301 varun.gupt 147
    communication_timestamp = Field(DateTime)
1273 varun.gupt 148
    using_options(shortnames = True)
149
    using_table_options(mysql_engine = "InnoDB")
150
 
151
#===============================================================================
557 chandransh 152
# Different entities for the Widget service
153
#===============================================================================
154
 
155
class Widget(Entity):
130 ashish 156
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 157
    type = Field(Integer)
772 rajveer 158
    user_id = Field(Integer)
557 chandransh 159
    name = Field(String(100))
772 rajveer 160
    enabled = Field(Boolean)
557 chandransh 161
    items = OneToMany("WidgetItem")
162
    using_options(shortnames=True)
746 rajveer 163
    using_table_options(mysql_engine="InnoDB")
130 ashish 164
 
557 chandransh 165
class WidgetItem(Entity):
130 ashish 166
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 167
    added_on = Field(DateTime)
168
    item = ManyToOne("Item")
169
    widget = ManyToOne("Widget")
170
    using_options(shortnames=True)    
746 rajveer 171
    using_table_options(mysql_engine="InnoDB")
130 ashish 172
 
557 chandransh 173
class Item(Entity):
174
    id = Field(Integer, primary_key=True, autoincrement=True)
175
    item_id = Field(Integer)
772 rajveer 176
    enabled = Field(Boolean)
557 chandransh 177
    widget_items=OneToMany("WidgetItem")
178
    using_options(shortnames=True)
746 rajveer 179
    using_table_options(mysql_engine="InnoDB")
557 chandransh 180
 
1249 chandransh 181
def initialize(dbname='user'):
772 rajveer 182
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
1249 chandransh 183
    engine = create_engine('mysql://root:shop2020@localhost/' + dbname, pool_recycle=7200)
1122 chandransh 184
    metadata.bind = engine
772 rajveer 185
    metadata.bind.echo = True
186
    setup_all(True)
187
 
188
if __name__=="__main__":
189
    initialize()
190
 
191
 
192
'''
557 chandransh 193
class Ratings(Entity):
194
    id = Field(Integer, primary_key=True, autoincrement=True)
195
    item_id = Field(Integer)
196
    type = Field(Integer)
197
    rating = Field(Float)
198
    using_options(shortnames=True)
746 rajveer 199
    using_table_options(mysql_engine="InnoDB")
557 chandransh 200
 
201
class UserRatings(Entity):
202
    id = Field(Integer, primary_key=True, autoincrement=True)
203
    item_id = Field(Integer)
204
    rating = Field(Float)
205
    user_id = Field(Integer)
206
    using_options(shortnames=True)
746 rajveer 207
    using_table_options(mysql_engine="InnoDB")
772 rajveer 208
'''