Skip to content

Commit 00b61a0

Browse files
authored
Fixed tag search. Support min/max start/end dates by themselves. Added more metrics (#107)
1 parent d87289a commit 00b61a0

File tree

13 files changed

+266
-64
lines changed

13 files changed

+266
-64
lines changed

dbdb/core/management/commands/create_twitter_cards.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Command(BaseCommand):
1919
def add_arguments(self, parser):
2020
parser.add_argument('system', metavar='S', type=str, nargs='?',
2121
help='System to force twiter card creation')
22+
parser.add_argument('--skip-errors', action='store_true',
23+
help="Ignore errors and keep processing")
2224
return
2325

2426
def handle(self, *args, **options):
@@ -50,7 +52,11 @@ def handle(self, *args, **options):
5052
continue
5153
elif os.path.exists(card_img):
5254
continue
53-
ver.create_twitter_card()
55+
try:
56+
ver.create_twitter_card()
57+
except:
58+
self.stdout.write("FAIL: %s -> %s" % (ver.system.name, card_img))
59+
if not options['skip_errors']: raise
5460
self.stdout.write("%s -> %s" % (ver.system.name, card_img))
5561
# FOR
5662
return

dbdb/core/management/commands/process_visits.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ def handle(self, *args, **options):
6767
return
6868
# IF
6969

70+
# Get the total # of visits per system so that we can update
71+
# the System objects for our stats calculation
72+
visits_per_system = { }
73+
with connection.cursor() as cursor:
74+
sql = "SELECT system_id, count(*) AS cnt FROM core_systemvisit GROUP BY system_id"
75+
cursor.execute(sql)
76+
visits_per_system = dict([ (row[0],int(row[1])) for row in cursor.fetchall() ])
77+
# WITH
78+
for system_id, visits in visits_per_system.items():
79+
system = System.objects.get(id=system_id)
80+
system.view_count = visits
81+
system.save()
82+
#print(system, "=>", visits_per_system[system_id])
83+
#sys.exit(0)
84+
7085
# Get the list of all unique IPs
7186
ip_addresses = [ ]
7287
with connection.cursor() as cursor:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.1.14 on 2022-07-04 19:26
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('core', '0026_auto_20220626_1511'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='feature',
15+
name='description',
16+
field=models.TextField(blank=True, help_text='This field supports Markdown Syntax'),
17+
),
18+
]

dbdb/core/models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Feature(models.Model):
3636
slug = models.SlugField(db_index=True, unique=True)
3737
label = models.CharField(max_length=100, unique=True)
3838
multivalued = models.BooleanField(default=True)
39+
description = models.TextField(blank=True, help_text='This field supports Markdown Syntax')
3940

4041
class Meta:
4142
ordering = ('label',)
@@ -490,14 +491,15 @@ def get_twitter_card_image(self):
490491

491492
def create_twitter_card(self):
492493
from PIL import Image, ImageDraw, ImageFont
494+
from cairosvg import svg2png
495+
import tempfile
493496

494497
# Create a nicely formatted version of the logo for the twitter card
495498
template = os.path.join(settings.BASE_DIR, "static", settings.TWITTER_CARD_TEMPLATE)
496499
im1 = Image.open(template).convert("RGBA")
497500
new_im = Image.new('RGBA', (im1.width, im1.height))
498501
new_im.paste(im1, (0, 0))
499502

500-
501503
# If there is no logo, then we will create an image of just the name
502504
if not self.logo:
503505
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 128)
@@ -516,6 +518,14 @@ def create_twitter_card(self):
516518
text_draw = ImageDraw.Draw(logo)
517519
text_draw.text((0, 0), name, font=font, fill=(70,70,70,255))
518520

521+
# SVG
522+
elif self.logo.path.lower().endswith("svg"):
523+
temp_name = os.path.join(tempfile.gettempdir(), next(tempfile._get_candidate_names()) + ".png")
524+
with open(self.logo.path) as fd:
525+
svg2png(bytestring=fd.read(),write_to=temp_name, scale=3)
526+
logo = Image.open(temp_name).convert("RGBA")
527+
528+
# PNG
519529
else:
520530
logo = Image.open(self.logo).convert("RGBA")
521531

0 commit comments

Comments
 (0)