Subversion Repositories SmartDukaan

Rev

Rev 746 | Rev 1122 | 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
10
from sqlalchemy.types import Integer
11
from elixir.relationships import OneToMany, ManyToOne
12
import datetime
746 rajveer 13
import elixir
130 ashish 14
 
15
class SocialService(Entity):
16
    id = Field(Integer, primary_key=True, autoincrement=True)
17
    name = Field(String(100))
18
    handles = OneToMany("SocialHandle")
557 chandransh 19
    using_options(shortnames=True)
746 rajveer 20
    using_table_options(mysql_engine="InnoDB")
21
 
130 ashish 22
class SocialHandle(Entity):
23
    id = Field(Integer, primary_key=True, autoincrement=True)
24
    handle = Field(String(100))
25
    service = ManyToOne("SocialService")
557 chandransh 26
    user = ManyToOne("User")
27
    using_options(shortnames=True)
746 rajveer 28
    using_table_options(mysql_engine="InnoDB")
557 chandransh 29
 
130 ashish 30
class Address(Entity):
31
    id = Field(Integer, primary_key=True, autoincrement=True)
32
    line_1 = Field(String(100))
33
    line_2 = Field(String(100))
34
    landmark = Field(String(100))
35
    city = Field(String(100))
36
    state = Field(String(100))
37
    pin = Field(String(10))
38
    country = Field(String(100))
39
    enabled = Field(Boolean)
40
    type = Field(Integer)
41
    added_on = Field(DateTime)
414 ashish 42
    name = Field(String(100))
43
    phone = Field(String(20))
557 chandransh 44
    user = ManyToOne("User")
45
    using_options(shortnames=True)
746 rajveer 46
    using_table_options(mysql_engine="InnoDB")
557 chandransh 47
 
130 ashish 48
class Phone(Entity):
49
    id = Field(Integer, primary_key=True, autoincrement=True)
50
    country_code = Field(String(5))
51
    area_code = Field(String(10))
52
    number = Field(String(20))
53
    extension = Field(String(10))
54
    type = Field(Integer)
557 chandransh 55
    user = ManyToOne("User")
56
    using_options(shortnames=True)
746 rajveer 57
    using_table_options(mysql_engine="InnoDB")
130 ashish 58
 
557 chandransh 59
class InternalInfo(Entity):
130 ashish 60
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 61
    geo_zone = Field(Integer)
62
    shipment_zone = Field(Integer)
63
    tax_zone = Field(Integer)
64
    rank_score = Field(Float)
65
    user = ManyToOne("User")
66
    using_options(shortnames=True)
746 rajveer 67
    using_table_options(mysql_engine="InnoDB")
557 chandransh 68
 
130 ashish 69
class IPMap(Entity):
70
    id = Field(Integer, primary_key=True, autoincrement=True)
71
    timestamp = Field(DateTime)
72
    ip = Field(String(30))
557 chandransh 73
    user_state = ManyToOne("UserState")
74
    using_options(shortnames=True)
746 rajveer 75
    using_table_options(mysql_engine="InnoDB")
557 chandransh 76
 
77
class UserState(Entity):
130 ashish 78
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 79
    last_login = Field(DateTime)
80
    last_logout = Field(DateTime)
81
    email_verification_sent_on = Field(DateTime)
82
    sms_verification_sent_on = Field(DateTime)
83
    is_email_verified = Field(Boolean)
84
    is_sms_verified =Field(Boolean)
85
    active_since = Field(DateTime)
86
    account_status = Field(Integer)
87
    ip_list = OneToMany("IPMap")
88
    user = ManyToOne("User")
89
    using_options(shortnames=True)
746 rajveer 90
    using_table_options(mysql_engine="InnoDB")
557 chandransh 91
 
92
class User(Entity):
93
    id = Field(Integer, primary_key=True, autoincrement=True)
130 ashish 94
    email = Field(String(100))
95
    password = Field(String(50))
557 chandransh 96
    name = Field(String(150))
504 rajveer 97
    default_address_id = Field(Integer)
98
    communication_email = Field(String(100))
