Beispiel #1
0
    def get(self, request, *args, **kwargs):
        people = self.get_queryset()

        q = self.request.GET.get('q', None)
        if 'q' in self.request.GET:
            people = people.filter(Q(first_name__icontains = q) | Q(last_name__icontains = q))
            
        people = people.values('first_name', 'last_name', 'email', 'twitter_username', 'github_username', 'id')
        for person in list(people):
            person['name'] = '%s %s' % (person['first_name'], person['last_name'])

        return render_json_to_response(list(people))
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        data = request.POST
        form_message = ''
        success_url = self.get_success_url()
        
        if 'organization_task' in data:
            success_url = reverse('organization_update')
            self.template_name = "people/organization_update.html"
            task = data['organization_task']
            organization = self.get_organization()
            
            if task == 'create':
                person = self.create_person(data, organization)
                form_message = 'Created'
                success_url += '?new=%s' % person.pk
            else:
                person = self.get_person(data['person'], organization, task)
                if task == 'update':
                    form_message = self.process_form(person, data)
                elif task == 'remove':
                    person.organizations.remove(organization)
                    form_message = 'Removed'
                elif task == 'add':
                    person.organizations.add(organization)
                    form_message = 'Added'
        else:
            person = self.get_person()
            form_message = self.process_form(person, data)
        
        if request.is_ajax():
            result = {
                'message': form_message,
                'person': {
                    'name': person.name(),
                    'pk': person.pk,
                    'first_name': person.first_name,
                    'last_name': person.last_name,
                    'email': person.email,
                    'twitter_username': person.twitter_username,
                    'github_username': person.github_username
                }
            }
            return render_json_to_response(result)

        # if for some reason we're not hitting via ajax
        messages.success(request, form_message)
        return redirect(success_url)
Beispiel #3
0
 def render_to_response(self, context):
     if self.render_json:
         jobs = []
         for job in context['object_list']:
             jobs.append({
                 'name': job.name,
                 'organization': job.organization.name,
                 'description': job.description,
                 'location': job.location,
                 'contact_name': job.contact_name,
                 'email': job.email,
                 'listed': dj_date(job.listing_start_date, 'F j, Y'),
                 'url': job.url,
                 'source_url': job.get_list_page_url,
             })
         return render_json_to_response(jobs)
     return super(JobList, self).render_to_response(context)
Beispiel #4
0
    def post(self, request, *args, **kwargs):
        data = request.POST
        form_message = ''
        
        task = data['organization_task']
        organization = self.get_organization()

        if task == 'create':
            job = self.create_job(data, organization)
            form_message = 'Created'
        else:
            job = self.get_job(data['job'], organization, task)
            if task == 'update':
                form_message = self.process_form(job, data)
            elif task == 'remove':
                job.delete()
                expire_page_cache(reverse('job_list'))
                expire_page_cache(organization.get_absolute_url())
                form_message = 'Removed'

        if request.is_ajax():
            result = {
                'message': form_message,
                'job': {
                    'name': job.name,
                    'pk': job.pk,
                    'contact_name': job.contact_name,
                    'email': job.email,
                    'description': job.description,
                    'location': job.location,
                    'url': job.url,
                    'listing_end_date': job.listing_end_date
                }
            }
            return render_json_to_response(result)

        # if for some reason we're not hitting via ajax
        messages.success(request, form_message)
        return redirect(self.get_success_url())
Beispiel #5
0
    def post(self, request, *args, **kwargs):
        context = {}
        user = request.user
        organization = self.get_organization(user)

        if organization:
            organization_form = OrganizationUpdateForm(instance=organization, data=request.POST)
            context.update({
                'user': request.user,
                'organization': organization,
                'organization_form': organization_form,
            })

            if organization_form.is_valid():
                organization_form.save()
                
        if request.is_ajax():
            result = {'success': 'True'}
            return render_json_to_response(result)

        # if for some reason we're not hitting via ajax
        messages.success(request, 'Updates saved')
        return render_to_response(self.template_name, context, context_instance=RequestContext(request))
