Exemple #1
0
    def post(self):
        data = request.get_json()

        #get current user
        current_user_jwt = get_jwt_identity()
        current_user = User.find_by_username(current_user_jwt)

        # create deadline out of json
        deadline = deadline_schema.load(data)
        #convert all datetime strings into strings which marshmallow can load (marshmallow requires ISO 8601 format INCLUDING SECONDS)
        try:
            data['date'] = str(parser.parse(data['date']))
        except:
            data['events'][i]['start_date'] = None

        new_deadline = Deadline(name=deadline.data['name'],
                                type=deadline.data['type'],
                                date=deadline.data['date'],
                                priority=deadline.data['priority'],
                                num_of_hours=deadline.data['num_of_hours'])

        # append create deadline to current user
        current_user.deadlines.append(new_deadline)

        try:
            new_deadline.save_to_db()
            current_user.save_to_db()
            ret = deadline_schema.dump(new_deadline)
            print(ret.data)
            return ret, 200
        except:
            return {'message': 'Something went wrong.'}, 500
Exemple #2
0
 def post(self, book_slug, arg):
   book = self.get_object_by_key_or_404(Book, book_slug)
   deadline = Deadline(book      = book,
                       starts_on = self.get_date_param('starts_on'),
                       ends_on   = self.get_date_param('ends_on'),
                       page      = self.get_int_param('page'),
                       location  = self.get_int_param('location'),
                       start_page= self.get_int_param('start_page'),
                       start_location= self.get_int_param('start_location'))
   deadline.put()
   self.redirect('/admin/books/%s/deadlines/%s/' % (book.slug, deadline.key()))
Exemple #3
0
def add_deadline():
    req = request.get_json(force = True)
    user = flask_praetorian.current_user()
    subject = req.get("subject", None)
    task_name = req.get("task_name", None)
    description = req.get("description", None)
    date = req.get("date", None)

    date_obj = date_transform(date)

    if not (subject.replace(" ", "") and task_name.replace(" ", "") and description.replace(" ", "")):
        return {"message": "Fill all the fields"}

    deadline = Deadline(subject = subject, deadline_name = task_name, deadline_desc = description, deadline_date = date_obj, owner = user)
    success_bool = True
    try:
        db.session.add(deadline)
        db.session.commit()
    except:
        success_bool = False
        db.session.rollback()

    if not success_bool:
        return {"message": "Something went wrong. Try again"}

    ret = {'message': "OK", "deadline_id": deadline.deadline_id, "deadline_date": date_transform(date)}
    return ret, 200
Exemple #4
0
    def post(self, token):
        args = self.args.parse_args()

        if token_check(args['client_id'], token):

            is_client = Client.query.filter_by(
                id=args['client_id']
            ).first()

            if not is_client:
                new_client = Client(id=args['client_id'])
                db.session.add(new_client)
                db.session.commit()

            new_deadline = Deadline(
                client_id=args['client_id'],
                description=args['description'],
                final_date=args['final_date']
            )
            db.session.add(new_deadline)
            db.session.commit()

            return {'status': 'success'}, 201
        else:
            return {'status': 'wrong api key'}, 403
Exemple #5
0
 def get(self):
     current_user_name = get_jwt_identity()
     ids = Deadline.find_all_deadlines_of_user(current_user_name)
     ret_ids = []
     for elt in ids:
         ret_ids.append(deadline_schema.dump(elt))
     # try:
     return [i[0] for i in ret_ids]
