Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: override org name + photo #4646

Merged
merged 6 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ class BountyAdmin(admin.ModelAdmin):
]

def img(self, instance):
if instance.admin_override_org_logo:
return format_html("<img src={} style='max-width:30px; max-height: 30px'>", mark_safe(instance.admin_override_org_logo.url))
if not instance.avatar_url:
return 'n/a'
img_html = format_html("<img src={} style='max-width:30px; max-height: 30px'>", mark_safe(instance.avatar_url))
return img_html
return format_html("<img src={} style='max-width:30px; max-height: 30px'>", mark_safe(instance.avatar_url))

def what(self, instance):
return str(instance)
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ def create_new_bounty(old_bounties, bounty_payload, bounty_details, bounty_id):
'bounty_owner_email', 'bounty_owner_name', 'github_comments', 'override_status', 'last_comment_date',
'snooze_warnings_for_days', 'admin_override_and_hide', 'admin_override_suspend_auto_approval',
'admin_mark_as_remarket_ready', 'funding_organisation', 'bounty_reserved_for_user', 'is_featured',
'featuring_date', 'fee_tx_id', 'fee_amount', 'repo_type', 'unsigned_nda', 'coupon_code'
'featuring_date', 'fee_tx_id', 'fee_amount', 'repo_type', 'unsigned_nda', 'coupon_code',
'admin_override_org_name', 'admin_override_org_logo'
],
)
if latest_old_bounty_dict['bounty_reserved_for_user']:
Expand Down
34 changes: 34 additions & 0 deletions app/dashboard/migrations/0034_auto_20190617_1549.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 2.1.7 on 2019-06-17 15:49

import app.utils
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0033_bounty_bounty_categories'),
]

operations = [
migrations.AddField(
model_name='bounty',
name='admin_override_org_logo',
field=models.ImageField(blank=True, help_text='Organization Logo - Override', null=True, upload_to=app.utils.get_upload_filename),
),
migrations.AddField(
model_name='bounty',
name='admin_override_org_name',
field=models.CharField(blank=True, max_length=255),
),
migrations.AddField(
model_name='profile',
name='admin_override_avatar',
field=models.ImageField(blank=True, help_text='override profile avatar', null=True, upload_to=app.utils.get_upload_filename),
),
migrations.AddField(
model_name='profile',
name='admin_override_name',
field=models.CharField(blank=True, help_text='override profile name.', max_length=255),
),
]
14 changes: 14 additions & 0 deletions app/dashboard/migrations/0038_merge_20190624_1716.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.1.7 on 2019-06-24 17:16

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0034_auto_20190617_1549'),
('dashboard', '0037_merge_20190624_1656'),
]

operations = [
]
48 changes: 42 additions & 6 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ class Bounty(SuperModel):
admin_mark_as_remarket_ready = models.BooleanField(
default=False, help_text=_('Admin override to mark as remarketing ready')
)
admin_override_org_name = models.CharField(max_length=255, blank=True) # TODO: Remove POST ORGS
danlipert marked this conversation as resolved.
Show resolved Hide resolved
admin_override_org_logo = models.ImageField(
upload_to=get_upload_filename,
null=True,
blank=True,
help_text=_('Organization Logo - Override'),
) # TODO: Remove POST ORGS
attached_job_description = models.URLField(blank=True, null=True)
event = models.ForeignKey('dashboard.HackathonEvent', related_name='bounties', null=True, on_delete=models.SET_NULL, blank=True)

Expand Down Expand Up @@ -487,6 +494,12 @@ def github_issue_number(self):
def org_name(self):
return self.github_org_name

@property
def org_display_name(self): # TODO: Remove POST ORGS
if self.admin_override_org_name:
return self.admin_override_org_name
return org_name(self.github_url)

@property
def github_org_name(self):
try:
Expand Down Expand Up @@ -563,6 +576,10 @@ def avatar_url_w_gitcoin_logo(self):

