コード例 #1
0
ファイル: views.py プロジェクト: bakaoh/web
def bounty_details(request, ghuser='', ghrepo='', ghissue=0):
    """Display the bounty details."""
    _access_token = request.session.get('access_token')
    profile_id = request.session.get('profile_id')
    issueURL = 'https://github.com/' + ghuser + '/' + ghrepo + '/issues/' + ghissue if ghissue else request.GET.get(
        'url')

    # try the /pulls url if it doesnt exist in /issues
    try:
        assert Bounty.objects.current().filter(github_url=issueURL).exists()
    except:
        issueURL = 'https://github.com/' + ghuser + '/' + ghrepo + '/pull/' + ghissue if ghissue else request.GET.get(
            'url')
        print(issueURL)
        pass

    bounty_url = issueURL
    params = {
        'issueURL': issueURL,
        'title': 'Issue Details',
        'card_title': 'Funded Issue Details | Gitcoin',
        'avatar_url': static('v2/images/helmet.png'),
        'active': 'bounty_details',
        'is_github_token_valid': is_github_token_valid(_access_token),
        'github_auth_url': get_auth_url(request.path),
        'profile_interested': False,
        "newsletter_headline": "Be the first to know about new funded issues."
    }

    if bounty_url:
        try:
            bounties = Bounty.objects.current().filter(github_url=bounty_url)
            if bounties:
                bounty = bounties.order_by('pk').first()
                # Currently its not finding anyting in the database
                if bounty.title and bounty.org_name:
                    params[
                        'card_title'] = f'{bounty.title} | {bounty.org_name} Funded Issue Detail | Gitcoin'
                    params['title'] = params['card_title']
                    params['card_desc'] = ellipses(
                        bounty.issue_description_text, 255)

                params['bounty_pk'] = bounty.pk
                params[
                    'interested_profiles'] = bounty.interested.select_related(
                        'profile').all()
                params['avatar_url'] = bounty.local_avatar_url
                if profile_id:
                    profile_ids = list(
                        params['interested_profiles'].values_list('profile_id',
                                                                  flat=True))
                    params['profile_interested'] = request.session.get(
                        'profile_id') in profile_ids
        except Bounty.DoesNotExist:
            pass
        except Exception as e:
            print(e)
            logging.error(e)

    return TemplateResponse(request, 'bounty_details.html', params)
コード例 #2
0
def bounty_details(request):

    params = {
        'issueURL': request.GET.get('issue_'),
        'title': 'Issue Details',
        'card_title': 'Funded Issue Details | Gitcoin',
        'avatar_url': 'https://gitcoin.co/static/v2/images/helmet.png',
        'active': 'bounty_details',
    }

    try:
        b = Bounty.objects.get(github_url=request.GET.get('url'),
                               current_bounty=True)
        if b.title:
            params[
                'card_title'] = "{} | {} Funded Issue Detail | Gitcoin".format(
                    b.title, b.org_name)
            params['title'] = params['card_title']
            params['card_desc'] = ellipses(b.issue_description_text, 255)
        params['avatar_url'] = b.local_avatar_url
    except Exception as e:
        print(e)
        pass

    return TemplateResponse(request, 'bounty_details.html', params)
コード例 #3
0
ファイル: views.py プロジェクト: spicer23/web
def external_bounties_show(request, issuenum, slug):
    """Handle Dummy External Bounties show page.

    Args:
        issuenum (int): The Github issue number.
        slug (str): The external bounty slug represenation.

    Returns:
        django.TemplateResponse: The external bounty details view.

    """
    print('************')
    print(issuenum)
    if issuenum == '':
        return external_bounties_index(request)

    try:
        bounty = ExternalBounty.objects.get(pk=issuenum, active=True)
    except Exception:
        raise Http404

    external_bounty = {}
    external_bounty_result = bounty
    external_bounty['created_on'] = external_bounty_result.created_on
    external_bounty['title'] = external_bounty_result.title
    external_bounty['crypto_price'] = round(
        external_bounty_result.amount,
        2) if external_bounty_result.amount else None
    external_bounty[
        'crypto_label'] = external_bounty_result.amount_denomination
    external_bounty['fiat_price'] = round(
        external_bounty_result.amount,
        2) if external_bounty_result.amount else None
    external_bounty['source'] = external_bounty_result.source_project
    external_bounty['content'] = strip_html(external_bounty_result.description)
    external_bounty['action_url'] = external_bounty_result.action_url
    external_bounty['avatar'] = external_bounty_result.avatar
    external_bounty['fiat_price'] = external_bounty_result.fiat_price

    params = {
        'active': 'offchain',
        'title': 'Bounty Universe Explorer',
        'card_desc': ellipses(external_bounty['content'], 300),
        "bounty": external_bounty,
    }

    # determine whether this should be a no_index_or_not
    # the below list may want to keep their SEO juice
    no_index_tag_list = ['HackerOne', 'OpenBounty', 'Bounty0x', 'BountySource']
    no_index = False
    for tag in no_index_tag_list:
        if tag in bounty.tags:
            no_index = True
    if no_index:
        params['no_index'] = True

    return TemplateResponse(request, 'external_bounties_show.html', params)
