Subversion Repositories SmartDukaan

Rev

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