Exemplo n.º 1
0
 def checkParameters(self):
   super(FixedReferenceProvider, self).checkParameters()
   try:
     Model.get(self.param_values['key'])
   except:
     raise ParameterValueError('Key %r does not exist!' %
                              self.param_values['key'])
Exemplo n.º 2
0
 def checkParameters(self):
     super(FixedReferenceProvider, self).checkParameters()
     try:
         Model.get(self.param_values['key'])
     except:
         raise ParameterValueError('Key %r does not exist!' %
                                   self.param_values['key'])
Exemplo n.º 3
0
 def __setattr__(self, attrname, value):
     """
     DataStore api stores all prop values say "email" is stored in "_email" so
     we intercept the set attribute, see if it has changed, then check for an
     onchanged method for that property to call
     """
     if attrname.find('_') != 0:
         if hasattr(self, '_' + attrname):
             curval = getattr(self, '_' + attrname)
             if curval != value:
                 self.__isdirty = True
                 if hasattr(self, attrname + '_onchange'):
                     getattr(self, attrname + '_onchange')(curval, value)
     DBModel.__setattr__(self, attrname, value)
Exemplo n.º 4
0
 def __setattr__(self,attrname,value):
     """
     DataStore api stores all prop values say "email" is stored in "_email" so
     we intercept the set attribute, see if it has changed, then check for an
     onchanged method for that property to call
     """
     if attrname.find('_') != 0:
         if hasattr(self,'_' + attrname):
             curval = getattr(self,'_' + attrname)
             if curval != value:
                 self.__isdirty = True
                 if hasattr(self,attrname + '_onchange'):
                     getattr(self,attrname + '_onchange')(curval,value)
     DBModel.__setattr__(self,attrname,value)
Exemplo n.º 5
0
    def post(self):
        user = users.get_current_user()
        ilmoitusVar = Model.get(self.request.get('key'))

	ilmoitusVar.Ilmoittaja = user
        OlenTemp =self.request.get('Olen')
        ilmoitusVar.Olen = self.request.get('Olen')
	etsinTemp = self.request.get('Etsin')
	ilmoitusVar.Etsin = etsinTemp
        PaikkaTemp = self.request.get('Paikka')
        if PaikkaTemp!="":
            ilmoitusVar.Paikka = self.request.get('Paikka')

        ilmoitusVar.Time = datetime.time(int(self.request.get('Hour')), int(self.request.get('Min')))

	DateTemp = self.request.get('Date')
	Date_res = DateTemp.split('.')
	ilmoitusVar.Date = datetime.date(int(Date_res[2]), int(Date_res[1]), int(Date_res[0]))
	ilmoitusVar.Datetime = datetime.datetime(int(Date_res[2]), int(Date_res[1]), int(Date_res[0]), int(self.request.get('Hour')), int(self.request.get('Min')))


        KuvausTemp = self.request.get('Kuvaus')
        if KuvausTemp!="":
            ilmoitusVar.Kuvaus = self.request.get('Kuvaus')
        VastattuTemp =self.request.get('Vastattu')
        if VastattuTemp!="":
            ilmoitusVar.Vastattu = int(VastattuTemp)
	AgeTemp = self.request.get('Age')
	if AgeTemp != "":
	  ilmoitusVar.Age = int(self.request.get('Age'))

        ilmoitusVar.put()
        self.redirect('/modified')
Exemplo n.º 6
0
    def get(self, key):

        login_url = users.create_login_url(self.request.uri)
        logout_url = users.create_logout_url(login_url)

        user = self.request.environ['current_user']
        emp = Model.get(key)

        pr = PerformanceReview.all().filter('employee', emp).\
                                    order('-date').get()

        pr_form = pr.forms.filter('type', self.type).get()

        if pr_form is None:
            pr_form = PerformanceReviewForm(pr=pr,
                                            type=self.type,
                                            status='draft')
            pr_form.put()

        self.form = pr_form

        if self.flag:
            job_assessment = JobAssessment(form=pr_form)
            job_assessment.put()

        if self.flag:
            self.redirect('/%(type)s/pr/get/%(type)s/%(key)s'
                            % {'type': self.type,
                               'key': pr.key()})
