Esempio n. 1
0
    def details_view_with_extra_func(self, extra_func):
        """
            Details model view
        """
        return_url = get_redirect_target() or self.get_url('.index_view')

        if not self.can_view_details:
            return redirect(return_url)

        if self.__class__.__name__ == 'AdminBIUserModelView':
            id = get_mdict_item_or_list(request.args, 'id')
            user_id = get_mdict_item_or_list(request.args, 'user_id')

            if id is not None:
                model = self.get_one(id)
            elif user_id is not None:
                model = self.session.query(BIUser).filter_by(user_id=user_id).one()
            else:
                return redirect(return_url)
        else:
            id = get_mdict_item_or_list(request.args, 'id')
            if id is None:
                return redirect(return_url)
            model = self.get_one(id)

        if model is None:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        return extra_func(model, return_url)
Esempio n. 2
0
    def rest_segments(self):
        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return redirect(get_redirect_target() or self.get_url('.index_view'))

        event = self.get_one(id)

        if event is None:
            flash(gettext('Event does not exist.'), 'error')
            return redirect(return_url)
        if request.method == 'GET':
            version = get_mdict_item_or_list(request.args, 'version')
            return Response(json.dumps({
                    'version': event.version,
                    'comment': event.comment,
                    'translation': event.translation,
                    'segments': event.dict_segments,
                }), mimetype="application/json")

        if request.method == 'POST':
            saved = request.get_json()
            if 'segments' not in saved or 'render' not in saved:
                abort(400)
            newversion = (event.version + 1)
            segments = []
            for s in saved['segments']:
                videofile=VideoFile.query.filter_by(id=int(s['videofile_id'])).first()
                segments.append(VideoSegment(
                    segment_id = int(s['segment_id'])+1,
                    event = event,
                    videofile = videofile,
                    start = float(s['start']),
                    length = float(s['length']),
                    assigned = True,
                    transition = s['transition'],
                    transition_length = s['transition_length'] if 'transition_length' in s else None,
                    version = newversion,
                ))
            event.version = newversion
            if saved['render'] is True:
                event.state = 'rendering'
            if 'comment' in saved:
                event.comment = saved['comment']
            if 'translation' in saved and isinstance(saved['translation'], bool):
                event.translation = saved['translation']
            for s in segments:
                db.session.add(s)
            db.session.commit()
            return Response(json.dumps(event.dict_segments), mimetype="application/json")
Esempio n. 3
0
    def assign_view(self):
        id = get_mdict_item_or_list(request.args, 'id')
        model = self.get_one(id)

        asset_id = get_mdict_item_or_list(request.args, 'asset_id')

        model.assign(asset_id)
        db.session.add(model)
        log("Update", model, user=current_user)
        db.session.commit()

        flash(f"File assigned to asset #{asset_id}", 'success')
        if request.args.get('refresh', False):
            return 'OK', 200, {'HX-Refresh': 'true'}
        
        return redirect(url_for('.details_view', id=id))
Esempio n. 4
0
    def details_view(self):
        """Override the details_view to use the export formatter."""
        return_url = get_redirect_target() or self.get_url('.index_view')

        if not self.can_view_details:
            return redirect(return_url)

        request_id = get_mdict_item_or_list(request.args, 'id')

        if request_id is None:
            return redirect(return_url)

        request_model = self.get_one(request_id)

        if request_model is None:
            flash(gettext('O registro não existe.'), 'erro')
            return redirect(return_url)

        if self.details_modal and request.args.get('modal'):
            template = self.details_modal_template
        else:
            template = self.details_template

        return self.render(template,
                           model=request_model,
                           details_columns=self._details_columns,
                           get_value=self.get_export_value,
                           return_url=return_url)
Esempio n. 5
0
    def details_view(self):
        sub = request.args.get('sub', self.default_subordinate_view)
        self._template_args.update({
            'sub': sub,
            'time_formatter': datetime.time,
        })
        self._edit_form_class = self._delegate_to_sub('form')
        self.override_fields(self._edit_form_class)

        return_url = get_redirect_target() or self.get_url('.index_view')

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return redirect(return_url)

        model = self.get_one(id)

        if model is None:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        form = self.edit_form(obj=model)

        form_opts = FormOpts(widget_args=self.form_widget_args,
                             form_rules=self._form_edit_rules)

        return self.render(self.details_modal_template,
                           model=model,
                           form=form,
                           form_opts=form_opts,
                           return_url=return_url)
