Esempio n. 1
0
from django.http import HttpResponseRedirect
from django.contrib.contenttypes.models import ContentType

from customtags.decorators import block
from pirate_core import FormMixin, ComboFormFactory, namespace_get
from django import template

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('pp_core')

@block
def pp_combo_form(context, nodelist, *args, **kwargs):
    """

    This tag is used to merge two separate forms into one form.  It does this
    by performing three actions:

    (1) It merges the fields of two separate forms into a single form with
        unified error messaging, and uniqueness among field names.
    (2) When provided a POST argument that matches its internally-determined
        form id, it will process that form in order to produce any error messages
    (3) When provided with a POST argument, it will assume that all forms
        passed in as arguments will also have been instantiated with that same POST.
        The validity of the MultiForm it produces will be tested; the MultiForm
        iteself will loop over the individual sub-forms testing to see if each is 
        valid as well.  Any errors discovered will be added to its own errors.
Esempio n. 2
0
from pirate_forum.templatetags.blobtags import get_form

from pirate_core.helpers import clean_html

from pirate_social.models import RelationshipEvent
from pirate_signals.models import relationship_event
from pirate_social.models import register_relationship_event
from pirate_core import HttpRedirectException, namespace_get, FormMixin

from django.template.defaultfilters import stringfilter
import uuid
from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_tag')

"""This is more of a group of helper generic templatetags

    TODO: Change the namespace and all hooks to reflect that"""

from django.template.defaultfilters import floatformat


@register.filter
def objectClass(value):
    """
    **Filter**

    Takes a float value and returns it as a percentage. Only makes sense for float values in the range [0,1].
Esempio n. 3
0
from pirate_topics.forms import TopicForm

from pirate_profile.models import Profile

from django.utils.html import urlize

from pirate_signals.models import aso_rep_event, update_agent

from pirate_badges.models import check_badges

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('pp_blob')


def get_form(t):
	#grabs the appropriate form for the text input corresponding to type from TYPE_CHOICES
	fd = ForumDimension.objects.get(key=t)
	return fd.get_form(), fd.get_model(), fd.name


def get_models():
	#returns a list of child models for ForumBlob
	return ForumDimension.objects.filter(is_content=True)


@register.filter    
def subtract(value, arg):
Esempio n. 4
0
from django.contrib.contenttypes.models import ContentType
from pirate_core import HttpRedirectException, namespace_get, FormMixin
from pirate_forum.models import Question, Nomination

from pirate_permissions.models import Permission

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)
'''
This file contains all of the tags that pertain to Issue objects, in order to fetch one
issue, a list of issues, or to add or update an issue.
'''

# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('pp_permissions')


