aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dev_status/views.py8
-rw-r--r--ignis/github.py42
-rw-r--r--ignis/migrations/0007_alter_object_location.py19
-rw-r--r--ignis/models.py7
-rw-r--r--ignis/objectstorage.py3
-rw-r--r--ignis/urls.py1
-rw-r--r--ignis/views.py13
-rw-r--r--requirements.txt3
-rw-r--r--static/css/main.css11
-rw-r--r--templates/dev_status/home.html85
10 files changed, 109 insertions, 83 deletions
diff --git a/dev_status/views.py b/dev_status/views.py
index 4914305a..cd0dc1c9 100644
--- a/dev_status/views.py
+++ b/dev_status/views.py
@@ -11,22 +11,18 @@ g = Github(os.getenv('GH_TOKEN'))
def home(request):
page = request.GET.get('page') or 1
items = request.GET.get('items') or 10
- filter = request.GET.get('filter') or 'public'
sort = request.GET.get('sort') or 'updated'
direction = request.GET.get('direction') or 'desc'
search = request.GET.get('search') or ''
- if not request.user.is_authenticated:
- filter = 'public'
context = {}
- repo_rl = g.get_user().get_repos(type=filter, sort=sort, direction=direction)
+ repo_rl = g.get_user('luciferreeves').get_repos(sort=sort, direction=direction)
repos = [repo for repo in repo_rl if (search.lower() in str(repo.name).lower() or search in str(repo.description).lower()) and 'luciferreeves' in str(repo.full_name).lower()] if search != '' else [repo for repo in repo_rl if 'luciferreeves' in str(repo.full_name).lower()]
context['repo_length'] = len(repos)
context['repos'] = repos[(int(page) - 1) * int(items):int(page) * int(items)]
- context['title'] = '{} Repositories'.format(str(filter).capitalize())
+ context['title'] = 'Repositories'
context['page'] = int(page)
context['items'] = int(items)
context['num_pages'] = math.ceil(context['repo_length'] / int(items))
- context['filter'] = filter
context['sort'] = sort
context['direction'] = direction
context['search'] = search
diff --git a/ignis/github.py b/ignis/github.py
new file mode 100644
index 00000000..a4cae4bf
--- /dev/null
+++ b/ignis/github.py
@@ -0,0 +1,42 @@
+import requests
+from dotenv import load_dotenv
+import os
+from selenium import webdriver
+from selenium.webdriver.chrome.options import Options as ChromeOptions
+from selenium.webdriver.firefox.options import Options as FirefoxOptions
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.support import expected_conditions as EC
+from io import BytesIO
+from PIL import Image
+
+load_dotenv()
+
+def get_cover(url):
+ image = requests.get(url).content
+ chrome_options = ChromeOptions()
+ chrome_options.add_argument("--headless")
+ chrome_options.add_argument("--disable-gpu")
+
+ firefox_options = FirefoxOptions()
+ firefox_options.add_argument("--headless")
+
+ driver = webdriver.Chrome(options=chrome_options) if os.getenv("ENVIRONMENT") == 'development' else webdriver.Firefox(options=firefox_options)
+
+ driver.get(url)
+ try:
+ # take screenshot of page - 1280x640
+ WebDriverWait(driver, 10).until(
+ EC.presence_of_element_located((By.TAG_NAME, 'svg'))
+ )
+ driver.set_window_size(1280, 640)
+ image = driver.get_screenshot_as_png()
+ finally:
+ driver.quit()
+
+ # resize image to 640x320
+ image = Image.open(BytesIO(image))
+ image = image.resize((640, 320))
+ output = BytesIO()
+ image.save(output, format='PNG')
+ return output.getvalue()
diff --git a/ignis/migrations/0007_alter_object_location.py b/ignis/migrations/0007_alter_object_location.py
new file mode 100644
index 00000000..c168f637
--- /dev/null
+++ b/ignis/migrations/0007_alter_object_location.py
@@ -0,0 +1,19 @@
+# Generated by Django 4.0.6 on 2022-11-22 12:00
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ignis', '0006_rename_post_slug_objectdirectory_name'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='object',
+ name='location',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ignis.objectdirectory'),
+ ),
+ ]
diff --git a/ignis/models.py b/ignis/models.py
index 9c99de5d..ac6d64d2 100644
--- a/ignis/models.py
+++ b/ignis/models.py
@@ -1,5 +1,4 @@
from django.db import models
-from blog.models import Post
# Create your models here.
class Object(models.Model):
@@ -7,10 +6,8 @@ class Object(models.Model):
metadata = models.CharField(max_length=255)
data = models.TextField()
created = models.DateTimeField(auto_now_add=True)
- location = models.OneToOneField(
- 'ObjectDirectory',
- on_delete=models.CASCADE,
- )
+
+ location = models.ForeignKey('ObjectDirectory', on_delete=models.CASCADE)
def __str__(self):
return self.md5
diff --git a/ignis/objectstorage.py b/ignis/objectstorage.py
index 84d3a5c0..7e437750 100644
--- a/ignis/objectstorage.py
+++ b/ignis/objectstorage.py
@@ -17,7 +17,8 @@ class ObjectStorage:
def create_object(self, md5, metadata, data, name):
if not ObjectDirectory.objects.filter(name=name).exists():
ObjectDirectory.objects.create(name=name)
- Object.objects.create(md5=md5, metadata=metadata, data=data, location=ObjectDirectory.objects.get(name=name))
+ if not Object.objects.filter(md5=md5).exists():
+ Object.objects.create(md5=md5, metadata=metadata, data=data, location=ObjectDirectory.objects.get(name=name))
def delete_object(self, slug, md5):
Object.objects.filter(location=ObjectDirectory.objects.get(name=slug), md5=md5).delete()
diff --git a/ignis/urls.py b/ignis/urls.py
index c35845d0..de4ff05b 100644
--- a/ignis/urls.py
+++ b/ignis/urls.py
@@ -7,5 +7,6 @@ urlpatterns = [
path('/post_image/<int:post_id>/', views.post_image, name='post_image'),
path('/upload', views.upload_image, name='upload_image'),
path('/image/<str:slug>/<str:md5>', views.get_image, name='get_image'),
+ path('/cover/<str:repository>', views.cover_image, name='cover_image'),
path('/su/mvdir', views.mvdir, name='mvdir'),
]
diff --git a/ignis/views.py b/ignis/views.py
index d904217c..1eb85b9a 100644
--- a/ignis/views.py
+++ b/ignis/views.py
@@ -8,6 +8,7 @@ from .objectstorage import ObjectStorage
import base64
import _md5
import json
+from .github import get_cover
# Create your views here.
@csrf_exempt
@@ -47,6 +48,18 @@ def get_image(request, slug, md5):
image = object_storage.get_object(slug, md5)
return HttpResponse(base64.b64decode(image.data), content_type=image.metadata)
+@csrf_exempt
+def cover_image(request, repository):
+ url = 'https://socialify.git.ci/luciferreeves/{}/image?font=KoHo&language=1&name=1&pattern=Floating%20Cogs&theme=Dark'.format(repository)
+ cover_store = ObjectStorage()
+ image_hash = _md5.md5(url.encode()).hexdigest()
+ if not cover_store.object_exists('github_covers', image_hash):
+ image = get_cover(url)
+ data = base64.b64encode(image).decode('utf-8')
+ cover_store.create_object(md5=image_hash, metadata='image/png', data=data, name='github_covers')
+ return HttpResponse(base64.b64decode(cover_store.get_object('github_covers', image_hash).data), content_type='image/png')
+ # cover_store.create_object(md5=image_hash, metadata='image/png', data=data, name='github_covers'))
+
def upload_image(request):
if request.method == 'POST':
if not request.user.is_authenticated and not request.user.is_staff:
diff --git a/requirements.txt b/requirements.txt
index 47cbb152..0581abef 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,4 +7,5 @@ cryptocode==0.1
captcha==0.4
PyGithub==1.55
requests==2.28.1
-pillow==9.2.0 \ No newline at end of file
+pillow==9.2.0
+selenium==4.6.0 \ No newline at end of file
diff --git a/static/css/main.css b/static/css/main.css
index 0ffc4f77..ac7d5fdc 100644
--- a/static/css/main.css
+++ b/static/css/main.css
@@ -11,6 +11,15 @@ body {
text-align: center;
}
+.zoom {
+ width: 320px;
+ height: 160px;
+ margin: 0 auto;
+ background-repeat: no-repeat;
+ background-position: center;
+ background-size: 338px 169px;
+}
+
.header {
background-image: url("../images/site/Banner.gif");
background-repeat: no-repeat;
@@ -87,8 +96,8 @@ fieldset {
.content {
padding: 9px 10px 20px 20px;
- overflow-x: hidden;
overflow-y: auto;
+ overflow-x: visible;
}
.alert {
diff --git a/templates/dev_status/home.html b/templates/dev_status/home.html
index 962d85ad..91a00276 100644
--- a/templates/dev_status/home.html
+++ b/templates/dev_status/home.html
@@ -3,15 +3,9 @@
<div class="area">
{% load static %}
{% load times %}
- {% if not user.is_authenticated %}
- <p style="padding: 15px 10px;" class="alert">
- You are not logged in. You can only view public repositories. Please login or register
- using the sidebar on the left to view both public and private repositories.
- </p>
- {% endif %}
<div style="background-image: url({% static 'images/site/repositories.png' %}); width: 720px; height: 173px; background-repeat: no-repeat; background-position: center;">
{% comment %} Search and Filter {% endcomment %}
- <table style="margin: 0 auto; position: relative; top: 125px;">
+ <table style="margin: 0 auto; position: relative; top: 120px;">
<form action="" method="get">
<tr>
<td>
@@ -29,17 +23,6 @@
</select>
</td>
<td>
- <select name="filter">
- {% if user.is_authenticated %}
- <option value="all" {% if filter == 'all' %}selected{% endif %}>All</option>
- {% endif %}
- <option value="public" {% if filter == 'public' %}selected{% endif %}>Public</option>
- {% if user.is_authenticated %}
- <option value="private" {% if filter == 'private' %}selected{% endif %}>Private</option>
- {% endif %}
- </select>
- </td>
- <td>
<select name="sort">
<option value="full_name" {% if sort == 'full_name' %}selected{% endif %}>Name</option>
<option value="created" {% if sort == 'created' %}selected{% endif %}>Created</option>
@@ -62,58 +45,22 @@
</div>
</div>
<hr>
- <div class='repositories'>
-
- <table style="width: 720px; table-layout: fixed; border-spacing: 12px; border-collapse: separate;">
+ <div class='repositories' style="width: 720px;">
+ <table style="width=720px; margin: 0 auto; table-layout: fixed;">
{% for repo in repos %}
- <tr style="vertical-align: middle;">
- <td width="48px">
- {% if repo.private %}
- <img src="{% static 'images/site/icons/key.gif' %}" alt="Private" title="Private" style="width: 32px; display: block; margin: 0px auto 0 auto; height: auto;">
- {% else %}
- <img src="{% static 'images/site/icons/globe.gif' %}" alt="Public" title="Public" style="width: 32px; display: block; margin: 0px auto 0 auto; height: auto;">
- {% endif %}
- </td>
- <td width="500px">
- <h3 style="margin: 0px auto 8px auto;"><a href="{% url 'dev_status:repo' repo.name %}" style="font-size: 18px;">
- {{ repo.name }}
- </a></h3>
- {% if repo.description %}
- <p style="margin-top: 0px;"><small>{{ repo.description }}</small></p>
- {% else %}
- <p style="color: grey; margin-top: 0px;"><small>No description provided.</small></p>
- {% endif %}
- <table style="display: inline-table; border-spacing: 12px; border-collapse: separate; position: relative; top: -18px; left: -14px;">
- <tr>
- <td width="20px">
- <img src="{% static 'images/site/icons/star.png' %}" alt="Public" title="Stargazers" style="width: 16px; display: block; margin: 0 auto; height: auto;">
- </td>
- <td>
- <p style="text-align: center; margin: 0 auto;" title="Stargazers"><small>{{ repo.stargazers_count }}</small></p>
- </td>
- <td width="20px">
- <img src="{% static 'images/site/icons/fork.png' %}" alt="Public" title="Forks" style="width: 16px; display: block; margin: 0 auto; height: auto;">
- </td>
- <td>
- <p style="text-align: center; margin: 0 auto;" title="Forks"><small>{{ repo.forks_count }}</small></p>
- </td>
- <td width="20px">
- <img src="{% static 'images/site/icons/issue.png' %}" alt="Public" title="Open Issues" style="width: 16px; display: block; margin: 0 auto; height: auto;">
- </td>
- <td>
- <p style="text-align: center; margin: 0 auto;" title="Open Issues"><small>{{ repo.open_issues_count }}</small></p>
- </td>
- </tr>
- </table>
- </td>
- <td width="136px">
- <table>
- <tr><td style="color: #c9d1d9; background-color: #21262d; border-color: #f0f6fc; padding: 5px 10px; border-radius: 4px;"><a style="color: #c9d1d9; text-decoration: none; font-family: sans-serif; font-size: 14px;" href="{{ repo.html_url }}" target="_blank">View on GitHub</a></td></tr>
- </table>
- </td>
- </tr>
- {% endfor %}
- </table>
+ <tr>
+ <td>
+ <a href="{% url 'dev_status:repo' repo.name %}" style="display: inline-block; margin-right: 10px; background-image: url('{% url 'ignis:cover_image' repo.name %}');" class="zoom"></a>
+ </a>
+ </td>
+ <td>
+ <p style="font-size: 20px; font-weight: bold;">{{ repo.name }}</p>
+ <p style="font-size: 15px;">{{ repo.description }}</p>
+
+ </td>
+ </tr>
+ {% endfor %}
+ </table>
</div>
<div class="pagination">
{% if num_pages and page %}