Esempio n. 6
0
    def details_view(self):
        """Details model view."""
        return_url = get_redirect_target() or self.get_url('.index_view')

        if not self.can_view_details:
            return redirect(return_url)

        widget_item_id = helpers.get_mdict_item_or_list(request.args, 'id')
        if widget_item_id is None:
            return redirect(return_url)

        model = self.get_one(widget_item_id)
        label = WidgetSettingView.get_label_display_to_list(model.widget_id)
        model.label = label

        if model is None:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        if self.details_modal and request.args.get('modal'):
            template = self.details_modal_template
        else:
            template = self.details_template

        return self.render(template,
                           model=model,
                           details_columns=self._details_columns,
                           get_value=self.get_detail_value,
                           return_url=return_url)
Esempio n. 7
0
    def edit_view(self):
        return_url = get_redirect_target() or self.get_url('.index_view')

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return redirect(return_url)
        top_project = self.get_one(id)

        form = EditTopProjectForm(description=top_project.description,
                                  name=top_project.name)

        if request.method == 'POST' and form.validate_on_submit():
            top_project.name = form.name.data
            top_project.description = form.description.data
            self.session.commit()
            if form.image.data:
                filename = secure_filename(form.image.data.filename)
                file_type = filename.rsplit('.', 1)[1]
                if file_type in ['png', 'jpg', 'jpeg']:

                    form.image.data.save(
                        os.path.join(current_app.config['UPLOAD_FOLDER'],
                                     'top_projects',
                                     '%s.png' % str(top_project.id)))
                else:
                    flash('this file is not supported')
                    return self.render('admin/edit_top_project.html',
                                       form=form)

            return redirect(return_url)

        return self.render('admin/edit_top_project.html', form=form)
Esempio n. 8
0
    def validate_model(self):

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return False

        #  Get Invited and Being Served states, to see if CSR has any open tickets.
        period_state_invited = PeriodState.get_state_by_name("Invited")
        period_state_being_served = PeriodState.get_state_by_name(
            "Being Served")

        #  See if CSR has any open tickets.
        citizen = Citizen.query \
            .join(Citizen.service_reqs) \
            .join(ServiceReq.periods) \
            .filter(Period.time_end.is_(None)) \
            .filter(Period.csr_id==id) \
            .filter(or_(Period.ps_id==period_state_invited.ps_id, Period.ps_id==period_state_being_served.ps_id)) \
            .all()

        if len(citizen) != 0:
            flash(gettext('CSR has an open ticket and cannot be edited.'),
                  'error')
            return False

        if not self.can_edit:
            return False

        model = self.get_one(id)

        if model is None:
            flash(gettext('Record does not exist.'), 'error')
            return False

        return model
    def sync_project_sprints_without_issues(self):
        return_url = get_redirect_target() or self.get_url(".index_view")
        model_id = get_mdict_item_or_list(request.args, "id")
        model = self.get_one(model_id)
        if not model.jira_project:
            flash("No Jira Project assigned to Activity", "error")
            return redirect(return_url)

        try:
            # synchronous sync
            current_app.logger.info(
                f"Syncing all sprints (without issues) of project {model.jira_project.project_key}"
            )
            from tasks.jira import (  # pylint: disable=import-outside-toplevel
                sync_all_sprints_without_issues, )

            result_only_sprints = sync_all_sprints_without_issues.delay(
                model_id)
            result_only_sprints.get()

            flash("Project sprints successfully synced.", "success")
        except Exception as e:
            logging.error(f"Sync project error: {e}")
            flash("Project sprints not synced.", "error")
        return redirect(return_url)
Esempio n. 10
0
    def details_view(self):
        """
            Details model view
        """
        return_url = get_redirect_target() or self.get_url('.index_view')

        if not self.can_view_details:
            return self.redirect(return_url)

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return self.redirect(return_url)

        model = self.get_one(id)

        if model is None:
            flash(gettext('Record does not exist.'), 'error')
            return self.redirect(return_url)

        if self.details_modal and request.args.get('modal'):
            template = self.details_modal_template
        else:
            template = self.details_template

        return self.render(template,
                           model=model,
                           details_columns=self._details_columns,
                           get_value=self.get_list_value,
                           return_url=return_url)
