# -*- coding: utf-8 -*-
#########################################################################
## This scaffolding model makes your app work on Google App Engine too
## File is released under public domain and you can use without limitations
#########################################################################
## if SSL/HTTPS is properly configured and you want all HTTP requests to
## be redirected to HTTPS, uncomment the line below:
# request.requires_https()
if not request.env.web2py_runtime_gae:
production=True
URI = 'mysql://hassan:hassan123@localhost/coacharabiadb'
if production:
db=DAL(URI, pool_size=20)
else:
db=DAL('sqlite://storage.sqlite', check_reserved=['mssql'])
else:
## connect to Google BigTable (optional 'google:datastore://namespace')
db = DAL('google:datastore')
## store sessions and tickets there
session.connect(request, response, db = db)
## or store session in Memcache, Redis, etc.
## from gluon.contrib.memdb import MEMDB
## from google.appengine.api.memcache import Client
## session.connect(request, response, db = MEMDB(Client()))
## by default give a view/generic.extension to all actions from localhost
## none otherwise. a pattern can be 'controller/function.extension'
response.generic_patterns = ['*'] if request.is_local else []
## (optional) optimize handling of static files
# response.optimize_css = 'concat,minify,inline'
# response.optimize_js = 'concat,minify,inline'
#########################################################################
## Here is sample code if you need for
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()
Contryes = ['Jordan']
auth.settings.extra_fields['auth_user']= [
Field('city',requires=IS_NOT_EMPTY(error_message='الرجاء أدخال أسم المدينة')),
Field('address','text',requires=IS_NOT_EMPTY(error_message='الرجاء أدخال العنوان لتفعيل خدمة التوصيل')),
Field('country',requires = IS_IN_SET(Contryes,error_message='الرجاء أختيار البلد')),
Field('phone',requires=IS_NOT_EMPTY(error_message='الرجاء أدخال الهاتف لتفعيل خدمة التوصيل'))]
## create all tables needed by auth if not custom tables
auth.define_tables()
## configure email
mail=auth.settings.mailer
mail.settings.sender = '
#' # your email
mail.settings.login = '#' # your credentials or None
## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with
janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain
use_janrain(auth,filename='private/janrain.key'
)
from gluon.contrib.login_methods.rpx_account import RPXAccount
from gluon.contrib.login_methods.extended_login_form import ExtendedLoginForm
other_form = RPXAccount(request, api_key='e9e06a5ed01c04decaba7875925a41c834d2e4b7', domain='coacharabia', url=url)
auth.settings.login_form = ExtendedLoginForm(auth,other_form)
# Recaptcha
from gluon.tools import Recaptcha
auth.settings.captcha = Recaptcha(request,
'6Lf0ltcSAAAAAHn5DJnbG3ROhS4BWF2uRC_3Vfet', '6Lf0ltcSAAAAANiY78w6RXMqOL0jQI4vyjaP9geM')
auth.settings.login_captcha = False
#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
## 'date','time','datetime','blob','upload', 'reference TABLENAME'
## There is an implicit 'id integer autoincrement' field
## Consult manual for more options, validators, etc.
##
## More API examples for controllers:
##
## >>> db.mytable.insert(myfield='value')
## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL)
## >>> for row in rows: print
row.id, row.myfield
#########################################################################
User = ['Men','Women','Both']
Categorys = ['Muscle Building','Gain Wight','Loss Wight','Pre Workout','Post Workout','Beauty Supplements','Vitamins']
Equipments = ['Gym Safty Equipments','Fitness Equipments']
Options = ['Flavor','size']
db.define_table('Brands',
Field('Brand_Name'),
Field('owner_Name'),
Field('Phone'),
Field('Date_added','date'),
Field('logo','upload')
)
db.define_table('Supplements',
Field('Brand_ID',db.Brands),
Field('English_Name'),
Field('Arabic_Name'),
Field('Arabic_Description','text'),
Field('English_Description','text'),
Field('Cover','upload'),
Field('Users',requires=IS_IN_SET(User)),
Field('Category',requires=IS_IN_SET(Categorys)),
Field('Old_Pirce','integer'),
Field('Pirce','integer'),
Field('Quantity','integer'),
Field('Date_added','date'),
Field('Hot','boolean'),
Field('New','boolean')
)
db.Supplements.Brand_ID.requires = IS_IN_DB(db,
db.Brands.id,'%(Brand_Name)s')
db.define_table('Tutorials',
Field('Supplement_ID', db.Supplements),
Field('English_Description','text'),
Field('Arabic_Description','text'),
Field('Video_URL'),
Field('Nutrition_Facts','upload')
)
db.Tutorials.Supplement_ID.requires = IS_IN_DB(db,
db.Supplements.id,'%(English_Name)s - %(Brand_ID)s')
db.define_table('Supplements_Statistics',
Field('Supplement_ID', db.Supplements),
Field('Views','integer'),
Field('Purchases','integer')
)
db.define_table('Supplements_Comments',
Field('Product_ID',db.Supplements),
Field('Name'),
Field('Comment'),
Field('Approved','boolean'),
Field('DateTime','datetime',default=request.now)
)
db.define_table('Supplements_Options',
Field('Supplement_ID',db.Supplements),
Field('Option_Type',requires=IS_IN_SET(Options)),
Field('value'),
Field('Price','integer'),
Field('order_number','integer')
)
db.Supplements_Options.Supplement_ID.requires = IS_IN_DB(db,
db.Supplements.id,'%(English_Name)s - %(Brand_ID)s')
db.Supplements_Comments.Product_ID.requires= IS_IN_DB(db,
db.Supplements.id,'%(English_Name)s')
db.define_table('OffersAndArticles',
Field('English_Title'),
Field('Arabic_Title'),
Field('English_Description','text'),
Field('Arabic_Description','text'),
Field('Cover_Image','upload'),
Field('Price'),
Field('Date','date')
)
db.define_table('Blogpost',
Field('English_Title'),
Field('Arabic_Title'),
Field('English_Post','text'),
Field('Arabic_Post','text'),
)
db.define_table('Equipment',
Field('English_Name'),
Field('Arabic_Name'),
Field('Cover','upload'),
Field('Users',requires=IS_IN_SET(User)),
Field('Category',requires=IS_IN_SET(Equipments)),
Field('Pirce','integer'),
Field('Quantity','integer'),
Field('Date_added','date'),
Field('Important','boolean')
)
db.define_table('Garage_Sale',
Field('Name'),
Field('Year_Made','date'),
Field('Image','upload'),
Field('Price','integer'),
Field('User_ID',db.auth_user)
)
db.define_table('COD',
Field('Product_ID'),
Field('Product_Type'),
Field('User_ID',db.auth_user),
Field('Country',requires=IS_IN_SET(Contryes)),
Field('City'),
Field('Address'),
Field('Phone')
)
db.define_table('cart',
Field('OrderID'),
Field('ProductID',db.Supplements),
Field('quantity'),
Field('catid')
)
db.define_table('orders',
Field('orderd_items'),
Field('User_ID'),
Field('DateTime'),
Field('Deliverd','boolean'))
################################# My Global Functions ###########################################
def youtube(url):
'''
Cuting The Youtube URL To Work with the Youtube AIP
'''
video_url = url
urllist=video_url.split("v=")
videoid = urllist[1].split('&')
return videoid[0]
# Creating a List For ALL the Item in The Cart
cartlist = []
for i in db(db.cart.OrderID == session.CartID).select(db.cart.ALL):
if i.ProductID in cartlist:
isincartlist = "ok"
else:
cartlist.append(i.ProductID)