コード例 #4
0
def bounty_details(request):
    """Display the bounty details."""
    _access_token = request.session.get('access_token')
    profile_id = request.session.get('profile_id')
    bounty_url = request.GET.get('url')
    params = {
        'issueURL': request.GET.get('issue_'),
        'title': 'Issue Details',
        'card_title': 'Funded Issue Details | Gitcoin',
        'avatar_url': 'https://gitcoin.co/static/v2/images/helmet.png',
        'active': 'bounty_details',
        'is_github_token_valid': is_github_token_valid(_access_token),
        'github_auth_url': get_auth_url(request.path),
        'profile_interested': False,
        "newsletter_headline": "Be the first to know about new funded issues."
    }

    if bounty_url:
        try:
            bounties = Bounty.objects.current().filter(github_url=bounty_url)
            if bounties:
                bounty = bounties.order_by('pk').first()
                # Currently its not finding anyting in the database
                if bounty.title and bounty.org_name:
                    params[
                        'card_title'] = f'{bounty.title} | {bounty.org_name} Funded Issue Detail | Gitcoin'
                    params['title'] = params['card_title']
                    params['card_desc'] = ellipses(
                        bounty.issue_description_text, 255)

                params['bounty_pk'] = bounty.pk
                params[
                    'interested_profiles'] = bounty.interested.select_related(
                        'profile').all()
                params['avatar_url'] = bounty.local_avatar_url
                params[
                    'is_legacy'] = bounty.is_legacy  # TODO: Remove this following legacy contract sunset.
                if profile_id:
                    profile_ids = list(
                        params['interested_profiles'].values_list('profile_id',
                                                                  flat=True))
                    params['profile_interested'] = request.session.get(
                        'profile_id') in profile_ids
        except Bounty.DoesNotExist:
            pass
        except Exception as e:
            print(e)
            logging.error(e)

    return TemplateResponse(request, 'bounty_details.html', params)
コード例 #5
0
ファイル: views.py プロジェクト: sdnnet3/web
def external_bounties_show(request, issuenum, slug):
    """Handle Dummy External Bounties show page.

    Args:
        issuenum (int): The Github issue number.
        slug (str): The external bounty slug represenation.

    Returns:
        django.TemplateResponse: The external bounty details view.

    """
    print('************')
    print(issuenum)
    if issuenum == '':
        return external_bounties_index(request)

    try:
        bounty = ExternalBounty.objects.get(pk=issuenum, active=True)
    except Exception:
        raise Http404

    external_bounty = {}
    external_bounty_result = bounty
    external_bounty['created_on'] = external_bounty_result.created_on
    external_bounty['title'] = external_bounty_result.title
    external_bounty['crypto_price'] = external_bounty_result.amount
    external_bounty['crypto_label'] = external_bounty_result.amount_denomination
    external_bounty['fiat_price'] = external_bounty_result.amount
    external_bounty['source'] = external_bounty_result.source_project
    external_bounty['content'] = strip_html(external_bounty_result.description)
    external_bounty['action_url'] = external_bounty_result.action_url
    external_bounty['avatar'] = external_bounty_result.avatar
    external_bounty['fiat_price'] = external_bounty_result.fiat_price

    params = {
        'active': 'offchain',
        'title': 'Offchain Bounty Explorer',
        'card_desc': ellipses(external_bounty['content'], 300),
        "bounty": external_bounty,
    }
    return TemplateResponse(request, 'external_bounties_show.html', params)