Esempio n. 11
0
 def edit_view(self):
     """Event edit view"""
     events = DataGetter.get_all_events()
     event_id = get_mdict_item_or_list(request.args, 'id')
     self.name = "Event | Edit"
     event = DataGetter.get_event(event_id)
     from ....forms.admin.event_form import EventForm
     self.form = EventForm(obj=event)
     self.form.logo.choices = DataGetter.get_all_files_tuple()
     self.form.logo.choices.insert(0, ('', ''))
     if self.form.validate():
         if request.method == "POST":
             if is_event_admin_or_editor(event_id):
                 DataManager.update_event(self.form, event)
                 flash("Event updated")
             else:
                 flash("You don't have permission!")
             return redirect(url_for('.index_view', event_id=event_id))
     return self.render(
         'admin/model/create_model.html',
         form=self.form,
         event_id=event_id,
         events=events,
         # owner=DataGetter.get_event_owner(event_id),
         cancel_url=url_for('.index_view'))
Esempio n. 12
0
    def edit_view(self):
        """
            restrict edit on invoices, that have not been sent.
        """
        return_url = get_redirect_target() or self.get_url('.index_view')

        if not self.can_edit:
            return redirect(return_url)

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return redirect(return_url)

        invoice = self.get_one(id)

        if invoice is None:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        if invoice.sent:
            flash(
                gettext('Invoice has already been sent and cannot be edited.'),
                'error')
            return redirect(return_url)

        return super(AdminInvoiceView, self).edit_view()
 def delete_sprints_and_issues(self):
     return_url = get_redirect_target() or self.get_url(".index_view")
     model_id = get_mdict_item_or_list(request.args, "id")
     model = self.get_one(model_id)
     try:
         sprints = (Sprint.query.filter(
             Sprint.activity == model).with_entities(
                 Sprint.sprint_id).all())
         issue_count = IssueSnapshot.query.filter(
             IssueSnapshot.sprint_id.in_(sprints)).delete(
                 synchronize_session=False)
         db.session.commit()
         sprint_count = Sprint.query.filter(
             Sprint.activity == model).delete()
         db.session.commit()
         message = (
             f"Deleted {sprint_count} sprints with {issue_count} issue snapshots."
         )
         current_app.logger.info(message)
         flash(message, "success")
     except Exception:
         current_app.logger.error(traceback.format_exc())
         current_app.logger.error(
             "Failed to delete sprints and issue snapshots")
         flash("Deleting sprints and issue snapshots failed", "error")
     return redirect(return_url)
Esempio n. 14
0
    def get_page(self):
        return_url = get_redirect_target() or self.get_url('.index_view')

        task_id = get_mdict_item_or_list(request.args, 'id')
        task = self.get_one(task_id)

        if task is None:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        if self.coll_name == 'crawl':
            colname = 'crawl_%s' % task['_project']
        else:
            colname = 'auth_%s' % task['_code']
        # print PageDB[colname]
        coll = PageDB[colname]
        page = coll.find({'_task_id': self._get_valid_id(task_id)})
        page = list(page)
        if not page:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        tmpl = 'admin/model/task_page_info.html'
        return self.render(tmpl,
                           # get_value=self.get_list_value,
                           get_value=lambda m, c: m[c],
                           get_type=type,
                           model=page)
Esempio n. 15
0
    def details_view(self):
        return_url = get_redirect_target() or self.get_url('.index_view')

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return redirect(return_url)

        if id.startswith("RH"):
            id = id[2:]

        model = self.get_one(id)

        if model is None:
            flash('Record does not exist.', 'error')
            return redirect(return_url)

        template = self.details_template

        batch_number = get_next_file_batch_number()
        file_form = FileForm(batch_number=batch_number)

        logs = db.session.query(LogItem).filter(
            LogItem.table == "Asset", LogItem.object_id == model.id).order_by(
                LogItem.datetime.desc()).all()

        return self.render(template,
                           model=model,
                           details_columns=self._details_columns,
                           get_value=self.get_detail_value,
                           return_url=return_url,
                           file_form=file_form,
                           logs=logs)
