예제 #1
0
def ProjectActivity(project, of_type, user, action=None, comments=None):
    activity = Activity(name=of_type, project_id=project.id, action=action)
    activity.user_id = user.id
    # Regular posts are 1 star
    score = 1
    # Booster stars to give projects special awards
    if of_type == 'boost':
        score = 10
    # Post comments are activity contents
    if comments is not None and len(comments) > 3:
        activity.content = comments
    if project.score is None:
        project.score = 0
    # Check for existing stars
    allstars = Activity.query.filter_by(name='star',
                                        project_id=project.id,
                                        user_id=user.id)
    if of_type == 'star':
        if allstars.count() > 0:
            return  # One star per user
    elif of_type == 'unstar':
        if allstars.count() > 0:
            allstars[0].delete()
        project.score = project.score - score
        project.save()
        return
    # Save current project score
    project.score = project.score + score
    activity.project_score = project.score
    project.save()
    db.session.add(activity)
    db.session.commit()
예제 #2
0
def ProjectActivity(project, of_type, current_user):
    activity = Activity(name=of_type,
                        project_id=project.id,
                        user_id=current_user.id)
    score = 0
    if project.score is None: project.score = 0
    allstars = Activity.query.filter_by(name='star',
                                        project_id=project.id,
                                        user_id=current_user.id)
    if of_type == 'star':
        score = 2
        if allstars.count() > 0:
            return  # One star per user
    elif of_type == 'unstar':
        score = 2
        if allstars.count() > 0:
            allstars[0].delete()
        #if current_user.is_admin:
        #    score = 10
        project.score = project.score - score
        project.save()
        return
    # Admin stars give projects special awards
    #if of_type == 'star' and current_user.is_admin:
    #    score = 10
    project.score = project.score + score
    project.save()
    db.session.add(activity)
    db.session.commit()
예제 #3
0
    def test_datapackage(self, project, testapp):
        """Create a data package."""

        event = Event(name="Test Event", summary="Just testin")
        event.save()

        role = Role(name="Test Role")
        role.save()

        user = UserFactory(username="******")
        user.roles.append(role)
        user.save()

        proj1 = Project(name="Test Project")
        proj1.event = event
        proj1.user = user
        proj1.save()

        acty1 = Activity("review", proj1.id)
        acty1.content = "Hello World!"
        acty1.save()

        dp_json = PackageEvent(event, user)
        assert dp_json.title == "Test Event"

        acty1.delete()
        proj1.delete()
        event.delete()

        assert Event.query.filter_by(name="Test Event").count() == 0

        ImportEventPackage(dp_json)
        assert Event.query.filter_by(name="Test Event").count() == 1
예제 #4
0
def ProjectActivity(project,
                    of_type,
                    current_user,
                    action=None,
                    comments=None,
                    resource=None):
    activity = Activity(name=of_type,
                        project_id=project.id,
                        user_id=current_user.id,
                        action=action)
    score = 1
    if comments is not None and len(comments) > 3:
        activity.content = comments
    if resource is not None:
        score = 2  # Double score for adding resources
        activity.resource_id = resource
    if project.score is None: project.score = 0
    allstars = Activity.query.filter_by(name='star',
                                        project_id=project.id,
                                        user_id=current_user.id)
    if of_type == 'star':
        if allstars.count() > 0:
            return  # One star per user
    elif of_type == 'unstar':
        if allstars.count() > 0:
            allstars[0].delete()
        project.score = project.score - score
        project.save()
        return
    # Booster stars to give projects special awards
    #if of_type == 'star' and current_user.is_admin:
    #    score = 10
    project.score = project.score + score
    activity.project_score = project.score
    project.save()
    db.session.add(activity)
    db.session.commit()
예제 #5
0
def SyncCommitData(project, commits):
    if project.event is None or len(commits) == 0:
        return
    prevactivities = Activity.query.filter_by(name='update',
                                              action='commit',
                                              project_id=project.id).all()
    prevdates = [a.timestamp.replace(microsecond=0) for a in prevactivities]
    prevlinks = [a.ref_url for a in prevactivities]
    username = None
    user = None
    since = project.event.starts_at_tz
    until = project.event.ends_at_tz
    for commit in commits:
        # Check duplicates
        if 'url' in commit and commit['url'] is not None:
            if commit['url'] in prevlinks:
                continue
        if commit['date'].replace(microsecond=0) in prevdates:
            continue
        if commit['date'] < since or commit['date'] > until:
            continue
        # Get message and author
        message = commit['message']
        if username != commit['author']:
            username = commit['author']
            user = User.query.filter_by(username=username).first()
            if user is None:
                message += ' (@%s)' % username or "git"
        # Create object
        activity = Activity(name='update',
                            action='commit',
                            project_id=project.id,
                            timestamp=commit['date'],
                            content=message)
        if 'url' in commit and commit['url'] is not None:
            activity.ref_url = commit['url']
        if user is not None:
            activity.user_id = user.id
        activity.save()
    db.session.commit()