557 chandransh 99
    active_cart_id = Field(Integer)
100
    jsession_id = Field(String(64))
101
    is_anonymous = Field(Boolean)
567 rajveer 102
    date_of_birth = Field(String(20))
557 chandransh 103
    sex = Field(Integer)
567 rajveer 104
    mobile_number = Field(String(20))
130 ashish 105
    addresses = OneToMany("Address")
106
    social_handles = OneToMany("SocialHandle")
557 chandransh 107
    using_options(shortnames=True)
746 rajveer 108
    using_table_options(mysql_engine="InnoDB")
557 chandransh 109
 
110
class Line(Entity):
643 chandransh 111
    cart = ManyToOne("Cart", primary_key=True)
746 rajveer 112
    item_id = Field(Integer, primary_key=True, autoincrement=False)
557 chandransh 113
    quantity = Field(Float)
114
    line_status = Field(Integer)
612 chandransh 115
    estimate = Field(Integer)
557 chandransh 116
    created_on = Field(DateTime)
117
    updated_on = Field(DateTime)
118
    using_options(shortnames=True)
746 rajveer 119
    using_table_options(mysql_engine="InnoDB")
504 rajveer 120
 
557 chandransh 121
class Cart(Entity):
130 ashish 122
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 123
    user_id = Field(Integer)
124
    cart_status = Field(Integer)
125
    address_id = Field(Integer)
690 chandransh 126
    checked_out_on = Field(DateTime)
557 chandransh 127
    created_on = Field(DateTime)
128
    updated_on = Field(DateTime)
564 chandransh 129
    lines = OneToMany("Line")
557 chandransh 130
    using_options(shortnames=True)
746 rajveer 131
    using_table_options(mysql_engine="InnoDB")
130 ashish 132
 
557 chandransh 133
#===============================================================================
134
# Different entities for the Widget service
135
#===============================================================================
136
 
137
class Widget(Entity):
130 ashish 138
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 139
    type = Field(Integer)
772 rajveer 140
    user_id = Field(Integer)
557 chandransh 141
    name = Field(String(100))
772 rajveer 142
    enabled = Field(Boolean)
557 chandransh 143
    items = OneToMany("WidgetItem")
144
    using_options(shortnames=True)
746 rajveer 145
    using_table_options(mysql_engine="InnoDB")
130 ashish 146
 
557 chandransh 147
class WidgetItem(Entity):
130 ashish 148
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 149
    added_on = Field(DateTime)
150
    item = ManyToOne("Item")
151
    widget = ManyToOne("Widget")
152
    using_options(shortnames=True)    
746 rajveer 153
    using_table_options(mysql_engine="InnoDB")
130 ashish 154
 
557 chandransh 155
class Item(Entity):
156
    id = Field(Integer, primary_key=True, autoincrement=True)
157
    item_id = Field(Integer)
772 rajveer 158
    enabled = Field(Boolean)
557 chandransh 159
    widget_items=OneToMany("WidgetItem")
160
    using_options(shortnames=True)
746 rajveer 161
    using_table_options(mysql_engine="InnoDB")
557 chandransh 162
 
772 rajveer 163
def initialize():
164
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
165
    metadata.bind = 'mysql://root:shop2020@localhost/user'
166
    metadata.bind.echo = True
167
    setup_all(True)
168
 
169
if __name__=="__main__":
170
    initialize()
171
 
172
 
173
'''
557 chandransh 174
class Ratings(Entity):
175
    id = Field(Integer, primary_key=True, autoincrement=True)
176
    item_id = Field(Integer)
177
    type = Field(Integer)
178
    rating = Field(Float)
179
    using_options(shortnames=True)
746 rajveer 180
    using_table_options(mysql_engine="InnoDB")
557 chandransh 181
 
182
class UserRatings(Entity):
183
    id = Field(Integer, primary_key=True, autoincrement=True)
184
    item_id = Field(Integer)
185
    rating = Field(Float)
186
    user_id = Field(Integer)
187
    using_options(shortnames=True)
746 rajveer 188
    using_table_options(mysql_engine="InnoDB")
772 rajveer 189
'''