Esempio n. 16
0
    def edit_view(self):
        """Define Api for edit view.

        Returns:
            HTML page -- Html page for edit view

        """
        return_url = get_redirect_target() or self.get_url('.index_view')

        if not self.can_edit:
            return redirect(return_url)

        id_list = helpers.get_mdict_item_or_list(request.args, 'id')

        widget_data = convert_widget_data_to_dict(self.get_one(id_list))
        multi_lang_data = WidgetMultiLangData.get_by_widget_id(id_list)
        converted_data = convert_data_to_desgin_pack(widget_data,
                                                     multi_lang_data)
        model = convert_data_to_edit_pack(converted_data)
        if model is None:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        return self.render(config.WEKO_GRIDLAYOUT_ADMIN_EDIT_WIDGET_SETTINGS,
                           model=json.dumps(model),
                           return_url=return_url)
Esempio n. 17
0
    def invite(self):
        id = get_mdict_item_or_list(request.args, 'id')
        member = self.get_one(id)
        self._invite(member)

        flash('invitation sent')
        return redirect(url_for('members.index_view'))
Esempio n. 18
0
    def edit_view(self):
        """
            Edit model view
        """
        if self.support_flow:
            if '/edit/' in request.url:
                url = request.url.replace('edit', 'approve-edit-view')
            return redirect(url)
        return_url = get_redirect_target() or self.get_url('.index_view')

        if not self.can_edit:
            return redirect(return_url)

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return redirect(return_url)

        model = self.get_one(id)

        if model is None:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        form = self.edit_form(obj=model)
        if not hasattr(form,
                       '_validated_ruleset') or not form._validated_ruleset:
            self._validate_form_instance(ruleset=self._form_edit_rules,
                                         form=form)

        if self.validate_form(form):
            if self.update_model(form, model):
                flash(gettext('Record was successfully saved.'), 'success')
                if '_add_another' in request.form:
                    return redirect(
                        self.get_url('.create_view', url=return_url))
                elif '_continue_editing' in request.form:
                    return redirect(request.url)
                else:
                    # save button
                    return redirect(
                        self.get_save_return_url(model, is_created=False))

        if request.method == 'GET' or form.errors:
            self.on_form_prefill(form, id)

        form_opts = FormOpts(widget_args=self.form_widget_args,
                             form_rules=self._form_edit_rules)

        if self.edit_modal and request.args.get('modal'):
            template = self.edit_modal_template
        else:
            template = self.edit_template

        return self.render(template,
                           model=model,
                           form=form,
                           form_opts=form_opts,
                           return_url=return_url,
                           one_line_columns=self.one_line_columns)
Esempio n. 19
0
 def edit_view(self):
     id = get_mdict_item_or_list(request.args, 'id')
     if id is not None:
         user = db_session.query(User).get(id)
         if user and user.superuser and not current_user.superuser:
             flash("Only superusers may perform this action.")
             return redirect(get_redirect_target())
     return super().edit_view()
Esempio n. 20
0
 def status_view_ajax(self):
     id = get_mdict_item_or_list(request.args, 'id')
     if id is None:
         return redirect(get_redirect_target()
                         or self.get_url('.index_view'))
     outlet = self._process_request(id, request)
     status = power.get_status(outlet)
     return Response(json.dumps(status), mimetype="application/json")
Esempio n. 21
0
    def snapshots_view(self):
        id = get_mdict_item_or_list(request.args, 'id')
        if id is None or not ObjectId.is_valid(id):
            abort(404)

        master = self.model.objects.get_or_404(id=id)
        snapshots = self.get_snapshot_model().objects(master=id).order_by('-created_at')

        return self.render(self.snapshots_template, model=master, snapshots=snapshots)
Esempio n. 22
0
    def delete_snapshot(self):
        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            abort(404)

        snapshot_id = self.object_id_converter(request.form['id'])
        self.get_snapshot_model().objects(id=snapshot_id).delete()

        return redirect(url_for('.snapshots_view', id=id))
Esempio n. 23
0
    def make_thumbnail_view(self):
        id = get_mdict_item_or_list(request.args, 'id')
        model = self.get_one(id)

        model.make_thumbnail()
        db.session.add(model)
        log("Update", model, user=current_user)
        db.session.commit()
        flash("Thumbnail created", 'success')
        return redirect(url_for("file.details_view", id=id))
