add support for formdata as events
This commit is contained in:
parent
04db07f2ca
commit
48f4e7aa0a
|
@ -4,7 +4,7 @@ from django.core.management.base import BaseCommand, CommandError
|
|||
from django.db.models import Q
|
||||
from django.utils.dateparse import parse_date
|
||||
|
||||
from eodb.events.models import Commit, Email, Redmine
|
||||
from eodb.events.models import Commit, Email, Redmine, Formdata
|
||||
|
||||
class GraphCommand(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
|
@ -38,8 +38,11 @@ class GraphCommand(BaseCommand):
|
|||
yield (None, self.get_events(options))
|
||||
|
||||
def get_events(self, options):
|
||||
domain_filter = Q(author_email__endswith='@entrouvert.com') | \
|
||||
Q(author_email__endswith='@entrouvert.org')
|
||||
if options['events'] in ('formdata',):
|
||||
domain_filter = Q(author_datetime__isnull=False)
|
||||
else:
|
||||
domain_filter = Q(author_email__endswith='@entrouvert.com') | \
|
||||
Q(author_email__endswith='@entrouvert.org')
|
||||
filters = {}
|
||||
|
||||
if options.get('username'):
|
||||
|
@ -56,7 +59,8 @@ class GraphCommand(BaseCommand):
|
|||
if options.get('datemax'):
|
||||
filters[datetime_var + '__lt'] = parse_date(options['datemax'])
|
||||
|
||||
return {'emails': Email, 'redmine': Redmine, 'git': Commit}[
|
||||
return {'emails': Email, 'redmine': Redmine, 'git': Commit,
|
||||
'formdata': Formdata}[
|
||||
options['events']].objects.filter(domain_filter).filter(**filters)
|
||||
|
||||
def get_title(self, options):
|
||||
|
@ -64,6 +68,7 @@ class GraphCommand(BaseCommand):
|
|||
'emails': 'Email activity',
|
||||
'git': 'Git activity',
|
||||
'redmine': 'Redmine activity',
|
||||
'formdata': 'Formdata activity',
|
||||
}[options['events']]
|
||||
if options.get('username'):
|
||||
title += ' for %s' % options['username']
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import csv
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils.dateparse import parse_datetime
|
||||
|
||||
from eodb.events.models import Formdata
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('filename', metavar='FILENAME')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for row in csv.reader(open(options['filename'])):
|
||||
if not parse_datetime(row[1]):
|
||||
continue
|
||||
event, created = Formdata.objects.get_or_create(
|
||||
author_datetime=parse_datetime(row[1]))
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.6 on 2017-10-21 08:23
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('events', '0003_redmine'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Formdata',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('author_datetime', models.DateTimeField()),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -22,3 +22,8 @@ class Redmine(models.Model):
|
|||
module = models.CharField(max_length=200)
|
||||
author_email = models.CharField(max_length=100)
|
||||
author_datetime = models.DateTimeField()
|
||||
|
||||
|
||||
class Formdata(models.Model):
|
||||
# add formdata_id (site:formdata_id)
|
||||
author_datetime = models.DateTimeField()
|
||||
|
|
Reference in New Issue