Skip to content

Commit

Permalink
Merge branch 'main' into blt-tomato
Browse files Browse the repository at this point in the history
  • Loading branch information
DonnieBLT authored Jul 8, 2024
2 parents 596d07d + ee9f128 commit a259ad3
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 175 deletions.
4 changes: 3 additions & 1 deletion blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
change_bid_status,
chatbot_conversation,
contributors_view,
create_github_issue,
deletions,
dislike_issue2,
dislike_issue3,
Expand Down Expand Up @@ -299,8 +300,9 @@
re_path(r"^like_issue3/(?P<issue_pk>\d+)/$", like_issue3, name="like_issue3"),
re_path(r"^dislike_issue3/(?P<issue_pk>\d+)/$", dislike_issue3, name="dislike_issue3"),
re_path(r"^flag_issue3/(?P<issue_pk>\d+)/$", flag_issue3, name="flag_issue3"),
# TODO(b) track this
re_path(r"^resolve/(?P<id>\w+)/$", resolve, name="resolve"),
# TODO(b) track this
re_path(r"^create_github_issue/(?P<id>\w+)/$", create_github_issue, name="create_github_issue"),
re_path(r"^vote_count/(?P<issue_pk>\d+)/$", vote_count, name="vote_count"),
path("domain/<int:pk>/subscribe/", subscribe_to_domains, name="subscribe_to_domains"),
re_path(r"^save_issue/(?P<issue_pk>\d+)/$", website.views.save_issue, name="save_issue"),
Expand Down
56 changes: 34 additions & 22 deletions company/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.core.exceptions import ValidationError
from django.core.files.storage import default_storage
from django.core.validators import URLValidator
from django.db import transaction
from django.db.models import Count, Q, Sum
from django.db.models.functions import ExtractMonth
from django.http import Http404
Expand Down Expand Up @@ -111,33 +112,44 @@ def post(self, request, *args, **kwargs):
messages.error(request, "Company name doesn't match your email domain.")
return redirect("register_company")

managers = User.objects.values("id").filter(email__in=data.get("email", []))

company = Company.objects.filter(name=data["company_name"]).first()

if company is not None:
messages.error(request, "Company already exist.")
if Company.objects.filter(name=company_name).exists():
messages.error(request, "Company already exists.")
return redirect("register_company")

company_logo = request.FILES.get("logo")
company_logo_file = company_logo.name.split(".")[0]
extension = company_logo.name.split(".")[-1]
company_logo.name = company_logo_file[:99] + str(uuid.uuid4()) + "." + extension
default_storage.save(f"company_logos/{company_logo.name}", company_logo)
company = Company.objects.create(
admin=user,
name=data["company_name"],
url=data["company_url"],
email=data["support_email"],
twitter=data["twitter_url"],
facebook=data["facebook_url"],
logo=f"company_logos/{company_logo.name}",
is_active=True,
)
if company_logo:
company_logo_file = company_logo.name.split(".")[0]
extension = company_logo.name.split(".")[-1]
company_logo.name = f"{company_logo_file[:99]}_{uuid.uuid4()}.{extension}"
logo_path = default_storage.save(f"company_logos/{company_logo.name}", company_logo)
else:
logo_path = None

try:
with transaction.atomic():
company = Company.objects.create(
admin=user,
name=company_name,
url=data["company_url"],
email=data["support_email"],
twitter=data.get("twitter_url", ""),
facebook=data.get("facebook_url", ""),
logo=logo_path,
is_active=True,
)

manager_emails = data.get("email", "").split(",")
managers = User.objects.filter(email__in=manager_emails)
company.managers.set(managers)
company.save()

company.managers.set([manager["id"] for manager in managers])
company.save()
except ValidationError as e:
messages.error(request, f"Error saving company: {e}")
if logo_path:
default_storage.delete(logo_path)
return render(request, "company/register_company.html")

messages.success(request, "Company registered successfully.")
return redirect("company_analytics", id=company.id)