Esempio n. 24
0
    def action_view(self):

        # 这个页面需要访问的url里包含verb参数
        verb = request.args.get('verb', None)
        if verb is None or verb not in self._action_view_cfg:
            return abort(404)
        cfg = self._action_view_cfg[verb]
        if verb == 'approve' and\
                self.support_flow.func in flow_map['two_approve']:
            cfg = self._action_view_cfg['sec-approve']

        return_url = get_redirect_target() or self.get_url('.index_view')
        if not self.can_view_details:
            return redirect(return_url)

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return redirect(return_url)

        model = self.get_one(id)

        if model is None:
            return redirect(return_url)
        if self.support_flow:
            only_columns = self.review_details_columns +\
                self.support_flow.func.get_flow_columns(model.status)
        details_columns = self.get_column_names(only_columns, None)

        form_class = cfg.form

        if self.get_audit_form_class(model, verb):
            form_class = self.get_audit_form_class(model, verb)

        if request.method == 'POST':
            self.process_flow_form(form_class, model, verb)
            return redirect(return_url)

        form = self.get_flow_form(form_class, model, verb)

        return self.render(self.action_view_template,
                           action=self.get_url('.action_view',
                                               id=id,
                                               verb=verb),
                           model=model,
                           details_columns=details_columns,
                           get_value=self.get_list_value,
                           return_url=return_url,
                           cancel_url=return_url,
                           action_name=cfg.action_name,
                           icon_value=cfg.icon_value,
                           form=form,
                           agreed=cfg.agreed,
                           refuse=cfg.refuse,
                           one_line_columns=self.one_line_columns,
                           review_details_columns=self.review_details_columns)
Esempio n. 25
0
 def get_task_info(self):
     task_id = get_mdict_item_or_list(request.args, 'id')
     print('task_id ==> ', task_id)
     task = log_task_coll.find_one({'task_id': self._get_valid_id(task_id)})
     tmpl = 'admin/model/log_task_info.html'
     return self.render(
         tmpl,
         # get_value=self.get_list_value,
         get_value=lambda m, c: m[c],
         get_type=type,
         model=task)
Esempio n. 26
0
    def refresh_view(self):
        """
            Refresh key and secret
        """
        return_url = get_redirect_target() or self.get_url('.index_view')

        id = get_mdict_item_or_list(request.args, 'id')
        if id is not None:
            self.get_one(id).refresh()

        return redirect(return_url)
Esempio n. 27
0
    def rotate_view(self):
        id = get_mdict_item_or_list(request.args, 'id')
        model = self.get_one(id)

        if model.filename.lower().split('.')[-1] not in ('jpg', 'jpeg'):
            flash("Sorry, rotation is currently only available for JPEG files.", 'error')
            return redirect(url_for("file.details_view", id=id))
        
        rotation = get_mdict_item_or_list(request.args, 'rotation')

        model.rotate(int(rotation))
        db.session.add(model)
        log("Update", model, user=current_user, action="rotate", rotation=rotation)
        db.session.commit()
        flash("Image rotated", 'success')
        
        if request.args.get('refresh', False):
            return 'OK', 200, {'HX-Refresh': 'true'}

        return redirect(url_for("file.details_view", id=id))
Esempio n. 28
0
 def user_redirect_view(self):
     id = get_mdict_item_or_list(request.args, 'id')
     if id:
         server = self.get_one(id)
         if server:
             return redirect(
                 url_for('admin/users.edit_view',
                         id=server.admin_c.id,
                         url=self.get_url('.index_view')))
         else:
             flash(gettext('Does not exist.'), 'error')
             return redirect(return_url)
Esempio n. 29
0
 def read_view(self):
     data = {}
     return_url = url_for('.index_view')
     id = get_mdict_item_or_list(request.args, 'id')
     if id is None:
         return redirect(return_url)
     model = self.get_one(id)
     if model is None:
         return redirect(return_url)
     apply(getattr(self.support_flow(model), Read), (), dict(**data))
     self.session.commit()
     return redirect(return_url)
