Exemple #1
0
from flask_login import current_user
from flask_wtf.file import FileField, file_required
from werkzeug.exceptions import BadRequest, NotFound
from werkzeug.utils import secure_filename

from abilian.core.models.subjects import User
from abilian.core.util import unwrap
from abilian.web import csrf, url_for
from abilian.web.blueprints import Blueprint
from abilian.web.forms import Form
from abilian.web.views import JSONView, View

if typing.TYPE_CHECKING:
    from abilian.web.uploads import FileUploadsExtension

bp = Blueprint("uploads", __name__, url_prefix="/upload")


class UploadForm(Form):

    file = FileField(validators=(file_required(), ))


class BaseUploadsView:
    uploads: "FileUploadsExtension"
    user: User

    def prepare_args(self, args, kwargs):
        args, kwargs = super().prepare_args(args, kwargs)
        self.uploads = current_app.extensions["uploads"]
        self.user = unwrap(current_user)
Exemple #2
0
from flask import (render_template, request, flash, session, redirect, url_for,
                   current_app, make_response)
import six
from six import text_type

from abilian.services import get_service
from abilian.services.security import Admin
from abilian.core.models.subjects import User
from abilian.core.commands import config as cmd_config
from abilian.core.extensions import csrf
from abilian.services.security import Anonymous
from abilian.web.blueprints import Blueprint

logger = logging.getLogger(__name__)
setup = Blueprint('setup',
                  __name__,
                  allowed_roles=Anonymous,
                  template_folder='templates')

# list supported dialects and detect unavailable ones due to missing dbapi
# module ('psycopg2' missing for example)

_dialects = OrderedDict((
    ('sqlite', u'SQLite (for demo)'),
    ('postgres', u'PostgreSQL'),
))

_dialects_unavailable = OrderedDict()

for dialect, label in six.iteritems(_dialects):
    d = sa.dialects.registry.load(dialect)
    try:
Exemple #3
0
from flask.blueprints import BlueprintSetupState
from werkzeug.exceptions import BadRequest
from werkzeug.utils import redirect

from abilian.core.entities import Entity
from abilian.core.models.attachment import Attachment, supports_attachments
from abilian.i18n import _, _l
from abilian.web import nav, url_for
from abilian.web.action import ButtonAction, actions
from abilian.web.blueprints import Blueprint
from abilian.web.views import BaseObjectView, ObjectCreate, ObjectDelete, \
    ObjectEdit

from .forms import AttachmentForm

bp = Blueprint("attachments", __name__, url_prefix="/attachments")


def _default_attachment_view(obj, obj_type, obj_id, **kwargs):
    if not hasattr(obj, "entity"):
        return url_for("attachments.entity", object_id=obj_id)
    entity = obj.entity
    return url_for(entity, _anchor=f"attachment-{obj.id}")


@bp.record_once
def register_default_view(state: BlueprintSetupState) -> None:
    state.app.default_view.register(Attachment, _default_attachment_view)