Exemple #6
0
    def _create_or_add_deadline(self, deadline_name, parentnode, extras):
        deadline = Deadline(assignment_group=parentnode,
                            deadline=parentnode.parentnode.publishing_time +
                            timedelta(days=10))

        if extras['ends']:
            deadline.deadline = parentnode.parentnode.publishing_time + timedelta(
                int(extras['ends'][0]))
        if extras['text']:
            deadline.text = extras['text'][0]

        # create the variable ref'ing directly to the deadline
        prefix = (
            parentnode.parentnode.parentnode.parentnode.short_name +
            '_' +  # subject_
            parentnode.parentnode.parentnode.short_name + '_' +  # period_
            parentnode.parentnode.short_name + '_' +  # assignment_
            parentnode.name + '_')

        deadline.full_clean()
        deadline.save()

        # only create this variable if a name is given
        if deadline_name:
            varname = prefix + deadline_name
            vars(self)[varname] = deadline

        # Add or append to the deadlines list. Last element will be
        # the same as the most recently created deadline, stored in
        # prefix+deadline_name
        vardict = prefix + 'deadlines'
        if vardict in vars(self).keys():
            vars(self)[vardict].append(deadline)
        else:
            vars(self)[vardict] = [deadline]

        # Create a variable with the name formatted as:
        #    subject_period_assignment_group_deadline<X> where X
        #    starts at 1 and increments for each deadline added to
        #    this group
        vars(self)[prefix + 'deadline' +
                   str(len(vars(self)[vardict]))] = deadline

        # check if the default deadline, deadline0, variable exists
        default_deadline_var = prefix + 'deadline0'
        if default_deadline_var not in vars(self).keys():
            vars(self)[default_deadline_var] = parentnode.deadlines.order_by(
                'deadline')[0]

        return deadline
def send_mails():
    Deadline.delete_old()
    yag = yagmail.SMTP(user='******',
                       password=os.environ.get('MAILER_PASSWORD'))
    session = Session()
    student_list = session.query(Student).all()
    session.close()
    for student in student_list:
        session = Session()
        contents = make_mail(student, session)
        session.close()
        try:
            yag.send(to=student.email,
                     subject='Upcoming Deadlines as on {}'.format(
                         datetime.now().strftime('%d/%m')),
                     contents=contents)
            print(contents)
            print("Email sent successfully")
        except:
            print("Error, email was not sent")

    yag.close()
    return None
Exemple #8
0
    def _create_or_add_deadline(self, deadline_name, parentnode, extras):
        deadline = Deadline(assignment_group=parentnode,
                            deadline=parentnode.parentnode.publishing_time + timedelta(days=10))

        if extras['ends']:
            deadline.deadline = parentnode.parentnode.publishing_time + timedelta(int(extras['ends'][0]))
        if extras['text']:
            deadline.text = extras['text'][0]

        # create the variable ref'ing directly to the deadline
        prefix = (parentnode.parentnode.parentnode.parentnode.short_name + '_' +  # subject_
                  parentnode.parentnode.parentnode.short_name + '_' +  # period_
                  parentnode.parentnode.short_name + '_' +  # assignment_
                  parentnode.name + '_')

        deadline.full_clean()
        deadline.save()

        # only create this variable if a name is given
        if deadline_name:
            varname = prefix + deadline_name
            vars(self)[varname] = deadline

        # Add or append to the deadlines list. Last element will be
        # the same as the most recently created deadline, stored in
        # prefix+deadline_name
        vardict = prefix + 'deadlines'
        if vardict in vars(self).keys():
            vars(self)[vardict].append(deadline)
        else:
            vars(self)[vardict] = [deadline]

        # Create a variable with the name formatted as:
        #    subject_period_assignment_group_deadline<X> where X
        #    starts at 1 and increments for each deadline added to
        #    this group
        vars(self)[prefix + 'deadline' + str(len(vars(self)[vardict]))] = deadline

        # check if the default deadline, deadline0, variable exists
        default_deadline_var = prefix + 'deadline0'
        if default_deadline_var not in vars(self).keys():
            vars(self)[default_deadline_var] = parentnode.deadlines.order_by('deadline')[0]

        return deadline
Exemple #9
0
    def get(self, id):
        deadline = Deadline.find_by_id(id)
        if not deadline:
            return {'message': 'A deadline with that id does not exist.'}
        #get the name of the user trying to do the updating
        current_user_name = get_jwt_identity()
        user = User.find_by_username(current_user_name)
        #return a helpful message if the user is trying to edit an account which is not their own
        if not current_user_name == deadline.user_name:
            return {
                'message':
                'That deadline belongs to another user account; you are not authorized to access it.'
            }

        #serialize deadline
        deadline_dump = deadline_schema.dump(deadline)
        try:
            return deadline_dump
        except:
            return {'message': 'Something went wrong.'}, 500