Subversion Repositories SmartDukaan

Rev

Rev 772 | Rev 1249 | 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
#===============================================================================
135
# Different entities for the Widget service
136
#===============================================================================
137
 
138
class Widget(Entity):
130 ashish 139
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 140
    type = Field(Integer)
772 rajveer 141
    user_id = Field(Integer)
557 chandransh 142
    name = Field(String(100))
772 rajveer 143
    enabled = Field(Boolean)
557 chandransh 144
    items = OneToMany("WidgetItem")
145
    using_options(shortnames=True)
746 rajveer 146
    using_table_options(mysql_engine="InnoDB")
130 ashish 147
 
557 chandransh 148
class WidgetItem(Entity):
130 ashish 149
    id = Field(Integer, primary_key=True, autoincrement=True)
557 chandransh 150
    added_on = Field(DateTime)
151
    item = ManyToOne("Item")
152
    widget = ManyToOne("Widget")
153
    using_options(shortnames=True)    
746 rajveer 154
    using_table_options(mysql_engine="InnoDB")
130 ashish 155
 
557 chandransh 156
class Item(Entity):
157
    id = Field(Integer, primary_key=True, autoincrement=True)
158
    item_id = Field(Integer)
772 rajveer 159
    enabled = Field(Boolean)
557 chandransh 160
    widget_items=OneToMany("WidgetItem")
161
    using_options(shortnames=True)
746 rajveer 162
    using_table_options(mysql_engine="InnoDB")
557 chandransh 163
 
772 rajveer 164
def initialize():
165
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
1122 chandransh 166
    engine = create_engine('mysql://root:shop2020@localhost/user', pool_recycle=7200)
167
    metadata.bind = engine
772 rajveer 168
    metadata.bind.echo = True
169
    setup_all(True)
170
 
171
if __name__=="__main__":
172
    initialize()
173
 
174
 
175
'''
557 chandransh 176
class Ratings(Entity):
177
    id = Field(Integer, primary_key=True, autoincrement=True)
178
    item_id = Field(Integer)
179
    type = Field(Integer)
180
    rating = Field(Float)
181
    using_options(shortnames=True)
746 rajveer 182
    using_table_options(mysql_engine="InnoDB")
557 chandransh 183
 
184
class UserRatings(Entity):
185
    id = Field(Integer, primary_key=True, autoincrement=True)
186
    item_id = Field(Integer)
187
    rating = Field(Float)
188
    user_id = Field(Integer)
189
    using_options(shortnames=True)
746 rajveer 190
    using_table_options(mysql_engine="InnoDB")
772 rajveer 191
'''