Exemplo n.º 7
0
    def post(self, object_key):

        try:
            obj = Model.get(object_key)
        except BadKeyError:
            self.error(405)
            return

        if self.request.get('value') == '' and not self.request.get('result'):
            obj.delete()
            return

        if self.request.get('value'):
            obj.value = self.request.get('value')

        try:
            obj.manager = self.request.environ['current_user']
        except AttributeError:
            pass

        if self.request.get('result'):
            obj.result = int(self.request.get('result'))

        obj.put()

        if obj.value is None:
            obj.delete()
Exemplo n.º 8
0
 def post(self):
   notification = Notification(
       item_cl = Model.get(Key(self.request.get('key'))),
       message = self.request.get('message'),
       user = users.User(self.request.get('email')),
       is_cl = ("True" == self.request.get('is_cl')),
       time = datetime.now(),
       read = False)
   notification.put()
Exemplo n.º 9
0
    def post(self):
        user = users.get_current_user()
	if not user:
	    self.redirect(users.create_login_url(self.request.uri))
	else: 
	    path=os.path.join(os.path.dirname(__file__),'confirm.html')	
	    postKey = self.request.get('key')
	    ilmoitusVar = Model.get(postKey)
	    template_values = {"url":users.create_logout_url("/"), 'key':postKey, 'datetime':ilmoitusVar.Datetime, 'age':ilmoitusVar.Age, 'gender':ilmoitusVar.Olen, 'location':ilmoitusVar.Paikka }
	    self.response.out.write(template.render(path,template_values))
Exemplo n.º 10
0
    def __call__(self, environ, start_response):

        current_user = users.get_current_user()
        url = users.create_login_url("/")

        req = Request(environ)

        non_auth_urls = ['/create_role', '/p', '/users', '/add_emp', '/edit_user', '/upload_contacts', '/parse_xls']
        if environ['PATH_INFO'] not in non_auth_urls:

            if current_user is None:
                try:
                    auth_header = req.headers['Authorization']
                except KeyError:
                    resp = Response(status="307", location=url)
                    return resp(environ, start_response)

                username, password = '', ''
                try:
                    user_info = base64.decodestring(auth_header[6:])
                    username, password = user_info.split(':')

                except ValueError:
                    resp = Response(status="401")
                    return resp(environ, start_response)

                user_info = User.gql("WHERE username = :username ",
                            username=username).get()

                if user_info is None:
                    resp = Response(status="401")
                    return resp(environ, start_response)

                if not check_password(password, user_info.password):
                    resp = Response(status="401")
                    return resp(environ, start_response)
            else:
                email = str(current_user.email()).strip()
                user_info = User.all().filter('email', email).get()

                if user_info is None:
                    user_info = User(
                        email=current_user.email())
                    user_info.put()

            environ["current_user"] = user_info

            try:
                environ["current_role"] = Model.get(user_info.role[0]).value
            except IndexError:
                environ["current_role"] = ''

        resp = req.get_response(self.app)
        return resp(environ, start_response)
Exemplo n.º 11
0
    def post(self):
        user = users.get_current_user()
	if not user:
	    self.redirect(users.create_login_url(self.request.uri))
	else: 
	    path=os.path.join(os.path.dirname(__file__),'modify.html')	
	    postKey = self.request.get('key')
	    ilmoitusVar = Model.get(postKey)
	    date = str(ilmoitusVar.Datetime.day) + "." + str(ilmoitusVar.Datetime.month) + "." + str(ilmoitusVar.Datetime.year)
	    template_values = {"url":users.create_logout_url("/"), 'Age':ilmoitusVar.Age, 'Olen':ilmoitusVar.Olen, 'Etsin':ilmoitusVar.Etsin, 'location':ilmoitusVar.Paikka, 'description':ilmoitusVar.Kuvaus, 'key':postKey, 'hour':ilmoitusVar.Datetime.hour, 'minute':ilmoitusVar.Datetime.minute, 'date':date}
	    self.response.out.write(template.render(path,template_values))
Exemplo n.º 12
0
    def post(self):

        super(UploadFile, self).post()

        key = self.request.POST.get('key')
        form = Model.get(key)
        blob_info = blobstore.BlobInfo.get(self.blob_key)
        form.file_key = str(blob_info.key())
        form.file_name = blob_info.filename

        form.put()
