Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged

Flag #923

Show file tree
Hide file tree
Changes from all 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
60 changes: 41 additions & 19 deletions Setup.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Setting up Development server

## Setting Up Development Server using Docker-compose

### Install [Docker](https://docs.docker.com/get-docker/)

```sh
# Move to project directory
cd BLT

# build the docker container
docker-compose build

# Run the docker container
docker-compose up

# for staticfiles collection (Optional)
docker exec -it <container id> /bin/bash

# collect staticfiles
python manage.py collectstatic

```

## Setting Up Development Server using Vagrant

### Install [Vagrant](https://www.vagrantup.com/)
Expand All @@ -11,26 +33,26 @@
```sh
# Move to project directory
cd BLT

# Start vagrant - It takes time during the first run, so go get a coffee!
vagrant up
# SSH into vagrant

# SSH into vagrant
vagrant ssh

# Move to project directory
cd BLT

# Create tables in the database
python manage.py migrate

# Create a super user
python manage.py createsuperuser

# Collect static files
python manage.py collectstatic

# Run the server
# Run the server
python manage.py runserver
```

Expand All @@ -50,35 +72,35 @@ from the host machine.

# Install postgres on mac using brew
brew install postgresql
# Install postgres on ubuntu

# Install postgres on ubuntu
sudo apt-get install postgresql

# Install pipenv on ubuntu
sudo apt-get install pipenv

# Install pipenv on mac
pip install pipenv

# Start virtual env
pipenv install | pipenv shell

# Move to project directory
cd BLT

# Create tables in the database
python manage.py migrate

# Load initial data
python3 manage.py loaddata website/fixtures/initial_data.json

# Create a super user
python manage.py createsuperuser

# Collect static files
python manage.py collectstatic

# Run the server
# Run the server
python manage.py runserver
```

Expand Down
3 changes: 3 additions & 0 deletions bugheist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@
re_path(
r"^like_issue/(?P<issue_pk>\d+)/$", website.views.like_issue, name="like_issue"
),
re_path(
r"^flag_issue/(?P<issue_pk>\d+)/$", website.views.flag_issue, name="flag_issue"
),
re_path(
r"^save_issue/(?P<issue_pk>\d+)/$", website.views.save_issue, name="save_issue"
),
Expand Down
20 changes: 20 additions & 0 deletions website/migrations/0069_userprofile_issue_flaged.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1 on 2022-08-20 15:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("website", "0068_winner_hunt"),
]

operations = [
migrations.AddField(
model_name="userprofile",
name="issue_flaged",
field=models.ManyToManyField(
blank=True, related_name="flaged", to="website.issue"
),
),
]
1 change: 1 addition & 0 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ class UserProfile(models.Model):
)
issue_upvoted = models.ManyToManyField(Issue, blank=True, related_name="upvoted")
issue_saved = models.ManyToManyField(Issue, blank=True, related_name="saved")
issue_flaged = models.ManyToManyField(Issue,blank=True,related_name="flaged")

def avatar(self, size=36):
if self.user_avatar:
Expand Down
25 changes: 25 additions & 0 deletions website/templates/_flags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% load gravatar %}
<a class="btn btn-info btn-xs flag_unflag" name="{{ object.pk }}">
<i class="fa fa-thumbs-down"></i> Flag {{ flags }}
</a>


<div id="flagedBy" class="modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h3>Flaged by:</h3>
{% for usr in flagers %}
<div class="list-group-item">
{% if usr.user.socialaccount_set.all.0.get_avatar_url %}
<img src="{{ usr.user.socialaccount_set.all.0.get_avatar_url }}" height="50px">
{% else %}
<img src="{% gravatar_url usr.user.email 50 %}">
{% endif %}
<a href="/profile/{{ usr.user.username }}">{{ usr.user.username }}</a>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
25 changes: 20 additions & 5 deletions website/templates/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@
}

.like_btn,
.flag_btn,
.bookmark,
.copy-btn,
.flag_btn a.flaged-by,
.like_btn a.liked-by {
vertical-align: top;
}
Expand Down Expand Up @@ -152,6 +154,9 @@ <h3 class="page-header">
<span class="like_btn">
{% include '_likes.html' %}
</span>
<span class="flag_btn">
{% include '_flags.html' %}
</span>
<a class="bookmark btn btn-success btn-xs" name="{{ object.pk }}">
<i class="fa fa-bookmark-o"></i> Bookmark
</a>
Expand Down Expand Up @@ -354,11 +359,8 @@ <h3>Comments:</h3>
</div>

<script type="text/javascript">
var label = {
{
object.label
}
};
var label = "{{object.label}}";

$(document).on('click', '.edit-issue', function (e) {
$('.form input[name=description]').val($('.issue-desc').text());
$('.form input[name=domain]').val($('.issue-domain').text());
Expand Down Expand Up @@ -487,6 +489,19 @@ <h3>Comments:</h3>
});
});

$('body').on('click', '.flag_unflag', function (e) {
e.preventDefault();
var issue_pk = $(this).attr('name');
$.ajax({
type: 'GET',
url: '/flag_issue/' + issue_pk + '/',
data: {},
success: function (data) {
$('.flag_btn').html(data);
},
});
});

$('body').on('click', '.bookmark', function (e) {
e.preventDefault();
var issue_pk = $(this).attr('name');
Expand Down
21 changes: 21 additions & 0 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,9 +1425,30 @@ def get_context_data(self, **kwargs):
context["all_users"] = User.objects.all()
context["likes"] = UserProfile.objects.filter(issue_upvoted=self.object).count()
context["likers"] = UserProfile.objects.filter(issue_upvoted=self.object)

context["flags"] = UserProfile.objects.filter(issue_flaged=self.object).count()
context["flagers"] = UserProfile.objects.filter(issue_flaged=self.object)
return context


@login_required(login_url="/accounts/login")
def flag_issue(request, issue_pk):
context = {}
issue_pk = int(issue_pk)
issue = Issue.objects.get(pk=issue_pk)
userprof = UserProfile.objects.get(user=request.user)
if userprof in UserProfile.objects.filter(issue_flaged=issue):
userprof.issue_flaged.remove(issue)
else:
userprof.issue_flaged.add(issue)
issue_pk = issue.pk

userprof.save()
total_flag_votes = UserProfile.objects.filter(issue_flaged=issue).count()
context["object"] = issue
context["flags"] = total_flag_votes
return render(request, "_flags.html", context)

def IssueEdit(request):
if request.method == "POST":
issue = Issue.objects.get(pk=request.POST.get("issue_pk"))
Expand Down