コード例 #6
0
def bounty_details(request,
                   ghuser='',
                   ghrepo='',
                   ghissue=0,
                   stdbounties_id=None):
    """Display the bounty details.

    Args:
        ghuser (str): The Github user. Defaults to an empty string.
        ghrepo (str): The Github repository. Defaults to an empty string.
        ghissue (int): The Github issue number. Defaults to: 0.

    Raises:
        Exception: The exception is raised for any exceptions in the main query block.

    Returns:
        django.template.response.TemplateResponse: The Bounty details template response.

    """
    is_user_authenticated = request.user.is_authenticated
    if is_user_authenticated and hasattr(request.user, 'profile'):
        _access_token = request.user.profile.get_access_token()
    else:
        _access_token = request.session.get('access_token')
    issue_url = 'https://github.com/' + ghuser + '/' + ghrepo + '/issues/' + ghissue if ghissue else request.GET.get(
        'url')

    # try the /pulls url if it doesnt exist in /issues
    try:
        assert Bounty.objects.current().filter(github_url=issue_url).exists()
    except Exception:
        issue_url = 'https://github.com/' + ghuser + '/' + ghrepo + '/pull/' + ghissue if ghissue else request.GET.get(
            'url')
        print(issue_url)

    params = {
        'issueURL': issue_url,
        'title': _('Issue Details'),
        'card_title': _('Funded Issue Details | Gitcoin'),
        'avatar_url': static('v2/images/helmet.png'),
        'active': 'bounty_details',
        'is_github_token_valid': is_github_token_valid(_access_token),
        'github_auth_url': get_auth_url(request.path),
        "newsletter_headline":
        _("Be the first to know about new funded issues."),
        'is_staff': request.user.is_staff,
    }

    if issue_url:
        try:
            bounties = Bounty.objects.current().filter(github_url=issue_url)
            if stdbounties_id:
                bounties.filter(standard_bounties_id=stdbounties_id)
            if bounties:
                bounty = bounties.order_by('-pk').first()
                if bounties.count() > 1 and bounties.filter(
                        network='mainnet').count() > 1:
                    bounty = bounties.filter(
                        network='mainnet').order_by('-pk').first()
                # Currently its not finding anyting in the database
                if bounty.title and bounty.org_name:
                    params[
                        'card_title'] = f'{bounty.title} | {bounty.org_name} Funded Issue Detail | Gitcoin'
                    params['title'] = params['card_title']
                    params['card_desc'] = ellipses(
                        bounty.issue_description_text, 255)

                params['bounty_pk'] = bounty.pk
                params['network'] = bounty.network
                params['stdbounties_id'] = bounty.standard_bounties_id
                params[
                    'interested_profiles'] = bounty.interested.select_related(
                        'profile').all()
                params['avatar_url'] = bounty.get_avatar_url(True)

                snooze_days = int(request.GET.get('snooze', 0))
                if snooze_days:
                    is_funder = bounty.is_funder(request.user.username.lower())
                    is_staff = request.user.is_staff
                    if is_funder or is_staff:
                        bounty.snooze_warnings_for_days = snooze_days
                        bounty.save()
                        messages.success(
                            request,
                            _(f'Warning messages have been snoozed for {snooze_days} days'
                              ))
                    else:
                        messages.warning(
                            request,
                            _('Only the funder of this bounty may snooze warnings.'
                              ))

        except Bounty.DoesNotExist:
            pass
        except Exception as e:
            print(e)
            logging.error(e)

    return TemplateResponse(request, 'bounty_details.html', params)
コード例 #7
0
def bounty_details(request, ghuser='', ghrepo='', ghissue=0):
    """Display the bounty details.

    Args:
        ghuser (str): The Github user. Defaults to an empty string.
        ghrepo (str): The Github repository. Defaults to an empty string.
        ghissue (int): The Github issue number. Defaults to: 0.

    Raises:
        Exception: The exception is raised for any exceptions in the main query block.

    Returns:
        django.template.response.TemplateResponse: The Bounty details template response.

    """
    is_user_authenticated = request.user.is_authenticated
    if is_user_authenticated and hasattr(request.user, 'profile'):
        _access_token = request.user.profile.get_access_token()
    else:
        _access_token = request.session.get('access_token')
    issue_url = 'https://github.com/' + ghuser + '/' + ghrepo + '/issues/' + ghissue if ghissue else request.GET.get('url')

    # try the /pulls url if it doesnt exist in /issues
    try:
        assert Bounty.objects.current().filter(github_url=issue_url).exists()
    except Exception:
        issue_url = 'https://github.com/' + ghuser + '/' + ghrepo + '/pull/' + ghissue if ghissue else request.GET.get('url')
        print(issue_url)

    params = {
        'issueURL': issue_url,
        'title': _('Issue Details'),
        'card_title': _('Funded Issue Details | Gitcoin'),
        'avatar_url': static('v2/images/helmet.png'),
        'active': 'bounty_details',
        'is_github_token_valid': is_github_token_valid(_access_token),
        'github_auth_url': get_auth_url(request.path),
        "newsletter_headline": _("Be the first to know about new funded issues."),
    }

    if issue_url:
        try:
            bounties = Bounty.objects.current().filter(github_url=issue_url)
            if bounties:
                bounty = bounties.order_by('pk').first()
                # Currently its not finding anyting in the database
                if bounty.title and bounty.org_name:
                    params['card_title'] = f'{bounty.title} | {bounty.org_name} Funded Issue Detail | Gitcoin'
                    params['title'] = params['card_title']
                    params['card_desc'] = ellipses(bounty.issue_description_text, 255)

                params['bounty_pk'] = bounty.pk
                params['interested_profiles'] = bounty.interested.select_related('profile').all()
                params['avatar_url'] = bounty.local_avatar_url
        except Bounty.DoesNotExist:
            pass
        except Exception as e:
            print(e)
            logging.error(e)

    return TemplateResponse(request, 'bounty_details.html', params)