Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        super(PGUserChangeForm, self).__init__(*args, **kwargs)
        # because the auth.User model is set to "blank=False" and the Django
        # auth.UserChangeForm is setup as a ModelForm, it will always validate
        # the "username" even though it is not present.  Thus the best way to
        # avoid the validation is to remove the "username" field, if it exists
        if self.fields.get('username'):
            del self.fields['username']

        self.fields['passwordinfo'].widget = TemplateRenderWidget(
            template='forms/widgets/community_auth_password_info.html',
            context={
                'type': self.password_type(self.instance),
            },
        )

        self.fields['logininfo'].widget = TemplateRenderWidget(
            template='forms/widgets/community_auth_usage_widget.html',
            context={
                'logins':
                exec_to_dict(
                    "SELECT s.name AS service, lastlogin, logincount FROM account_communityauthsite s INNER JOIN account_communityauthlastlogin l ON s.id=l.site_id WHERE user_id=%(userid)s ORDER BY lastlogin DESC",
                    {
                        'userid': self.instance.pk,
                    }),
            })
Esempio n. 2
0
File: admin.py Progetto: tpud/pgweb
    def __init__(self, *args, **kwargs):
        super(PGUserChangeForm, self).__init__(*args, **kwargs)
        # because the auth.User model is set to "blank=False" and the Django
        # auth.UserChangeForm is setup as a ModelForm, it will always validate
        # the "username" even though it is not present.  Thus the best way to
        # avoid the validation is to remove the "username" field, if it exists
        if self.fields.get('username'):
            del self.fields['username']

        self.fields['passwordinfo'].widget = TemplateRenderWidget(
            template='forms/widgets/community_auth_password_info.html',
            context={
                'type': self.password_type(self.instance),
            },
        )

        self.fields['logininfo'].widget = TemplateRenderWidget(
            template='forms/widgets/community_auth_usage_widget.html',
            context={
                'logins':
                exec_to_dict(
                    "SELECT s.name AS service, lastlogin, logincount FROM account_communityauthsite s INNER JOIN account_communityauthlastlogin l ON s.id=l.site_id WHERE user_id=%(userid)s ORDER BY lastlogin DESC",
                    {
                        'userid': self.instance.pk,
                    }),
            })

        self.fields[
            'email'].help_text = "Be EXTREMELY careful when changing an email address! It is almost ALWAYS better to reset the password on the user and have them change it on their own! Sync issues are common!"
        self.fields['extraemail'].widget = TemplateRenderWidget(
            template='forms/widgets/extra_email_list_widget.html',
            context={
                'emails':
                SecondaryEmail.objects.filter(user=self.instance).order_by(
                    '-confirmed', 'email'),
            },
        )
Esempio n. 3
0
def release_notes(request, major_version=None, minor_version=None):
    """Contains the main archive of release notes."""
    # this query gets a list of a unique set of release notes for each version of
    # PostgreSQL. From PostgreSQL 9.4+, release notes are only present for their
    # specific version of PostgreSQL, so all legacy release notes are present in
    # 9.3 and older
    # First the query identifies all of the release note files that have been loaded
    # into the docs. We will limit our lookup to release notes from 9.3 on up,
    # given 9.3 has all the release notes for PostgreSQL 9.3 and older
    # From there, it parses the version the release notes are for
    # from the file name, and breaks it up into "major" and "minor" version from
    # our understanding of how PostgreSQL version numbering is handled, which is
    # in 3 camps: 1 and older, 6.0 - 9.6, 10 - current
    # It is then put into a unique set
    # Lastly, we determine the next/previous versions (lead/lag) so we are able
    # to easily page between the different versions in the unique release note view
    # We only include the content if we are doing an actual lookup on an exact
    # major/minor release pair, to limit how much data we load into memory
    sql = """
    SELECT
        {content}
        file, major, minor,
        lag(minor) OVER (PARTITION BY major ORDER BY minor) AS previous,
        lead(minor) OVER (PARTITION BY major ORDER BY minor) AS next
    FROM (
        SELECT DISTINCT ON (file, major, minor)
            {content}
            file,
            CASE
                WHEN v[1]::int >= 10 THEN v[1]::numeric
                WHEN v[1]::int <= 1 THEN v[1]::int
                ELSE array_to_string(v[1:2], '.')::numeric END AS major,
            COALESCE(
                CASE
                    WHEN v[1]::int >= 10 THEN v[2]
                    WHEN v[1]::int <= 1 THEN '.' || v[2]
                    ELSE v[3]
                END::numeric, 0
            ) AS minor
        FROM (
            SELECT
                {content}
                file,
                string_to_array(regexp_replace(file, 'release-(.*)\\.htm.*', '\\1'), '-') AS v
            FROM docs
            WHERE file ~ '^release-\\d+' AND version >= 9.3
        ) r
    ) rr
    """
    params = []
    # if the major + minor version are provided, then we want to narrow down
    # the results to all the release notes for the minor version, as we need the
    # list of the entire set in order to generate the nice side bar in the release
    # notes
    # otherwise ensure the release notes are returned in order
    if major_version is not None and minor_version is not None:
        # a quick check to see if major is one of 6 - 9 as a whole number. If
        # it is, this may be because someone is trying to up a major version
        # directly from the URL, e.g. "9.1", even through officially the release
        # number was "9.1.0".
        # anyway, we shouldn't 404, but instead transpose from "9.1" to "9.1.0".
        # if it's not an actual PostgreSQL release (e.g. "9.9"), then it will
        # 404 at a later step.
        if major_version in ['6', '7', '8', '9']:
            major_version = "{}.{}".format(major_version, minor_version)
            minor_version = '0'
        # at this point, include the content
        sql = sql.format(content="content,")
        # restrict to the major version, order from latest to earliest minor
        sql = """{}
        WHERE rr.major = %s
        ORDER BY rr.minor DESC""".format(sql)
        params += [major_version]
    else:
        sql = sql.format(content="")
        sql += """
        ORDER BY rr.major DESC, rr.minor DESC;
        """
    # run the query, loading a list of dict that contain all of the release
    # notes that are filtered out by the query
    release_notes = exec_to_dict(sql, params)
    # determine which set of data to pass to the template:
    # if both major/minor versions are present, we will load the release notes
    # if neither are present, we load the list of all of the release notes to list out
    if major_version is not None and minor_version is not None:
        # first, see if any release notes were returned; if not, raise a 404
        if not release_notes:
            raise Http404()
        # next, see if we can find the specific release notes we are looking for
        # format what the "minor" version should look like
        try:
            minor = Decimal('0.{}'.format(minor_version) if major_version in
                            ['0', '1'] else minor_version)
        except TypeError:
            raise Http404()
        try:
            release_note = [r for r in release_notes if r['minor'] == minor][0]
        except IndexError:
            raise Http404()
        # of course, if nothing is found, return a 404
        if not release_note:
            raise Http404()
        context = {
            'major_version': major_version,
            'minor_version': minor_version,
            'release_note': release_note,
            'release_notes': release_notes
        }
    else:
        context = {'release_notes': release_notes}
    return render_pgweb(request, 'docs', 'docs/release_notes.html', context)