Esempio n. 30
0
    def edit_view(self):
        """
            Edit model view
        """
        return_url = self.get_return_url()
        model = self.validate_model()

        if not model:
            return redirect(return_url)

        csr_id = get_mdict_item_or_list(request.args, 'id')

        form = self.edit_form(obj=model)
        if not hasattr(form,
                       '_validated_ruleset') or not form._validated_ruleset:
            self._validate_form_instance(ruleset=self._form_edit_rules,
                                         form=form)

        if self.validate_form(form) and self.update_model(form, model):

            #  Trim the user name, if necessary.
            updated_csr = CSR.query.filter_by(csr_id=csr_id).first()

            check_uservalues(updated_csr)

            socketio.emit('clear_csr_cache', {"id": csr_id})
            socketio.emit('csr_update', {
                "csr_id": csr_id,
                "receptionist_ind": updated_csr.receptionist_ind
            },
                          room=current_user.office_id)

            flash(gettext('''Record was successfully saved.'''), 'success')

            request_redirect(self, return_url, model, request)

        if request.method == 'GET' or form.errors:
            self.on_form_prefill(form, id)

        form_opts = FormOpts(widget_args=self.form_widget_args,
                             form_rules=self._form_edit_rules)

        if self.edit_modal and request.args.get('modal'):
            template = self.edit_modal_template
        else:
            template = self.edit_template

        return self.render(template,
                           model=model,
                           form=form,
                           form_opts=form_opts,
                           return_url=return_url)
Esempio n. 31
0
    def resetpass_view(self):
        """
            Reset password view
        """
        return_url = get_redirect_target() or self.get_url('.index_view')

        if not self.can_edit:
            return redirect(return_url)

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return redirect(return_url)

        model = self.get_one(id)

        if model is None:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        form = self.action_form(obj=model)

        if not hasattr(form,
                       '_validated_ruleset') or not form._validated_ruleset:
            self._validate_form_instance(ruleset=form._form_edit_rules,
                                         form=form)

        if self.validate_form(form):
            if self.update_model(form, model):
                flash(gettext('Record was successfully saved.'), 'success')
                if '_add_another' in request.form:
                    return redirect(
                        self.get_url('.create_view', url=return_url))
                elif '_continue_editing' in request.form:
                    return redirect(request.url)
                else:
                    # save button
                    return redirect(
                        self.get_save_return_url(model, is_created=False))

        if request.method == 'GET' or form.errors:
            self.on_form_prefill(form, id)

        form_opts = FormOpts(widget_args=form.form_widget_args,
                             form_rules=form._form_edit_rules)

        template = 'model/resetpass.html'

        return self.render(template,
                           model=model,
                           form=form,
                           form_opts=form_opts,
                           return_url=return_url)
Esempio n. 32
0
    def auto_assign_view(self):
        id = get_mdict_item_or_list(request.args, 'id')
        model = self.get_one(id)

        asset_id = model.auto_assign()
        if asset_id:
            db.session.add(model)
            log("Update", model, user=current_user)
            db.session.commit()
            flash(f"Automatically assigned to asset #{asset_id:05}", 'success')
        else:
            flash("No RH barcode found.", 'success')
        return redirect(url_for("file.details_view", id=id))
Esempio n. 33
0
    def aircraft_details_view(self):
        sub = request.args.get('sub')
        return_url = get_redirect_target() or self.get_url('.index_view')

        if not self.can_view_details:
            return redirect(return_url)

        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return redirect(return_url)
        model = self.get_aircraft(id)

        if model is None:
            flash(gettext('Record does not exist.'), 'error')
            return redirect(return_url)

        # 获得绑定状态
        bind_status, bounded = self.get_bindable_status(model)

        # 获得当前飞机实例支持的绑定状态
        # 无需显示的绑定状态会在构建列表时剔除
        boundable_categories = [{
            'id': item[0],
            'name': item[1]
        } for item in support_due_list[model['planeType']] if item[2]]

        self._template_args.update({
            'sub':
            sub,
            'bind_status':
            bind_status,
            'bounded':
            bounded,
            'support_bounded_categories':
            boundable_categories,
        })

        find_method = self._delegate_to_sub('find_method') or self.get_list

        extra_args = self._delegate_to_sub('extra') or {}

        if callable(extra_args):
            extra_args = extra_args(model=model)

        self._template_args.update(**extra_args)
        self._template_args.update({
            'sub': sub,
            'time_formatter': datetime.time,
        })
        return self.render_aircraft_or_list(id, model, sub, return_url,
                                            find_method, **extra_args)