Exemplo n.º 13
0
    def post(self):
        user = users.get_current_user()
	if not user:
	    self.redirect(users.create_login_url(self.request.uri))
	else: 
	    path=os.path.join(os.path.dirname(__file__),'deleted.html')	
	    postKey = self.request.get('key')
	    ilmoitusVar = Model.get(postKey)
	    ilmoitusVar.Poistettu = True
	    ilmoitusVar.put()
	    template_values = {"url":users.create_logout_url("/")}
	    self.response.out.write(template.render(path,template_values))  
Exemplo n.º 14
0
 def __new__(cls,
             return_tuple=False,
             **kwargs):
     if return_tuple:
         props = set()
         for name in cls.properties():
             props.add(name)
         props |= set(kwargs.keys())
         props = list(props)
         Model2 = namedtuple('Model2', props)
         return Model2(**{name: (kwargs[name] if name in kwargs else None) for name in props})
     else:
         return Model.__new__(Model, **kwargs)
Exemplo n.º 15
0
    def post(self):

        key = self.request.get('key')

        email = self.request.get('email').strip()

        user = User.get(key)

        user.email = email

        first_name = self.request.get('first_name').strip()
        user.first_name = first_name

        last_name = self.request.get('last_name').strip()
        user.last_name = last_name

        position = self.request.get('position')
        user.position = position

        first_date =  self.request.get('first_date')
        try:
            first_date = datetime.datetime.strptime(first_date, '%Y-%m-%d').date()
        except ValueError:
            first_date = None
        user.first_date = first_date

        dept = self.request.get('dept')
        dept_ref = Dept.all().filter('name', dept).get()

        if dept_ref is None:
            dept_ref = Dept(name=dept)
            dept_ref.put()

        user.dept = dept_ref
        try:
            manager = Model.get(self.request.get('manager'))
        except BadKeyError:
            manager = None
        user.manager = manager

        roles = self.request.get('role')[:-1].split(',')

        user.role = []
        for role in roles:
                role_key = Role.gql("WHERE value = :role",
                                    role=role).get().key()
                user.role.append(role_key)
        user.put()

        self.response.out.write('You have successfully updated user info')
Exemplo n.º 16
0
    def post(self):

        user = self.request.environ['current_user']

        role_key = Role.gql("WHERE value = :hr", hr='hr').get().key()

        if role_key not in user.role:
            self.error(403)
            return

        start_str = self.request.get('start')
        finish_str = self.request.get('finish')
        type = self.request.get('type')

        event = Event.all().filter('type', type).get()
        try:
            first_date = event.first_effective_date
        except AttributeError:
            first_date = None

        employees = self.request.get('employees')[:-1].split(',')

        try:
            start = datetime.datetime.strptime(start_str, '%Y-%m-%d').date()
            finish = datetime.datetime.strptime(finish_str, '%Y-%m-%d').date()
        except ValueError:
            self.response.out.write('incorrect date')
            self.error(403)
            return

        description = "PR %s: %s-%s" % (type, start_str, finish_str)

        period = PerformanceReviewPeriod(type=type,
                                         description=description,
                                         start_date=start,
                                         finish_date=finish)
        period.put()

        for employee in employees:
            if employee != '':
                user = Model.get(employee)
                pr = PerformanceReview(employee=user,
                                       first_effective_date=first_date,
                                       manager=user.manager,
                                       period=period,
                                       date=start)
                pr.put()

        self.response.out.write(period.key())
Exemplo n.º 17
0
def jsonToModel(Model, jsonString):
	jsonObj = json.loads(jsonString)
	if jsonObj.has_key(KEY_IDENTIFIER):
		instance = Model.get(jsonObj[KEY_IDENTIFIER])
	else:
		instance = Model()
		
	for property, value in jsonObj.items():
		if hasattr(Model, property):
			value = convertToGaeDatatype(instance, property, value)
			setattr(instance, property, value)
		else:
			if property != KEY_IDENTIFIER:
				logging.info('Ignored the "%s" property not found on the %s class' % (property, Model.__name__))

		
	return instance