Beispiel #6
0
    def get(self, request, *args, **kwargs):
        '''
        Returns the following counts for Mozilla contributors dashboard:
        
        * Distinct authors who published articles in the previous year
        * New authors who published articles in the previous week, where "new"
          means they have not published in the previous year
        * Distinct people associated with articles published in the previous year
        * New people associated with articles published in the previous week,
          where "new" means they have not been mentioned in the previous year
        
        These counts reflect the way Source articles can be associated
        with individuals:
        
        * Authors: The person or people who wrote the article
        * People: A person or people whose work is being covered by the article.
          These people may or may not also be listed as article Authors.
        
        A date may be passed as a querystring parameter to provide a starting
        point for calculations. If no date is passed, `today` will be assumed.
        
        * /api/1.0/contributor-count/
        * /api/1.0/contributor-count/?date=2014-04-12
        
        Date ranges will be calculated from midnight of the starting date, so
        records won't be missed based on the time of day when the query is run.
        '''
        
        # set up the date parameters
        requested_date = request.GET.get('date', None)
        if requested_date:
            start_date = parser.parse(requested_date)
        else:
            today = datetime.today()
            midnight = datetime.min.time()
            start_date = datetime.combine(today, midnight)
            
        previous_year = start_date - timedelta(days=365)
        previous_7_days = start_date - timedelta(days=7)
        
        # set up the necessary article querysets
        articles_year = Article.live_objects.filter(pubdate__lt=start_date, pubdate__gte=previous_year)
        articles_7_days = Article.live_objects.filter(pubdate__lt=start_date, pubdate__gte=previous_7_days)
        articles_year_exclude_7_days = Article.live_objects.filter(pubdate__lt=previous_7_days, pubdate__gte=previous_year)

        # get down to counting some authors
        # first, take all the articles published in the previous year, fetch
        # the pk values for their `authors` m2m relationship
        authors_previous_year = articles_year.values_list('authors', flat=True)
        # filter out `none` values, use set() to remove dupes, count members
        authors_previous_year_count = len(set(filter(None, authors_previous_year)))
        
        # repeat process for articles published in the previous week, but only
        # to the point where we're creating the set of unique author values
        authors_previous_7_days = articles_7_days.values_list('authors', flat=True)
        authors_previous_7_days_set = set(filter(None, authors_previous_7_days))
        
        # do the same for articles published during previous year but NOT
        # during the previous week
        authors_previous_year_exclude_7_days = articles_year_exclude_7_days.values_list('authors', flat=True)
        authors_previous_year_exclude_7_days_set = set(filter(None, authors_previous_year_exclude_7_days))
        
        # then use set difference to find author values from previous 7 days
        # that do NOT appear elsewhere in the previous year
        authors_new_previous_7_days_count = len(
            authors_previous_7_days_set.difference(authors_previous_year_exclude_7_days_set)
        )

        # now repeat all of that for people associated with published articles
        people_previous_year = articles_year.values_list('people', flat=True)
        people_previous_year_count = len(set(filter(None, people_previous_year)))

        people_previous_7_days = articles_7_days.values_list('people', flat=True)
        people_previous_7_days_set = set(filter(None, people_previous_7_days))
        
        people_previous_year_exclude_7_days = articles_year_exclude_7_days.values_list('people', flat=True)
        people_previous_year_exclude_7_days_set = set(filter(None, people_previous_year_exclude_7_days))
        
        people_new_previous_7_days_count = len(
            people_previous_7_days_set.difference(people_previous_year_exclude_7_days_set)
        )
        
        result = {
            'start_date': datetime.strftime(start_date, '%Y-%m-%d'),
            'previous_year': datetime.strftime(previous_year, '%Y-%m-%d'),
            'previous_7_days': datetime.strftime(previous_7_days, '%Y-%m-%d'),
            'authors_previous_year': authors_previous_year_count,
            'authors_new_previous_7_days': authors_new_previous_7_days_count,
            'people_previous_year': people_previous_year_count,
            'people_new_previous_7_days': people_new_previous_7_days_count
        }
        
        return render_json_to_response(result)