예제 #1
0
def get_application_terms_of_use_line1():
    """
    Get application usage terms from config
    :return:
    """
    _company_name = config.get("COMPANY_NAME")
    return config.get('APPLICATION_TERMS_OS_USE_LINE1') + _company_name
예제 #2
0
def display_app_name():
    """
    Display Application name during start up.
    :return: None
    """
    _app_title = config.get('APPLICATION_SHORT_TITLE').upper() or config.get(
        'APPLICATION_TITLE').upper()
    _env = config.get('ENVIRONMENT').lower()
    result = pyfiglet.figlet_format(_app_title)
    print(result)
    print("Environment: {}".format(_env))
    print("\n")
예제 #3
0
def validate_avatar_file(file_upload):
    """
    Validate the avatar uploaded or updated for an employee
    :param file_upload: class UploadedFile
    :return: Boolean
    """

    _allowed_formats = tuple(config.get('AVATAR_FILE_FORMATS', ["png", "jpeg", "jpg"]))

    file_name, file_ext = os.path.splitext(file_upload.name)
    if not file_ext or file_ext.replace(".", "").lower() not in _allowed_formats:
        raise err.ValidationError({
            "upload_avatar": "File not in required format only allowed format is png, jpeg and jpg"
        })

    if file_upload.size > int(config.get('MAX_AVATAR_SIZE_BYTES')):
        raise err.ValidationError({
            "avatar": "Uploaded image file exceeded limit."
        })

    return True
예제 #4
0
def send_email_create_employee(to):
    """
    Sends Subject and body to the recently created employee
    :return: tuple
    """
    log.info("Sending an email to the new employee")
    log.info(to)
    if isinstance(to, list) or isinstance(to, tuple):
        if len(to) > 1:
            raise err.ValidationError(
                "This should not happen. On create employee, email is sent to employee only"
            )

    validators.email_validator("work_email", to[0])
    user = u.get_user_given_email(to[0])
    sub = "Admin has created your profile. Please reset your password"
    body = """
    Hi {first_name} {last_name},

    Welcome to {application_name}!!

    Please use this link to reset your password and login to your account to update your profile.

    Password reset link:{reset_link}

    Yours,

    Admin,
    {company_name}
    """.format(first_name=user.first_name,
               last_name=user.last_name,
               application_name=config.get("APPLICATION_TITLE"),
               reset_link="",
               company_name=config.get("COMPANY_NAME"))

    return sub, body
예제 #5
0
def get_application_terms_of_use_copyrights():
    """
    Get application usage terms from config
    :return:
    """
    return config.get('APPLICATION_TERMS_OS_USE_COPYRIGHT')
예제 #6
0
def get_application_short_title():
    """
    Get application short title from config
    :return: str
    """
    return config.get('APPLICATION_SHORT_TITLE', "Short title not given")
예제 #7
0
def get_application_title():
    """
    Get the application title from the config
    :return: str
    """
    return config.get("APPLICATION_TITLE", "Title not given")
예제 #8
0
    def app_route(self, route):
        """
        Register app redirects using route.register()

        This will be completely open and same as django url dispatcher. However,
        every url should have a url_key (friendly name). This url_key is used used to
        override any existing url/views in any extension.

        Django allows duplicate url patterns and always takes the first match. Hence url_key is used to take the latest
        duplicate url allowing us to modify any url

        So route.register() has 2 arguments
            - url_key: str (friendly name to each url)
            - django_urlcof_value: Same as django urlpatterns

        e.g.:

        route.register(
            url_key=about_blog_id,
            django_urlconf_value=path('about/', views.about, {'blog_id': 3})
        )

         route.register(
            url_key=author-polls,
            django_urlconf_value=path('author-polls/', include('polls.urls', namespace='author-polls'))
        )

        So if you give url_key=author_polls in some other extention all author-polls view function are replace with new
        views.


        :param route: class (EMPAppRoutes)
        :return: None
        """

        # Route for api
        log.info("Registering api route")
        route.register(url_key="app_api",
                       django_urlconf_value=path('{}<action_name>'.format(
                           config.get('APPLICATION_API_ENDPOINT')),
                                                 EMAppAPIView.as_view(),
                                                 name='app_api'))

        route.register(url_key="admin",
                       django_urlconf_value=path('admin/', admin.site.urls))

        # Register Login page
        route.register(url_key="login",
                       django_urlconf_value=path('login/',
                                                 EMAppLoginView.as_view(),
                                                 name="login"))

        # Register Logout
        route.register(
            url_key="logout",
            django_urlconf_value=path(
                'logout/',
                EMAppLogoutView.as_view(extra_context={'next': "/login/"}),
                name="logout"))

        # Change password
        route.register(
            url_key="change_password",
            django_urlconf_value=path(
                'change-password/',
                EMAppPasswordChangeView.as_view(success_url='/logout'),
                name='change_password'))

        # Reset Password
        route.register(
            url_key="password_reset",
            django_urlconf_value=path(
                'password-reset/',
                EMAppPasswordResetView.as_view(
                    subject_template_name=
                    'registration/password_reset_subject.txt',
                    email_template_name='registration/password_reset_email.html'
                ),
                name='password_reset'))

        # Reset password done
        route.register(url_key="password_reset_done",
                       django_urlconf_value=path(
                           'password-reset/done/',
                           EMAppPasswordResetDoneView.as_view(),
                           name='password_reset_done'))

        # Confirm reset password url that will be sent to an email
        route.register(url_key="password_reset_confirm",
                       django_urlconf_value=path(
                           'password-reset-confirm/<uidb64>/<token>/',
                           EMAppPasswordResetConfirmView.as_view(),
                           name='password_reset_confirm'))

        # Password reset complete
        route.register(url_key="password_reset_complete",
                       django_urlconf_value=path(
                           'password-reset-complete/',
                           EMAppPasswordResetCompleteView.as_view(),
                           name='password_reset_complete'))

        return None