Exemplo n.º 18
0
    def get(self):
        users = User.all().order('first_name').fetch(1000)
        for user in users:
            user.roles = ''
            for role in user.role:
                user.roles = user.roles + Model.get(role).value + ' '
                
        upload_url_first_date = blobstore.create_upload_url('/upload_first_date')
        upload_url = blobstore.create_upload_url('/upload_contacts')




        self.template_values.update({'users': users,
                                     'upload_url_first_date': upload_url_first_date,
                                     'upload_url': upload_url})

        self.response.out.write(template.render(self.path,
                                                self.template_values))
Exemplo n.º 19
0
    def get(self):

        user = self.request.environ['current_user']
        current_role = self.request.environ['current_role']
        email = None
        if user is not None:
            email = user.email

        login_url = users.create_login_url(self.request.uri)
        logout_url = users.create_logout_url(login_url)
        roles = []
        for role_key in user.role:
            roles.append(Model.get(role_key).value)
        template_values = {
                           'username': email,
                           'user': user,
                           'roles': roles,
                           'current_role': current_role,
                           'logout_url': logout_url}

        path = 'templates/index.html'
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 20
0
    def post(self):

        key = self.request.get('key')
        pr = Model.get(key)
        start_str = self.request.get('start')
        finish_str = self.request.get('finish')
        first_date = self.request.get('first_date')

        if start_str:
            try:
                start = datetime.datetime.strptime(start_str,
                                                   '%Y-%m-%d').date()
                pr.start_date = start
            except ValueError:
                self.response.out.write('incorrect date')
                self.error(401)
                return

        if finish_str:
            try:
                finish = datetime.datetime.strptime(finish_str,
                                                    '%Y-%m-%d').date()
                pr.finish_date = finish
            except ValueError:
                self.response.out.write('incorrect date')
                self.error(401)
                return

        if first_date:
            try:
                first_effective_date = datetime.datetime.strptime(first_date,
                                                    '%Y-%m-%d').date()
                pr.first_effective_date = first_effective_date
            except ValueError:
                self.response.out.write('incorrect date')
                self.error(401)
                return

        pr.put()
Exemplo n.º 21
0
    def get(self, key):

        users = User.all()
        managers = []
        for user in users:
            for role in user.role:
                if Model.get(role).value == 'manager':
                    managers.append(user)

        roles = []
        if key:
            user = User.get(key)
            for role in user.role:
                roles.append(Role.get(role).value)
        else:
            user = None

        template_values = {'managers': managers,
                           'user': user,
                           'roles': roles}

        path = 'templates/new_user.html'
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 22
0
  def getValue(self):
    self.checkParameters()

    return Model.get(self.param_values['key']);
Exemplo n.º 23
0
from google.appengine.ext.db import Model
from views import MainPage, Pop40Page
import logging
import os
import webapp2 as webapp

logging.getLogger().setLevel(logging.DEBUG)
logging.info('App was loaded.')

# check if the DB is storing all the available weeks
for filename in os.listdir('data'):
    datestr = filename.split('_', 1)[1].rstrip('.rss')
    week = Model.get_by_key_name(datestr) # TODO: this is not working
    if not week:
        logging.info(datestr + ' was missing')

app = webapp.WSGIApplication([('/', MainPage),
                              ('/all', Pop40Page)],
                              debug=True)
Exemplo n.º 24
0
from google.appengine.ext.db import Model
from views import MainPage, Pop40Page
import logging
import os
import webapp2 as webapp

logging.getLogger().setLevel(logging.DEBUG)
logging.info('App was loaded.')

# check if the DB is storing all the available weeks
for filename in os.listdir('data'):
    datestr = filename.split('_', 1)[1].rstrip('.rss')
    week = Model.get_by_key_name(datestr)  # TODO: this is not working
    if not week:
        logging.info(datestr + ' was missing')

app = webapp.WSGIApplication([('/', MainPage), ('/all', Pop40Page)],
                             debug=True)
Exemplo n.º 25
0
 def __init__(self, parent=None, key_name=None, _app=None, **kwds):
     self.__isdirty = False
     DBModel.__init__(self, parent=None, key_name=None, _app=None, **kwds)
Exemplo n.º 26
0
 def __init__(self, parent=None, key_name=None, _app=None, **kwds):
     self.__isdirty = False
     DBModel.__init__(self, parent=None, key_name=None, _app=None, **kwds)
Exemplo n.º 27
0
    def getValue(self):
        self.checkParameters()

        return Model.get(self.param_values['key'])