Esempio n. 4
0
File: views.py Progetto: jkatz/pgweb
def release_notes(request, major_version=None, minor_version=None):
    """Contains the main archive of release notes."""
    # this query gets a list of a unique set of release notes for each version of
    # PostgreSQL. From PostgreSQL 9.4+, release notes are only present for their
    # specific version of PostgreSQL, so all legacy release notes are present in
    # 9.3 and older
    # First the query identifies all of the release note files that have been loaded
    # into the docs. We will limit our lookup to release notes from 9.3 on up,
    # given 9.3 has all the release notes for PostgreSQL 9.3 and older
    # From there, it parses the version the release notes are for
    # from the file name, and breaks it up into "major" and "minor" version from
    # our understanding of how PostgreSQL version numbering is handled, which is
    # in 3 camps: 1 and older, 6.0 - 9.6, 10 - current
    # It is then put into a unique set
    # Lastly, we determine the next/previous versions (lead/lag) so we are able
    # to easily page between the different versions in the unique release note view
    # We only include the content if we are doing an actual lookup on an exact
    # major/minor release pair, to limit how much data we load into memory
    sql = """
    SELECT
        {content}
        file, major, minor,
        lag(minor) OVER (PARTITION BY major ORDER BY minor) AS previous,
        lead(minor) OVER (PARTITION BY major ORDER BY minor) AS next
    FROM (
        SELECT DISTINCT ON (file, major, minor)
            {content}
            file,
            CASE
                WHEN v[1]::int >= 10 THEN v[1]::numeric
                WHEN v[1]::int <= 1 THEN v[1]::int
                ELSE array_to_string(v[1:2], '.')::numeric END AS major,
            COALESCE(
                CASE
                    WHEN v[1]::int >= 10 THEN v[2]
                    WHEN v[1]::int <= 1 THEN '.' || v[2]
                    ELSE v[3]
                END::numeric, 0
            ) AS minor
        FROM (
            SELECT
                {content}
                file,
                string_to_array(regexp_replace(file, 'release-(.*)\.htm.*', '\\1'), '-') AS v
            FROM docs
            WHERE file ~ '^release-\d+' AND version >= 9.3
        ) r
    ) rr
    """
    params = []
    # if the major + minor version are provided, then we want to narrow down
    # the results to all the release notes for the minor version, as we need the
    # list of the entire set in order to generate the nice side bar in the release
    # notes
    # otherwise ensure the release notes are returned in order
    if major_version is not None and minor_version is not None:
        # at this point, include the content
        sql = sql.format(content="content,")
        # restrict to the major version, order from latest to earliest minor
        sql = """{}
        WHERE rr.major = %s
        ORDER BY rr.minor DESC""".format(sql)
        params += [major_version]
    else:
        sql = sql.format(content="")
        sql += """
        ORDER BY rr.major DESC, rr.minor DESC;
        """
    # run the query, loading a list of dict that contain all of the release
    # notes that are filtered out by the query
    release_notes = exec_to_dict(sql, params)
    # determine which set of data to pass to the template:
    # if both major/minor versions are present, we will load the release notes
    # if neither are present, we load the list of all of the release notes to list out
    if major_version is not None and minor_version is not None:
        # first, see if any release notes were returned; if not, raise a 404
        if not release_notes:
            raise Http404()
        # next, see if we can find the specific release notes we are looking for
        # format what the "minor" version should look like
        try:
            minor = Decimal('0.{}'.format(minor_version) if major_version in ['0', '1'] else minor_version)
        except TypeError:
            raise Http404()
        try:
            release_note = [r for r in release_notes if r['minor'] == minor][0]
        except IndexError:
            raise Http404()
        # of course, if nothing is found, return a 404
        if not release_note:
            raise Http404()
        context = {
            'major_version': major_version,
            'minor_version': minor_version,
            'release_note': release_note,
            'release_notes': release_notes
        }
    else:
        context = {'release_notes': release_notes}
    return render_pgweb(request, 'docs', 'docs/release_notes.html', context)