UPLOAD_BUTTON = ButtonAction("form",
Exemple #4
0
from six import text_type
from werkzeug.exceptions import BadRequest

from abilian.core.entities import Entity
from abilian.core.models.comment import Comment, is_commentable
from abilian.core.util import utc_dt
from abilian.i18n import _, _l
from abilian.web import nav, url_for
from abilian.web.action import ButtonAction, actions
from abilian.web.blueprints import Blueprint
from abilian.web.views.object import CANCEL_BUTTON, ObjectCreate, \
    ObjectDelete, ObjectEdit

from .forms import CommentForm

bp = Blueprint("comments", __name__, url_prefix="/comments")


def _default_comment_view(obj, obj_type, obj_id, **kwargs):
    entity = obj.entity
    return url_for(entity, _anchor="comment-{}".format(obj.id))


@bp.record_once
def register_default_view(state):
    state.app.default_view.register(Comment, _default_comment_view)


COMMENT_BUTTON = ButtonAction("form",
                              "edit",
                              btn_class="primary",
Exemple #5
0
    render_template,
    request,
    session,
    url_for,
)

from abilian.core.extensions import csrf, db
from abilian.core.models.subjects import User
from abilian.core.util import unwrap
from abilian.services import get_service
from abilian.services.security import Admin, Anonymous
from abilian.web.blueprints import Blueprint

logger = logging.getLogger(__name__)
setup = Blueprint("setup",
                  __name__,
                  allowed_roles=Anonymous,
                  template_folder="templates")

# list supported dialects and detect unavailable ones due to missing dbapi
# module ('psycopg2' missing for example)

_dialects = OrderedDict(
    (("sqlite", "SQLite (for demo)"), ("postgresql", "PostgreSQL")))

_dialects_unavailable = OrderedDict()  # type: Dict[Text, Text]

for dialect, _label in _dialects.items():
    d = sa.dialects.registry.load(dialect)
    try:
        d.dbapi()
    except ImportError as e:
Exemple #6
0
from abilian.core.util import fqcn
from abilian.i18n import _, _l
from abilian.web import csrf, url_for, views
from abilian.web.action import Endpoint, FAIcon
from abilian.web.blueprints import Blueprint
from abilian.web.frontend import ModuleAction, ModuleActionDropDown, \
    ModuleActionGroupItem, ModuleComponent, ModuleView

from .manager import ExcelManager
from .tasks import export as export_task
from .util import XLSX_MIME

logger = logging.getLogger(__name__)

bp = Blueprint("crm_excel", __name__, url_prefix="/excel")


class _ItemUpdate(object):
    """Holds item update data.

    Used in import views.

    :param item_id: primary key
    :param attrs: list of attributes, in received order
    :param signature: verify @attrs authenticity
    :param data: dict attr => new value. Keys must be in attrs
    """

    def __init__(self, item_id, attrs, signature, data):
        self.id = item_id
Exemple #7
0
from werkzeug.exceptions import BadRequest
from flask import current_app, send_file

from abilian.i18n import _, _l
from abilian.core.entities import Entity
from abilian.core.models.attachment import Attachment, is_support_attachments
from abilian.web import url_for, nav
from abilian.web.blueprints import Blueprint
from abilian.web.action import actions, ButtonAction
from abilian.web.views import (
  BaseObjectView, ObjectCreate, ObjectDelete, ObjectEdit,
)

from .forms import AttachmentForm

bp = Blueprint('attachments', __name__, url_prefix='/attachments')


def _default_attachment_view(obj, obj_type, obj_id, **kwargs):
  entity = obj.entity
  return url_for(entity, _anchor='attachment-{}'.format(obj.id))


@bp.record_once
def register_default_view(state):
  state.app.default_view.register(Attachment, _default_attachment_view)

UPLOAD_BUTTON = ButtonAction('form', 'edit', btn_class='primary',
                             title=_l(u'Send'))

Exemple #8
0
from werkzeug import secure_filename
from werkzeug.exceptions import BadRequest, NotFound
from flask import current_app, send_file, jsonify
from flask.signals import request_tearing_down
from flask_login import current_user
from flask_wtf.file import FileField, file_required

from abilian.core.util import pdb_on_error

from abilian.web import csrf, url_for
from abilian.web.forms import Form
from abilian.web.blueprints import Blueprint
from abilian.web.views import View, JSONView

bp = Blueprint('uploads', __name__, url_prefix='/upload')

class UploadForm(Form):

  file = FileField(validators=(file_required(),))


class BaseUploadsView(object):

  def prepare_args(self, args, kwargs):
    args, kwargs = super(BaseUploadsView, self).prepare_args(args, kwargs)
    self.uploads = current_app.extensions['uploads']
    self.user = current_user._get_current_object()
    return args, kwargs

Exemple #9
0
# coding=utf-8
""""""
from flask import current_app
from werkzeug.exceptions import BadRequest

from abilian.core.entities import Entity
from abilian.core.models.tag import Tag
from abilian.i18n import _l
from abilian.web import url_for
from abilian.web.blueprints import Blueprint
from abilian.web.views import BaseObjectView, JSONView, ObjectCreate, \
    ObjectDelete, ObjectEdit

from .forms import TagForm

bp = Blueprint("tags", __name__, url_prefix="/tags", template_folder="templates")


class BaseTagView:
    """Mixin for tag views."""

    Model = Tag
    Form = TagForm

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.extension = current_app.extensions["tags"]


class TagEdit(BaseTagView, ObjectEdit):
    _message_success = _l("Tag edited")
Exemple #10
0
from flask_login import current_user
from werkzeug.exceptions import BadRequest

from abilian.core.entities import Entity
from abilian.core.models.comment import Comment, is_commentable
from abilian.core.util import utc_dt
from abilian.i18n import _, _l
from abilian.web import nav, url_for
from abilian.web.action import ButtonAction, actions
from abilian.web.blueprints import Blueprint
from abilian.web.views.object import CANCEL_BUTTON, ObjectCreate, \
    ObjectDelete, ObjectEdit

from .forms import CommentForm

bp = Blueprint("comments", __name__, url_prefix="/comments")


def _default_comment_view(obj, obj_type, obj_id, **kwargs):
    entity = obj.entity
    return url_for(entity, _anchor=f"comment-{obj.id}")


@bp.record_once
def register_default_view(state):
    state.app.default_view.register(Comment, _default_comment_view)


COMMENT_BUTTON = ButtonAction("form", "edit", btn_class="primary", title=_l("Post"))

Exemple #11
0
from werkzeug.exceptions import BadRequest
from flask_login import current_user

from abilian.i18n import _, _l
from abilian.core.entities import Entity
from abilian.core.models.comment import Comment, is_commentable
from abilian.core.util import utc_dt
from abilian.web import url_for, nav
from abilian.web.blueprints import Blueprint
from abilian.web.action import actions, ButtonAction
from abilian.web.views.object import (
  ObjectEdit, ObjectCreate, ObjectDelete, CANCEL_BUTTON,
)
from .forms import CommentForm

bp = Blueprint('comments', __name__, url_prefix='/comments')

def _default_comment_view(obj, obj_type, obj_id, **kwargs):
  entity = obj.entity
  return url_for(entity, _anchor='comment-{}'.format(obj.id))


@bp.record_once
def register_default_view(state):
  state.app.default_view.register(Comment, _default_comment_view)

COMMENT_BUTTON = ButtonAction('form', 'edit', btn_class='primary',
                              title=_l(u'Post'))


class BaseCommentView(object):
Exemple #12
0
from abilian.core.entities import Entity
from abilian.core.models.tag import Tag
from abilian.web import url_for
from abilian.web.blueprints import Blueprint
from abilian.web.views import (
    JSONView,
    BaseObjectView,
    ObjectEdit,
    ObjectCreate,
    ObjectDelete,
)

from .forms import TagForm

bp = Blueprint('tags',
               __name__,
               url_prefix='/tags',
               template_folder='templates')


class BaseTagView(object):
    """
  Mixin for tag views
  """
    Model = Tag
    Form = TagForm

    def __init__(self, *args, **kwargs):
        super(BaseTagView, self).__init__(*args, **kwargs)
        self.extension = current_app.extensions['tags']

    def view_url(self):
Exemple #13
0
from werkzeug.exceptions import BadRequest
from flask import current_app

from abilian.i18n import _l
from abilian.core.entities import Entity
from abilian.core.models.tag import Tag
from abilian.web import url_for
from abilian.web.blueprints import Blueprint
from abilian.web.views import (
  JSONView, BaseObjectView, ObjectEdit, ObjectCreate, ObjectDelete,
)

from .forms import TagForm

bp = Blueprint('tags', __name__, url_prefix='/tags',
               template_folder='templates')


class BaseTagView(object):
  """
  Mixin for tag views
  """
  Model = Tag
  Form = TagForm

  def __init__(self, *args, **kwargs):
    super(BaseTagView, self).__init__(*args, **kwargs)
    self.extension = current_app.extensions['tags']

  def view_url(self):
    return url_for()
Exemple #14
0
# coding=utf-8
""""""
from flask import current_app, jsonify, send_file
from flask_login import current_user
from flask_wtf.file import FileField, file_required
from werkzeug.exceptions import BadRequest, NotFound
from werkzeug.utils import secure_filename

from abilian.core.util import unwrap
from abilian.web import csrf, url_for
from abilian.web.blueprints import Blueprint
from abilian.web.forms import Form
from abilian.web.views import JSONView, View

bp = Blueprint("uploads", __name__, url_prefix="/upload")


class UploadForm(Form):

    file = FileField(validators=(file_required(),))


class BaseUploadsView:
    def prepare_args(self, args, kwargs):
        args, kwargs = super().prepare_args(args, kwargs)
        self.uploads = current_app.extensions["uploads"]
        self.user = unwrap(current_user)
        return args, kwargs


class NewUploadView(BaseUploadsView, JSONView):
Exemple #15
0
from abilian.i18n import _, _l
from abilian.core.entities import Entity
from abilian.core.models.attachment import Attachment, is_support_attachments
from abilian.web import url_for, nav
from abilian.web.blueprints import Blueprint
from abilian.web.action import actions, ButtonAction
from abilian.web.views import (
    BaseObjectView,
    ObjectCreate,
    ObjectDelete,
    ObjectEdit,
)

from .forms import AttachmentForm

bp = Blueprint('attachments', __name__, url_prefix='/attachments')


def _default_attachment_view(obj, obj_type, obj_id, **kwargs):
    entity = obj.entity
    return url_for(entity, _anchor='attachment-{}'.format(obj.id))


@bp.record_once
def register_default_view(state):
    state.app.default_view.register(Attachment, _default_attachment_view)


UPLOAD_BUTTON = ButtonAction('form',
                             'edit',
                             btn_class='primary',
Exemple #16
0
from flask import current_app
from werkzeug.exceptions import BadRequest

from abilian.core.entities import Entity
from abilian.core.models.tag import Tag
from abilian.i18n import _l
from abilian.web import url_for
from abilian.web.blueprints import Blueprint
from abilian.web.views import BaseObjectView, JSONView, ObjectCreate, \
    ObjectDelete, ObjectEdit

from .forms import TagForm

bp = Blueprint("tags",
               __name__,
               url_prefix="/tags",
               template_folder="templates")


class BaseTagView:
    """Mixin for tag views."""

    Model = Tag
    Form = TagForm

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.extension = current_app.extensions["tags"]


class TagEdit(BaseTagView, ObjectEdit):
Exemple #17
0
from abilian.core.extensions import csrf, db
from abilian.core.models.subjects import User
from abilian.core.signals import auth_failed
from abilian.core.util import md5, unwrap
from abilian.i18n import _, render_template_i18n
from abilian.services.security import Anonymous
from abilian.web.blueprints import Blueprint

from .models import LoginSession

__all__ = ("login",)

login = Blueprint(
    "login",
    __name__,
    url_prefix="/user",
    allowed_roles=Anonymous,
    template_folder="templates",
)
route = login.route


#
# Login / Logout
#
@route("/login")
def login_form():
    """Display the login form."""
    next_url = get_redirect_target()
    return render_template("login/login.html", next_url=next_url)
Exemple #18
0
from werkzeug import secure_filename
from werkzeug.exceptions import BadRequest, NotFound
from flask import current_app, send_file, jsonify
from flask.signals import request_tearing_down
from flask_login import current_user
from flask_wtf.file import FileField, file_required

from abilian.core.util import pdb_on_error

from abilian.web import csrf, url_for
from abilian.web.forms import Form
from abilian.web.blueprints import Blueprint
from abilian.web.views import View, JSONView

bp = Blueprint('uploads', __name__, url_prefix='/upload')


class UploadForm(Form):

    file = FileField(validators=(file_required(), ))


class BaseUploadsView(object):
    def prepare_args(self, args, kwargs):
        args, kwargs = super(BaseUploadsView, self).prepare_args(args, kwargs)
        self.uploads = current_app.extensions['uploads']
        self.user = current_user._get_current_object()
        return args, kwargs