@block
def cani(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    # this tag only works if a valid pair is assigned to the 'object=' argument
    obj = kwargs.pop('object', None)
    user = kwargs.pop('user', None)

    if obj is None:
        raise ValueError(
            "tag requires that a object pair be passed "
Esempio n. 5
0
from django.http import HttpResponseRedirect
import datetime
from django.contrib.auth.models import User
from pirate_badges.models import Badge, BadgeDimension, test_badge, BadgeType
from pirate_core import HttpRedirectException, namespace_get, FormMixin
from pirate_social.models import RelationshipEvent 
from pirate_deliberation.models import Argument
from pirate_consensus.models import UpDownVote
from django.contrib.contenttypes.models import ContentType
from tagging.models import TaggedItem

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_badge')


@block
def pp_badge_dimensions(context, nodelist, *args, **kwargs):
    '''Retrieves all dimensions of badges'''
    context.push()
    namespace = get_namespace(context)

    namespace['badges'] = BadgeDimension.objects.all()

    output = nodelist.render(context)
    context.pop()
    return output

Esempio n. 6
0
from django import forms
from django.http import HttpResponseRedirect
import datetime
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from pirate_core import HttpRedirectException, namespace_get, FormMixin
from pirate_social.models import Subscription

from pirate_signals.models import aso_rep_event, notification_send

from customtags.decorators import block_decorator

register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_social')


@block
def pp_get_all_users(context, nodelist, *args, **kwargs):
    context.push()
    namespace = get_namespace(context)

    users = User.objects.all()

    namespace['feed'] = master_query
    output = nodelist.render(context)
    context.pop()

    return output
Esempio n. 7
0
from django import template

from pirate_core import namespace_get
from oa_cache.views import render_hashed

from settings import DOMAIN

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_cache')


@block
def pp_get_cached_data(context, nodelist, *args, **kwargs):
    """
    This templatetag is called only when the page is initially loaded, to
    give the template access to 

    :param object: id of django.db.models.Model object
    :type object: str 
    :param user: djngo.contrib.auth.models.User object
    :returns:
        * pp_consensus.consensus
            This is the consensus object itself
        * pp_consensus.interest
            Holds the interest integer generated by the ranking algorithm
        * pp_consensus.controversy
            Holds the controversy rating generated by the controversy ranking algorithm
        * pp_consensus.consensus
Esempio n. 8
0
from pirate_login.models import Login, Register
from pirate_social.models import Location

from oa_verification.models import EmailVerification
import datetime, random, sha
from django.core.mail import send_mail

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)
'''
This file contains all of the tags that pertain to User/Login objects
'''
# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('pp_login')


class KeyGenerator(forms.Form):
    """Form for generating a new key for registration."""
    form_id = forms.CharField(widget=forms.HiddenInput(),
                              initial="pp_key_generator")
    user = forms.CharField(label=_(u'Username'))


@block
def pp_last_visit(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)
Esempio n. 9
0
from django import template
from oa_platform.models import Platform, PlatformDimension
from pirate_core import namespace_get
from django.contrib.contenttypes.models import ContentType
from pirate_consensus.models import Consensus
from django import forms
from pirate_core.fields import JqSplitDateTimeField
from pirate_core.widgets import JqSplitDateTimeWidget
from customtags.decorators import block_decorator
from pirate_forum.models import ForumDimension


register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('oa_platform')


@block
def pp_is_in_platform(context, nodelist, *args, **kwargs):
    context.push()
    namespace = get_namespace(context)

    object_pk = kwargs.get('object_pk', None)
    platform = kwargs.get('platform', None)

    namespace['is_in'] = object_pk in platform.planks

    output = nodelist.render(context)
    context.pop()
Esempio n. 10
0
from django.contrib.contenttypes.models import ContentType
from tagging.models import Tag, TaggedItem
from pirate_profile.models import Profile
from pirate_core.helpers import clean_html
from pirate_sources.models import IMGSource

import pytz

from pirate_core import HttpRedirectException, namespace_get

from customtags.decorators import block_decorator

register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get("pp_profile")


@block
def pp_get_user_profile(context, nodelist, *args, **kwargs):
    """
    This block tag can create or process forms to get tags.
    Usage is as follows:
    {% pp_get_user_profile user=requet.object %}
       Do stuff with {{ pp_profile.user }} and {{ pp_profile.profile }}.
    {% endpp_get_user_profile %}
    """

    context.push()
    namespace = get_namespace(context)
Esempio n. 11
0
import datetime
import sys
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from pirate_reputation.models import Reputation, ReputationDimension, ReputationEvent, AbuseTicket, FeedbackTicket
from pirate_consensus.models import Consensus
from pirate_forum.models import get_rangelist
from pirate_core import namespace_get
import settings
from notification import models as notification

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_reputation')


@block
def pp_get_reputation_events_graph(context, nodelist, *args, **kwargs):
    '''
    This block tag can create or process forms to get tags.
    Usage is as follows:

    {% pp_get_reputation_events_graph user=request.object x=8 y=100 %}
       Do stuff with {{ pp_reputation.graph_html }}
    {% endpp_get_reputation %}

    This template tag dynamically generates the html required for a (x,y) graph
    where x is the activity rate and y is the time dimension. This graph shows
    users a basic idea of the user's activity rate.
Esempio n. 12
0
from pirate_topics.forms import TopicForm

from pirate_profile.models import Profile

from django.utils.html import urlize

from pirate_signals.models import aso_rep_event, update_agent

from pirate_badges.models import check_badges

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('pp_blob')


def get_form(t):
    #grabs the appropriate form for the text input corresponding to type from TYPE_CHOICES
    fd = ForumDimension.objects.get(key=t)
    return fd.get_form(), fd.get_model(), fd.name


def get_models():
    #returns a list of child models for ForumBlob
    return ForumDimension.objects.filter(is_content=True)


@register.filter    
def subtract(value, arg):
Esempio n. 13
0
from django import template
from pirate_core import namespace_get
from oa_dashboard.models import DashboardPanel
from oa_cache.views import render_hashed
from oa_cache.models import interpret_hash
from django.contrib.auth.models import User
from customtags.decorators import block_decorator


register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('oa_dashboard')


@block
def oa_get_dashboard(context, nodelist, *args, **kwargs):
    context.push()
    namespace = get_namespace(context)

    request = kwargs.get('request', None)
    user = kwargs.get('user', None)
    dashboard_id = kwargs.get('dashboard_id', None)
    boards = []
    namespace['boards'] = {}
    if user is not None and user.is_authenticated() and dashboard_id is not None:
        #get platform for this contenttype and user
        boards = DashboardPanel.objects.filter(user=user,
                dashboard_id=dashboard_id).order_by('priority')
    elif not user.is_authenticated():
        try:
Esempio n. 14
0
from django import template
from django import forms
from django.http import HttpResponseRedirect
import datetime
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from pirate_core import HttpRedirectException, namespace_get, FormMixin
from pirate_social.models import Subscription

from pirate_signals.models import aso_rep_event, notification_send

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_social')

@block
def pp_get_all_users(context, nodelist, *args, **kwargs):
    context.push()
    namespace = get_namespace(context)

    users = User.objects.all()
    
    
    
    namespace['feed'] = master_query
    output = nodelist.render(context)
    context.pop()

    return output
Esempio n. 15
0
from pirate_core.helpers import clean_html

from pirate_social.models import RelationshipEvent
from pirate_signals.models import relationship_event
from pirate_social.models import register_relationship_event
from pirate_core import HttpRedirectException, namespace_get, FormMixin

from django.template.defaultfilters import stringfilter
import uuid
from customtags.decorators import block_decorator

register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_tag')
"""This is more of a group of helper generic templatetags

    TODO: Change the namespace and all hooks to reflect that"""

from django.template.defaultfilters import floatformat


@register.filter
def percent(value):
    """
    **Filter**

    Takes a float value and returns it as a percentage. Only makes sense for float values in the range [0,1].

    for example:
Esempio n. 16
0
from django.http import HttpResponseRedirect
import datetime
from django.contrib.auth.models import User
from pirate_badges.models import Badge, BadgeDimension, test_badge, BadgeType
from pirate_core import HttpRedirectException, namespace_get, FormMixin
from pirate_social.models import RelationshipEvent
from pirate_deliberation.models import Argument
from pirate_consensus.models import UpDownVote
from django.contrib.contenttypes.models import ContentType
from tagging.models import TaggedItem

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_badge')


@block
def pp_badge_dimensions(context, nodelist, *args, **kwargs):
    '''Retrieves all dimensions of badges'''
    context.push()
    namespace = get_namespace(context)

    namespace['badges'] = BadgeDimension.objects.all()

    output = nodelist.render(context)
    context.pop()
    return output

Esempio n. 17
0
from pirate_core import HttpRedirectException, namespace_get, FormMixin
from pirate_forum.models import Question, Nomination

from pirate_permissions.models import Permission

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

'''
This file contains all of the tags that pertain to Issue objects, in order to fetch one
issue, a list of issues, or to add or update an issue.
'''

# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('pp_permissions')


@block
def cani(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    # this tag only works if a valid pair is assigned to the 'object=' argument
    obj = kwargs.pop('object', None)
    user = kwargs.pop('user', None)

    if obj is None:
        raise ValueError("tag requires that a object pair be passed "
                             "to it assigned to the 'object=' argument, and that the str "
Esempio n. 18
0
from django.conf import settings
from django.core.paginator import Paginator, InvalidPage
from django.http import Http404
from django.shortcuts import render_to_response
from django.template import RequestContext
from haystack.forms import ModelSearchForm, FacetedSearchForm
from haystack.query import EmptySearchQuerySet

RESULTS_PER_PAGE = getattr(settings, 'HAYSTACK_SEARCH_RESULTS_PER_PAGE', 20)

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('oa_search')

"""
Port of the Haystack Search View to our TemplateTag language
"""


@block
def oa_haystack_search(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    dimension = kwargs.get('search_key', None)
    POST = kwargs.get('POST', None)
    page = kwargs.get('page', None)
Esempio n. 19
0
from django.http import HttpResponseRedirect
from django.contrib.contenttypes.models import ContentType

from customtags.decorators import block
from pirate_core import FormMixin, ComboFormFactory, namespace_get
from django import template

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('pp_core')


@block
def pp_combo_form(context, nodelist, *args, **kwargs):
    """

    This tag is used to merge two separate forms into one form.  It does this
    by performing three actions:

    (1) It merges the fields of two separate forms into a single form with
        unified error messaging, and uniqueness among field names.
    (2) When provided a POST argument that matches its internally-determined
        form id, it will process that form in order to produce any error messages
    (3) When provided with a POST argument, it will assume that all forms
        passed in as arguments will also have been instantiated with that same POST.
        The validity of the MultiForm it produces will be tested; the MultiForm
        iteself will loop over the individual sub-forms testing to see if each is 
        valid as well.  Any errors discovered will be added to its own errors.
Esempio n. 20
0
from django.conf import settings
from django.core.paginator import Paginator, InvalidPage
from django.http import Http404
from django.shortcuts import render_to_response
from django.template import RequestContext
from haystack.forms import ModelSearchForm, FacetedSearchForm
from haystack.query import EmptySearchQuerySet

RESULTS_PER_PAGE = getattr(settings, 'HAYSTACK_SEARCH_RESULTS_PER_PAGE', 20)

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('oa_search')
"""
Port of the Haystack Search View to our TemplateTag language
"""


@block
def oa_haystack_search(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    dimension = kwargs.get('search_key', None)
    POST = kwargs.get('POST', None)

    load_all = True
Esempio n. 21
0
import datetime
import sys
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from pirate_reputation.models import Reputation, ReputationDimension, ReputationEvent, AbuseTicket, FeedbackTicket
from pirate_consensus.models import Consensus
from pirate_forum.models import get_rangelist
from pirate_core import namespace_get
import settings
from notification import models as notification

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_reputation')


@block
def pp_get_reputation_events_graph(context, nodelist, *args, **kwargs):
    '''
    This block tag can create or process forms to get tags.
    Usage is as follows:

    {% pp_get_reputation_events_graph user=request.object x=8 y=100 %}
       Do stuff with {{ pp_reputation.graph_html }}
    {% endpp_get_reputation %}

    This template tag dynamically generates the html required for a (x,y) graph
    where x is the activity rate and y is the time dimension. This graph shows
    users a basic idea of the user's activity rate.
Esempio n. 22
0
from django import forms
from django.http import HttpResponseRedirect
import datetime
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from pirate_core import HttpRedirectException, namespace_get, FormMixin
from pirate_social.models import Subscription

from pirate_signals.models import aso_rep_event, notification_send

from customtags.decorators import block_decorator

register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_subscription')


@block
def pp_get_subscribees_for_user(context, nodelist, *args, **kwargs):
    context.push()
    namespace = get_namespace(context)

    user = kwargs.pop('user', None)
    start = kwargs.get('start', None)
    end = kwargs.get('end', None)

    if start is None and end is None:
        start = 0
        end = 8
    else:
Esempio n. 23
0
from pirate_social.models import Location

from oa_verification.models import EmailVerification
import datetime, random, sha
from django.core.mail import send_mail

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)


'''
This file contains all of the tags that pertain to User/Login objects
'''
# this function assignment lets us reuse the same code block a bunch of places
get_namespace = namespace_get('pp_login')


class KeyGenerator(forms.Form):
    """Form for generating a new key for registration."""
    form_id = forms.CharField(widget=forms.HiddenInput(), initial="pp_key_generator")
    user = forms.CharField(label=_(u'Username'))


@block
def pp_last_visit(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    user = kwargs.get('user', None)
Esempio n. 24
0
from pirate_reputation.models import ReputationDimension
from pirate_core.helpers import clean_html
from pirate_deliberation.forms import YeaArgumentForm, NayArgumentForm
from pirate_deliberation.choices import ARG_TYPES_DICT

from pirate_core import HttpRedirectException, namespace_get, FormMixin

from django.utils.html import urlize

from pirate_signals.models import aso_rep_event,notification_send, relationship_event

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_argumentation')


@block
def pp_get_argument_count(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    obj = kwargs.pop('object', None)
    arg_type = kwargs.pop('arg_type', None)

    arg_list = Argument.objects.all()

    if isinstance(arg_type, unicode):
        arg_type, created = Stance.objects.get_or_create(arg=arg_type)
Esempio n. 25
0
from django import template
from django import forms
from django.http import HttpResponseRedirect
import datetime
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from pirate_core import HttpRedirectException, namespace_get, FormMixin
from pirate_social.models import Subscription

from pirate_signals.models import aso_rep_event, notification_send

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_subscription')


@block
def pp_get_subscribees_for_user(context, nodelist, *args, **kwargs):
    context.push()
    namespace = get_namespace(context)

    user = kwargs.pop('user', None)
    start = kwargs.get('start', None)
    end = kwargs.get('end', None)

    if start is None and end is None:
        start = 0
        end = 8
    else:
Esempio n. 26
0
from django import template

from pirate_core import namespace_get
from oa_cache.views import render_hashed

from settings import DOMAIN

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_cache')


@block
def pp_get_cached_data(context, nodelist, *args, **kwargs):
    """
    This templatetag is called only when the page is initially loaded, to
    give the template access to 

    :param object: id of django.db.models.Model object
    :type object: str 
    :param user: djngo.contrib.auth.models.User object
    :returns:
        * pp_consensus.consensus
            This is the consensus object itself
        * pp_consensus.interest
            Holds the interest integer generated by the ranking algorithm
        * pp_consensus.controversy
            Holds the controversy rating generated by the controversy ranking algorithm
        * pp_consensus.consensus
Esempio n. 27
0
from pirate_signals.models import aso_rep_event, notification_send, relationship_event


from django.contrib.auth.models import User
from pirate_sources.models import IMGSource
from oa_verification.models import arpv, PhotoVerificationTask, PhotoUserVerifications, Referral
from oa_verification.forms import arpvForm, ReferralForm
from pirate_core.widgets import HorizRadioRenderer
from collections import defaultdict

from customtags.decorators import block_decorator
register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('oa_ver')


class ActionTakenForm(forms.ModelForm):

    def save(self, commit=True):
        new_source = super(ActionTakenForm, self).save(commit=commit)
        return new_source

    class Meta:
        model = ActionTaken
        exclude = ('user', 'content_object','object_pk','content_type')

    form_id = forms.CharField(widget=forms.HiddenInput(), initial="pp_actiontaken_form")

Esempio n. 28
0
from django.contrib.contenttypes.models import ContentType
from tagging.models import Tag, TaggedItem
from pirate_profile.models import Profile
from pirate_core.helpers import clean_html
from pirate_sources.models import IMGSource

import pytz

from pirate_core import HttpRedirectException, namespace_get

from customtags.decorators import block_decorator

register = template.Library()
block = block_decorator(register)

get_namespace = namespace_get('pp_profile')


@block
def pp_get_user_profile(context, nodelist, *args, **kwargs):
    '''
    This block tag can create or process forms to get tags.
    Usage is as follows:
    {% pp_get_user_profile user=requet.object %}
       Do stuff with {{ pp_profile.user }} and {{ pp_profile.profile }}.
    {% endpp_get_user_profile %}
    '''

    context.push()
    namespace = get_namespace(context)