Esempio n. 34
0
    def create_snapshot(self):
        id = get_mdict_item_or_list(request.args, 'id')
        if id is None or not ObjectId.is_valid(id):
            abort(404)

        master = self.model.objects.get_or_404(id=id)

        self.get_snapshot_model().objects(master=id, published=True).update(published=False)

        snapshot = master.create_snapshot()
        snapshot.published = True
        snapshot.save()

        return redirect(url_for('.snapshots_view', id=id))
Esempio n. 35
0
    def edit_view(self):

        id = get_mdict_item_or_list(request.args, 'id')
        model = self.get_one(id)

        if not self.has_campaign_access(model):
            abort(404)

        draft_id = model.draft_id

        self._template_args['draft_id'] = draft_id
        form_data = campaign_service.get_draft(draft_id)
        form_output = form_data["data"] if form_data != None else {}
        self._template_args['form_data'] = json_util.dumps(form_output)
        return super(CampaignView, self).edit_view()
Esempio n. 36
0
 def can(self, operation='view'):
     obj_id = get_mdict_item_or_list(request.args, 'id') if has_request_context() else None
     obj = None if obj_id is None else self.get_one(obj_id)
     if obj is None:
         same_org = True
     else:
         if has_organization_field(obj):
             if obj.organization is None:
                 same_org = False
             else:
                 same_org = (obj.organization.id == current_user.organization.id)
         else:
             same_org = True
     role_assigned = same_org and current_user.is_authenticated and (self.role_identify + '_' + operation in get_user_roles())
     return (is_super_admin()) or (role_assigned)
Esempio n. 37
0
    def edit_menu(self):
        id = get_mdict_item_or_list(request.args, 'id')
        if id is None:
            return False

        def is_active(endpoint):
            return endpoint == request.url_rule.endpoint

        edit_menu = [{
            'url': url_for('.snapshots_view', id=id),
            'endpoint': self.endpoint+'.snapshots_view',
            'label': 'Snapshots',
            'is_active': is_active,
        }]

        return edit_menu
 def edit_view(self):
     """Event edit view"""
     events = DataGetter.get_all_events()
     event_id = get_mdict_item_or_list(request.args, 'id')
     self.name = "Event | Edit"
     event = DataGetter.get_object(Event, event_id)
     from ....forms.admin.event_form import EventForm
     self.form = EventForm(obj=event)
     if self.form.validate_on_submit():
         if is_event_admin_or_editor(event_id):
             DataManager.update_event(self.form, event)
             flash("Event updated")
         else:
             flash("You don't have permission!")
         return redirect(url_for('.index_view', event_id=event_id))
     return self.render('admin/model/edit_event.html',
                        form=self.form,
                        event_id=event_id,
                        events=events,
                        # owner=DataGetter.get_event_owner(event_id),
                        cancel_url=url_for('.index_view'))
Esempio n. 39
0
 def edit_view(self):
     """Event edit view"""
     events = DataGetter.get_all_events()
     event_id = get_mdict_item_or_list(request.args, 'id')
     self.name = "Event | Edit"
     event = DataGetter.get_event(event_id)
     from ....forms.admin.event_form import EventForm
     self.form = EventForm(obj=event)
     self.form.logo.choices=DataGetter.get_all_files_tuple()
     self.form.logo.choices.insert(0, ('', ''))
     if self.form.validate():
         if request.method == "POST":
             if is_event_admin_or_editor(event_id):
                 DataManager.update_event(self.form, event)
                 flash("Event updated")
             else:
                 flash("You don't have permission!")
             return redirect(url_for('.index_view', event_id=event_id))
     return self.render('admin/model/create_model.html',
                        form=self.form,
                        event_id=event_id,
                        events=events,
                        # owner=DataGetter.get_event_owner(event_id),
                        cancel_url=url_for('.index_view'))
Esempio n. 40
0
 def get_model_return_url(self):
     from flask_admin.helpers import get_redirect_target
     return_url = get_redirect_target() or self.get_url('.index_view')
     model_id = get_mdict_item_or_list(request.args, 'id')
     model = self.get_one(model_id)
     return model, return_url