示例#1
0
文件: api.py 项目: mouedhen/sndlatr
 def create_model(self, data):
     """ create a new job from given data """
     user = auth.get_current_user()
     job = self.model_cls(user_email=user.email(), user_id=user.user_id())
     self._set_model_data(job, data)
     job.put()
     logging.debug(u'created Job {} for {}'.format(job.key, job.user_email))
     self.response_json(job)
示例#2
0
文件: api.py 项目: Schibum/sndlatr
 def create_model(self, data):
     """ create a new model from given data """
     user = auth.get_current_user()
     job = self.model_cls(user_id=user.user_id())
     self._set_model_data(job, data)
     job.put()
     logging.debug('created Model {}'.format(job.key))
     self.response_json(job)
示例#3
0
文件: api.py 项目: mouedhen/sndlatr
 def create_model(self, data):
     """ create a new model from given data """
     user = auth.get_current_user()
     job = self.model_cls(user_id=user.user_id())
     self._set_model_data(job, data)
     job.put()
     logging.debug('created Model {}'.format(job.key))
     self.response_json(job)
示例#4
0
文件: api.py 项目: Schibum/sndlatr
 def create_model(self, data):
     """ create a new job from given data """
     user = auth.get_current_user()
     job = self.model_cls(user_email=user.email(),
                          user_id=user.user_id())
     self._set_model_data(job, data)
     job.put()
     logging.debug(u'created Job {} for {}'.format(job.key, job.user_email))
     self.response_json(job)
示例#5
0
文件: api.py 项目: mouedhen/sndlatr
 def get_model(self, id):
     try:
         id = int(id)
     except ValueError:
         raise HTTPBadRequest('invalid job id')
     user = auth.get_current_user()
     model = self.model_cls.get_by_id(id)
     if model is None:
         raise HTTPNotFound()
     if model.user_id != user.user_id():
         raise HTTPForbidden()
     return model
示例#6
0
文件: api.py 项目: Schibum/sndlatr
 def get_model(self, id):
     try:
         id = int(id)
     except ValueError:
         raise HTTPBadRequest('invalid job id')
     user = auth.get_current_user()
     model = self.model_cls.get_by_id(id)
     if model is None:
         raise HTTPNotFound()
     if model.user_id != user.user_id():
         raise HTTPForbidden()
     return model
示例#7
0
文件: api.py 项目: mouedhen/sndlatr
 def get(self, id=None):
     if id is not None:
         return self.response_json(self.get_model(id))
     else:
         user = auth.get_current_user()
         # ignore ids > 100
         try:
             ids = [int(id) for id in self.request.GET.getall('id')[0:100]]
         except ValueError:
             raise HTTPBadRequest()
         job_futures = [self.model_cls.get_by_id_async(id) for id in ids]
         jobs = [future.get_result() for future in job_futures]
         jobs = filter(None, jobs)
         if any(job.user_id != user.user_id() for job in jobs):
             raise HTTPForbidden()
         return self.response_json(jobs)
示例#8
0
文件: api.py 项目: Schibum/sndlatr
 def get(self, id=None):
     if id is not None:
         return self.response_json(self.get_model(id))
     else:
         user = auth.get_current_user()
         # ignore ids > 100
         try:
             ids = [int(id) for id in self.request.GET.getall('id')[0:100]]
         except ValueError:
             raise HTTPBadRequest()
         job_futures = [self.model_cls.get_by_id_async(id) for id in ids]
         jobs = [future.get_result() for future in job_futures]
         jobs = filter(None, jobs)
         if any(job.user_id != user.user_id() for job in jobs):
             raise HTTPForbidden()
         return self.response_json(jobs)
示例#9
0
文件: api.py 项目: mouedhen/sndlatr
 def post(self, id):
     job = models.RemindJob.get_by_id(int(id))
     user = auth.get_current_user()
     if job is None:
         raise HTTPNotFound()
     if job.user_id != user.user_id():
         raise HTTPForbidden()
     if job.state != 'scheduled':
         logging.warn('check_reply for non-scheduled job not possible')
         raise HTTPBadRequest()
     reply = validation.disabled_reply_schema(self.json)
     job.disabled_reply = models.DisabledReply(
         message_id=reply['messageId'],
         from_name=reply['fromName'],
         from_email=reply['fromEmail'])
     job.add_to_check_reply_queue()
     self.response_json(None)
示例#10
0
文件: api.py 项目: Schibum/sndlatr
 def post(self, id):
     job = models.RemindJob.get_by_id(int(id))
     user = auth.get_current_user()
     if job is None:
         raise HTTPNotFound()
     if job.user_id != user.user_id():
         raise HTTPForbidden()
     if job.state != 'scheduled':
         logging.warn('check_reply for non-scheduled job not possible')
         raise HTTPBadRequest()
     reply = validation.disabled_reply_schema(self.json)
     job.disabled_reply = models.DisabledReply(
         message_id=reply['messageId'],
         from_name=reply['fromName'],
         from_email=reply['fromEmail'])
     job.add_to_check_reply_queue()
     self.response_json(None)
示例#11
0
文件: api.py 项目: Schibum/sndlatr
    def get(self):
        user = auth.get_current_user()
        account_future = models.Account.get_by_id_async(user.user_id())

        send_jobs_future = models.SendJob.query_display(
            user.user_id()).fetch_async()
        remind_jobs_future = models.RemindJob.query_display(
            user.user_id()).fetch_async()
        snippets_future = models.Snippet.query_display(
            user.user_id()).fetch_async()

        account = account_future.get_result()

        if account is None:
            self.response_json({'auth': 'need_code'})
            return

        self.response_json(
            {'sendJobs': send_jobs_future.get_result(),
             'remindJobs': remind_jobs_future.get_result(),
             'snippets': snippets_future.get_result()})
示例#12
0
文件: api.py 项目: mouedhen/sndlatr
    def get(self):
        user = auth.get_current_user()
        account_future = models.Account.get_by_id_async(user.user_id())

        send_jobs_future = models.SendJob.query_display(
            user.user_id()).fetch_async()
        remind_jobs_future = models.RemindJob.query_display(
            user.user_id()).fetch_async()
        snippets_future = models.Snippet.query_display(
            user.user_id()).fetch_async()

        account = account_future.get_result()

        if account is None:
            self.response_json({'auth': 'need_code'})
            return

        self.response_json({
            'sendJobs': send_jobs_future.get_result(),
            'remindJobs': remind_jobs_future.get_result(),
            'snippets': snippets_future.get_result()
        })