def get_avatar_url(self, gitcoin_logo_flag=False):
"""Return the local avatar URL."""

if self.admin_override_org_logo:
return self.admin_override_org_logo.url

org_name = self.github_org_name
gitcoin_logo_flag = "/1" if gitcoin_logo_flag else ""
if org_name:
Expand Down Expand Up @@ -1941,6 +1958,13 @@ class Profile(SuperModel):
resume = models.FileField(upload_to=get_upload_filename, null=True, blank=True, help_text=_('The profile resume.'))
actions_count = models.IntegerField(default=3)
fee_percentage = models.IntegerField(default=10)
admin_override_name = models.CharField(max_length=255, blank=True, help_text=_('override profile name.'))
admin_override_avatar = models.ImageField(
upload_to=get_upload_filename,
null=True,
blank=True,
help_text=_('override profile avatar'),
)
persona_is_funder = models.BooleanField(default=False)
persona_is_hunter = models.BooleanField(default=False)

Expand Down Expand Up @@ -2400,6 +2424,8 @@ def github_url(self):

@property
def avatar_url(self):
if self.admin_override_avatar:
return self.admin_override_avatar.url
if self.active_avatar:
return self.active_avatar.avatar_url
return f"{settings.BASE_URL}dynamic/avatar/{self.handle}"
Expand All @@ -2414,13 +2440,23 @@ def absolute_url(self):

@property
def username(self):
handle = ''
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved
if getattr(self, 'user', None) and self.user.username:
handle = self.user.username
# TODO: (mbeacom) Remove this check once we get rid of all the lingering identity shenanigans.
elif self.handle:
handle = self.handle
return handle
return self.user.username

if self.handle:
return self.handle

return None

@property
def name(self):
if self.admin_override_name:
return self.admin_override_name

if self.data and self.data["name"]:
return self.data["name"]

return username(self)


def is_github_token_valid(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@


{% for org in orgs %}
<div class="form__radio option {{org}}">
<input name="org" id="{{org}}" type="radio" value="{{org}}" val-ui="Turing-Chain">
danlipert marked this conversation as resolved.
Show resolved Hide resolved
<label class="filter-label" for="{{org}}">
<img src="/dynamic/avatar/{{org}}" class="rounded-circle" width="24" height="24"> {{org}}
<div class="form__radio option {{org.org_name}}">
<input name="org" id="{{org.org_name}}" type="radio" value="{{org.org_name}}" val-ui="Turing-Chain">
<label class="filter-label" for="{{org.org_name}}">
<img src="{{org.avatar_url}}" class="rounded-circle" width="24" height="24"> {{org.display_name}}
</label>
</div>
{% endfor %}
Expand Down
6 changes: 1 addition & 5 deletions app/dashboard/templates/profiles/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@
</div>

<h1 class="profile-header__handle">
{% if profile.data.name %}
{{ profile.data.name }}
{% else %}
{{ profile.handle }}
{% endif %}
{{ profile.name }}
{% if verification.verified %}
<button class="btn btn-sm animate-verify" data-container="body" data-toggle="popover" data-html="true" data-placement="bottom" data-trigger="hover click" data-content='
<p class="h6 my-2 text-left">Gitcoin Verified <img width="18" src="{% static "v2/images/badge-verify.svg" %}"></p>
Expand Down
13 changes: 12 additions & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2766,7 +2766,18 @@ def hackathon(request, hackathon=''):

title = evt.name
network = get_default_network()
orgs = set([bounty.org_name for bounty in Bounty.objects.filter(event=evt, network=network).current()])

# TODO: Refactor post orgs
orgs = []
for bounty in Bounty.objects.filter(event=evt, network=network).current():
org = {
'display_name': bounty.org_display_name,
'avatar_url': bounty.avatar_url,
'org_name': bounty.org_name
}
orgs.append(org)

orgs = list({v['org_name']:v for v in orgs}.values())

params = {
'active': 'dashboard',
Expand Down