Expand Down
46 changes: 23 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tweepy = "^4.8.0"
Unidecode = "^1.3.8"
user-agents = "^2.2.0"
whitenoise = "^6.7.0"
django-debug-toolbar = "^4.4.3"
django-debug-toolbar = "^4.4.5"
selenium = "^4.22.0"
pylibmc = "^1.6.1"
psycopg2-binary = "^2.9.9"
Expand Down Expand Up @@ -79,7 +79,7 @@ openai = "^1.35.10"
[tool.poetry.group.dev.dependencies]
black = "^24.2.0"
isort = "^5.13.2"
ruff = "^0.5.0"
ruff = "^0.5.1"

[tool.isort]
known_first_party = ["blt"]
Expand Down
43 changes: 20 additions & 23 deletions website/templates/includes/_like_dislike_share.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% comment %} three dot {% endcomment %}
<button id="dropdownDefaultButton"
data-dropdown-toggle="dropdown"
class="like_unlike border-[1px] rounded-2xl shadow-sm mb-3 cursor-pointer relative transform-[0] font-bold text-[#3e3446] bg-white border-black-2 text-[#0.875rem] leading-4 p-4 "
class="md:hidden like_unlike border-[1px] rounded-2xl shadow-sm mb-3 cursor-pointer relative transform-[0] font-bold text-[#3e3446] bg-white border-black-2 text-[#0.875rem] leading-4 p-4 "
type="button">
<svg viewBox="0 0 16 16" fill="currentColor" height="12px" width="12px">
<circle cx="8" cy="8" r="1.31"></circle><circle cx="1.31" cy="8" r="1.31"></circle><circle cx="14.69" cy="8" r="1.31"></circle>
Expand All @@ -15,28 +15,6 @@
<ul class="py-2 m-2 rounded text-gray-700"
aria-labelledby="dropdownDefaultButton">
<span class="md:hidden flex flex-col">{% include "./_like_dislike_widget.html" with device="mobile" %}</span>
<li>
<a href="https://twitter.com/intent/tweet?text=Bug Found on @{{ object.domain_title }} - {{ object.description }} Report: https://{% env 'FQDN' %}/issue/{{ object.id }}"
target="_blank"
rel="noopener noreferrer"
class="w-[100%] block px-4 py-2 hover:bg-gray-100">Tweet &nbsp;<i class="fa-brands fa-x-twitter fa-lg"></i></a>
</li>
<li>
<button onclick="copyClipboard()"
class="flex w-[100%] px-4 py-2 hover:bg-gray-100">
Copy &nbsp;<i class="fa-solid fa-copy text-3xl text-red-[#4A6676]"></i>
</button>
</li>
<li>
<a href="#" class="block px-4 py-2 hover:bg-gray-100">Github &nbsp;<i class="fa-brands fa-github text-3xl text-black"></i></a>
</li>
{% if request.user.is_superuser or request.user == object.user %}
<li>
<a href="{% url 'delete_issue' id=object.id %}"
onclick="return confirm('Are you sure you want to delete this issue?')"
class="block px-4 py-2 hover:bg-gray-100"> Delete &nbsp;<i class="fa-solid fa-trash text-2xl text-black"></i></a>
</li>
{% endif %}
</ul>
</div>
<span class="max-sm:hidden">{% include "./_like_dislike_widget.html" with device="desktop" %}</span>
Expand Down Expand Up @@ -185,6 +163,25 @@
}
</script>
<script>
function createIssue(){
var issue_pk = $("#create_issue").attr('name');
$.ajax({
type: 'GET',
url: '/create_github_issue/' + issue_pk,
data: {},
success: function (data) {
if(data["status"] != "ok"){
$.notify(data["status_reason"], {
style: "custom",
className: "danger"
});
}else{
window.location.reload();
}
},
});
}

function sanitizeURL(url) {
var a = document.createElement('a');
a.href = encodeURI(url);
Expand Down
Loading

0 comments on commit a259ad3

Please sign in to comment.