Repository: DjangoGirls/djangogirls

Issue:
move greg link to twitter



Discussion:

Resolving patch:
diff --git a/core/management/commands/prepare_dispatch.py b/core/management/commands/prepare_dispatch.py
new file mode 100644
--- /dev/null
+++ b/core/management/commands/prepare_dispatch.py
@@ -0,0 +1,73 @@
+import calendar
+import datetime
+from itertools import groupby
+from django.core.management import BaseCommand
+from django.utils import timezone
+from django.contrib.humanize.templatetags.humanize import apnumber
+
+from core.models import Event
+import click
+
+
+def generate_html_content(event_list):
+    result = []
+    for event in event_list:
+        city = event.city
+        url = event.eventpage.url
+        html = "<a href='https://djangogirls.org/%s'>%s</a>" % (url, city)
+        result.append(html)
+    return result
+
+
+class Command(BaseCommand):
+    help = 'Generate "Next events" section for the Dispatch.'
+
+    def handle(self, *args, **options):
+
+        now = timezone.now()
+        raw_dispatch_date = click.prompt(click.style("What is the date of the previous Dispatch? (Format: YYYY-MM-DD)", bold=True, fg='yellow'))
+        dispatch_date = datetime.datetime.strptime(raw_dispatch_date, "%Y-%m-%d").replace(tzinfo=datetime.timezone.utc)
+
+        # Get the events that happened since the last Dispatch.
+
+        click.echo(click.style("PREVIOUS EVENTS", bold=True))
+
+        previous_events = Event.objects.filter(date__gt=dispatch_date.strftime("%Y-%m-%d"),
+                                               date__lt=now.strftime("%Y-%m-%d"),
+                                               eventpage__isnull=False)
+        result_previous = generate_html_content(previous_events)
+
+        num_events = len(result_previous)
+
+        if result_previous:
+            click.echo("%s event%s happened since the last dispatch: " % (apnumber(num_events), "s" if num_events > 1 else "")
+                  + ", ".join(result_previous) + ".")
+        else:
+            click.echo("No event took place since the last Dispatch.")
+
+
+        # Get the events that were created since the last Dispatch.
+
+        click.echo(click.style("NEXT EVENTS", bold=True))
+        next_events = Event.objects.all().filter(created_at__range=(dispatch_date, now), eventpage__isnull=False)
+
+        sorted_event = groupby(next_events, key=lambda event: event.date.month)
+
+        if next_events:
+            for month, events in sorted_event:
+                month_list = generate_html_content(events)
+                click.echo(calendar.month_name[month] + ": " + ", ".join(month_list) + "." + "<br />")
+        else:
+            click.echo("There's no new event to announce. Don't forget to check our <a href='https://djangogirls.org/events/'>website</a> to get a list of our events planned for the next few months.")
+
+
+        # Get the events with open registration.
+
+        click.echo("OPEN REGISTRATION")
+        open_events = Event.objects.all().filter(eventpage__form__open_from__lte=now, eventpage__form__open_until__gte=now, eventpage__isnull=False)
+        result_open = generate_html_content(open_events)
+
+        if result_open:
+            click.echo("Registrations are still open for: " + ", ".join(result_open) + ".")
+        else:
+            click.echo("There's no event with open registration.")
\ No newline at end of file
diff --git a/core/migrations/0018_auto_20160521_1930.py b/core/migrations/0018_auto_20160521_1930.py
new file mode 100644
--- /dev/null
+++ b/core/migrations/0018_auto_20160521_1930.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.4 on 2016-05-21 19:30
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0017_auto_20160214_2008'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='coach',
+            options={'ordering': ('name',), 'verbose_name_plural': 'Coaches'},
+        ),
+        migrations.AlterModelOptions(
+            name='event',
+            options={'ordering': ('pk',), 'verbose_name_plural': 'List of events'},
+        ),
+        migrations.AlterModelOptions(
+            name='eventpage',
+            options={'ordering': ('title',), 'verbose_name': 'Website'},
+        ),
+        migrations.AlterModelOptions(
+            name='sponsor',
+            options={'ordering': ('name',)},
+        ),
+        migrations.AddField(
+            model_name='event',
+            name='created_at',
+            field=models.DateTimeField(auto_now_add=True, null=True),
+        ),
+    ]
diff --git a/core/models.py b/core/models.py
--- a/core/models.py
+++ b/core/models.py
@@ -111,6 +111,7 @@ class Event(models.Model):
     team = models.ManyToManyField(User, blank=True)
     is_on_homepage = models.BooleanField(default=False)
     is_deleted = models.BooleanField(default=False)
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
 
     objects = EventManager()
     all_objects = models.Manager()  # This includes deleted objects


Test patch: