示例#1
0
    def form_valid(self, form):

        gas = self.get_object()
       
        #insert here user permissions check
 
        name = form.cleaned_data['name']
        id_in_des = form.cleaned_data['id_in_des']
        headquarter = form.cleaned_data['headquarter']
        description = form.cleaned_data['description']
        birthday = form.cleaned_data['birthday']
        #contact_set = form.cleaned_data['contact_set']
        #orders_email_contact = form.cleaned_data['']

        if gas:
            gas.name = name
       
        gas.save() 

        # Code to update a generic set of objects  
        #to_add, to_remove = self.update_values(old_categories, 
        #    new_categories
        #)
        #action.category_set.add(*to_add)
        #action.category_set.remove(*to_remove)

        #if form.cleaned_data['politician_set']:

        success_url = gas.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#2
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        #recipient = form.cleaned_data['referrer']
        recipient = action.referrers
        message = form.cleaned_data['message_text']
        request_type = consts.REQUEST_TYPE_MESSAGE

        sender.assert_can_send_action_message(sender, 
            recipient, 
            action
        )

        action_request = ActionRequest(
            action=action,
            sender=sender,
            request_notes=message,
            request_type=request_type 
        )
        action_request.save()
        action_request.recipient_set.add(*recipient)
        action_request.save()

        action_message_sent.send(sender=action_request)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#3
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        message = form.cleaned_data['request_text']
        status = form.cleaned_data['status_to_set']

        if status in (a_consts.ACTION_STATUS_VICTORY,):
            request_type = consts.REQUEST_TYPE_SET_VICTORY
        elif status in (a_consts.ACTION_STATUS_CLOSED,):
            request_type = consts.REQUEST_TYPE_SET_CLOSURE

        sender.assert_can_ask_action_status_update(
            action,
            request_type
        )

        action_request = ActionRequest(
            action=action,
            sender=sender,
            request_notes=message,
            request_type=request_type 
        )
        action_request.save()
        
        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#4
0
    def form_valid(self, form):

        gas = self.get_object()

        #insert here user permissions check

        name = form.cleaned_data['name']
        id_in_des = form.cleaned_data['id_in_des']
        headquarter = form.cleaned_data['headquarter']
        description = form.cleaned_data['description']
        birthday = form.cleaned_data['birthday']
        #contact_set = form.cleaned_data['contact_set']
        #orders_email_contact = form.cleaned_data['']

        if gas:
            gas.name = name

        gas.save()

        # Code to update a generic set of objects
        #to_add, to_remove = self.update_values(old_categories,
        #    new_categories
        #)
        #action.category_set.add(*to_add)
        #action.category_set.remove(*to_remove)

        #if form.cleaned_data['politician_set']:

        success_url = gas.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#5
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        recipient = form.cleaned_data['follower']
        request_notes = form.cleaned_data['request_text']
        request_type = consts.REQUEST_TYPE_MODERATION

        sender.assert_can_request_moderation_for_action(sender, recipient, action)
        #print("RECIPIENT: %s", recipient)
        action_request = ActionRequest(
            action=action,
            sender=sender,
            request_notes=request_notes,
            request_type=request_type 
        )
        action_request.save()
        action_request.recipient_set.add(recipient)
        action_request.save()

        action_moderation_request_submitted.send(sender=action_request)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#6
0
    def form_valid(self, form):
        """Create askbot question --> then set action relations"""

        timestamp = datetime.datetime.now()
        title = form.cleaned_data['title']
        tagnames = form.cleaned_data['tags']
        text = form.cleaned_data['text']
        in_nomine = form.cleaned_data['in_nomine']
        total_threshold = int(form.cleaned_data['threshold'])

        question = self.request.user.post_question(
            title = title,
            body_text = text,
            tags = tagnames,
            wiki = False,
            is_anonymous = False,
            timestamp = timestamp
        )

        action = question.action 

        # check if this action is created by an organization
        if in_nomine[:3] == "org":
            in_nomine_pk = int(in_nomine[4:])
            log.debug("IN_NOMINE %s _PK %s" % (in_nomine[:3], in_nomine[4:]))
            action.in_nomine_org = Organization.objects.get(pk=in_nomine_pk)
            # We update "in_nomine_org" and no other action parameters below,
            # so it is safe and good to "save" here.
            action.save()

        categories = form.cleaned_data['category_set']
        action.category_set.add(*categories)

        geoname_data = form.cleaned_data['geoname_set']
        #COMMENT WARNING TODO: we should have a specific GeonameField
        # which has a clean() method that does the following kludge
        # The same is valid for other m2m fields below
        geonames = self.get_or_create_geonames(geoname_data)
        action.geoname_set.add(*geonames)
        
        politician_data = form.cleaned_data['politician_set']
        politicians = self.get_or_create_politicians(politician_data)
        action.politician_set.add(*politicians)
        
        medias = form.cleaned_data['media_set']
        #TODO: Matteo 
        action.media_set.add(*medias)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#7
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()
        moderator = form.cleaned_data['moderator']
        #notes = form.cleaned_data['text']

        sender.assert_can_remove_action_moderator(moderator, action)

        action.moderator_set.remove(moderator)

        action_moderator_removed.send(sender=action, moderator=moderator)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#8
0
    def form_valid(self, form):
        """Create askbot question --> then set action relations"""

        timestamp = datetime.datetime.now()
        title = form.cleaned_data['title']
        tagnames = form.cleaned_data['tags']
        text = form.cleaned_data['text']
        in_nomine = form.cleaned_data['in_nomine']
        total_threshold = int(form.cleaned_data['threshold'])

        question = self.request.user.post_question(title=title,
                                                   body_text=text,
                                                   tags=tagnames,
                                                   wiki=False,
                                                   is_anonymous=False,
                                                   timestamp=timestamp)

        action = question.action

        # check if this action is created by an organization
        if in_nomine[:3] == "org":
            in_nomine_pk = int(in_nomine[4:])
            log.debug("IN_NOMINE %s _PK %s" % (in_nomine[:3], in_nomine[4:]))
            action.in_nomine_org = Organization.objects.get(pk=in_nomine_pk)
            # We update "in_nomine_org" and no other action parameters below,
            # so it is safe and good to "save" here.
            action.save()

        categories = form.cleaned_data['category_set']
        action.category_set.add(*categories)

        geoname_data = form.cleaned_data['geoname_set']
        #COMMENT WARNING TODO: we should have a specific GeonameField
        # which has a clean() method that does the following kludge
        # The same is valid for other m2m fields below
        geonames = self.get_or_create_geonames(geoname_data)
        action.geoname_set.add(*geonames)

        politician_data = form.cleaned_data['politician_set']
        politicians = self.get_or_create_politicians(politician_data)
        action.politician_set.add(*politicians)

        medias = form.cleaned_data['media_set']
        #TODO: Matteo
        action.media_set.add(*medias)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#9
0
    def form_valid(self, form):

        user = self.request.user
        action_request = self.get_object()
        action = action_request.action
        message_response = form.cleaned_data['message_text']

        user.assert_can_reply_to_action_message(action_request)

        action_request.is_processed = True
        action_request.is_accepted = True
        action_request.answer_notes = message_response
        action_request.save()

        action_message_replied.send(sender=action_request, replier=user)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#10
0
    def form_valid(self, form):

        user = self.request.user
        action_request = self.get_object()
        action = action_request.action
        message_response = form.cleaned_data['message_text']

        user.assert_can_reply_to_action_message(action_request)

        action_request.is_processed = True
        action_request.is_accepted = True
        action_request.answer_notes = message_response
        action_request.save()

        action_message_replied.send(sender=action_request, replier=user)
 
        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#11
0
    def form_valid(self, form):

        user = self.request.user
        action_request = self.get_object()
        action = action_request.action
        accepted = form.cleaned_data['accept_request']
        answer_notes = form.cleaned_data['answer_text']

        user.assert_can_process_moderation_for_action(action_request)

        action_request.is_processed = True
        #NOTE: weird behaivour. Cleaned data for accepted return a string
        action_request.is_accepted = [False, True][accepted == '1']
        #print("action_request is accepted: %s" % action_request.is_accepted)
        action_request.answer_notes = answer_notes
        action_request.save()

        if action_request.is_accepted:
            #print("action.moderator_set.add(user)")
            action.moderator_set.add(user)

        # For all same request_types ActionRequest -->
        # set processed, is_accepted,
        # and in answer_notes write ("processed with #action_request.pk")
        # QUESTION: Is this true only for accepted requests or for not
        # accepted requests too?
        duplicate_requests = action_request.get_same_request_types().exclude(
            pk=action_request.pk)

        for request in duplicate_requests:
            request.is_processed = True
            request.is_accepted = action_request.is_accepted
            request.answer_notes = "moderation request processed and %s accepted with action_request %s" % (
                action_request.pk, ["", "not"][not action_request.is_accepted])
            request.save()

        action_moderation_request_processed.send(sender=action_request
                                                 #moderator=user
                                                 )

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#12
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()
        moderator = form.cleaned_data['moderator']
        #notes = form.cleaned_data['text']

        sender.assert_can_remove_action_moderator(
            moderator, 
            action
        )

        action.moderator_set.remove(moderator)

        action_moderator_removed.send(sender=action, 
            moderator=moderator
        )

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#13
0
    def form_valid(self, form):

        user = self.request.user
        action_request = self.get_object()
        action = action_request.action
        accepted = form.cleaned_data['accept_request']
        answer_notes = form.cleaned_data['answer_text']

        user.assert_can_process_moderation_for_action(action_request)

        action_request.is_processed = True
        #NOTE: weird behaivour. Cleaned data for accepted return a string 
        action_request.is_accepted = [False, True][accepted=='1']
        #print("action_request is accepted: %s" % action_request.is_accepted)
        action_request.answer_notes = answer_notes
        action_request.save()


        if action_request.is_accepted:
            #print("action.moderator_set.add(user)")
            action.moderator_set.add(user)

        # For all same request_types ActionRequest --> 
        # set processed, is_accepted, 
        # and in answer_notes write ("processed with #action_request.pk")
        # QUESTION: Is this true only for accepted requests or for not 
        # accepted requests too?
        duplicate_requests = action_request.get_same_request_types().exclude(pk=action_request.pk)

        for request in duplicate_requests:
            request.is_processed = True
            request.is_accepted = action_request.is_accepted
            request.answer_notes = "moderation request processed and %s accepted with action_request %s" % (action_request.pk, ["","not"][not action_request.is_accepted])
            request.save()

        action_moderation_request_processed.send(sender=action_request
            #moderator=user
        )

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#14
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        message = form.cleaned_data['request_text']
        status = form.cleaned_data['status_to_set']

        if status in (a_consts.ACTION_STATUS_VICTORY, ):
            request_type = consts.REQUEST_TYPE_SET_VICTORY
        elif status in (a_consts.ACTION_STATUS_CLOSED, ):
            request_type = consts.REQUEST_TYPE_SET_CLOSURE

        sender.assert_can_ask_action_status_update(action, request_type)

        action_request = ActionRequest(action=action,
                                       sender=sender,
                                       request_notes=message,
                                       request_type=request_type)
        action_request.save()

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#15
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        recipient = form.cleaned_data['follower']
        request_notes = form.cleaned_data['request_text']
        request_type = consts.REQUEST_TYPE_MODERATION

        sender.assert_can_request_moderation_for_action(
            sender, recipient, action)
        #print("RECIPIENT: %s", recipient)
        action_request = ActionRequest(action=action,
                                       sender=sender,
                                       request_notes=request_notes,
                                       request_type=request_type)
        action_request.save()
        action_request.recipient_set.add(recipient)
        action_request.save()

        action_moderation_request_submitted.send(sender=action_request)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#16
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        #recipient = form.cleaned_data['referrer']
        recipient = action.referrers
        message = form.cleaned_data['message_text']
        request_type = consts.REQUEST_TYPE_MESSAGE

        sender.assert_can_send_action_message(sender, recipient, action)

        action_request = ActionRequest(action=action,
                                       sender=sender,
                                       request_notes=message,
                                       request_type=request_type)
        action_request.save()
        action_request.recipient_set.add(*recipient)
        action_request.save()

        action_message_sent.send(sender=action_request)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#17
0
    def form_valid(self, form):

        form.save()
        success_url = GAS.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#18
0
    def form_valid(self, form):
        """Edit askbot question --> then set action relations"""

        action = self.get_object()

        self.request.user.assert_can_edit_action(action)

        question = action.question

        title = form.cleaned_data['title']
        #theese tags will be replaced to the old ones
        tagnames = form.cleaned_data['tags']
        text = form.cleaned_data['text']
        total_threshold = int(form.cleaned_data['threshold'])

        self.request.user.edit_question(
            question=question,
            title=title,
            body_text=text,
            revision_comment=None,
            tags=tagnames,
            wiki=False,
            edit_anonymously=False,
        )

        new_categories = form.cleaned_data['category_set']
        old_categories = action.categories
        to_add, to_remove = self.update_values(old_categories, new_categories)
        action.category_set.add(*to_add)
        action.category_set.remove(*to_remove)

        geoname_data = form.cleaned_data['geoname_set']
        old_geonames = action.geonames
        new_geonames = self.get_or_create_geonames(geoname_data)
        to_add, to_remove = self.update_values(old_geonames, new_geonames)
        action.geoname_set.add(*to_add)
        action.geoname_set.remove(*to_remove)

        politician_data = form.cleaned_data['politician_set']
        old_politicians = action.politicians
        new_politicians = self.get_or_create_politicians(politician_data)
        to_add, to_remove = self.update_values(old_politicians,
                                               new_politicians)
        action.politician_set.add(*to_add)
        action.politician_set.remove(*to_remove)

        medias = form.cleaned_data['media_set']
        #TODO: Matteo
        #old_medias = action.medias
        #new_medias = []
        #to_add, to_remove = self.update_values(old_medias,
        #    new_medias
        #)
        #action.media_set.add(*to_add)
        #action.media_set.remove(*to_remove)

        #for m2m_attr in (
        #    'geoname_set',
        #    'politician_set',
        #    'media_set'
        #):
        #    #Theese attributes should contain Json data
        #    m2m_value = form.cleaned_data.get(m2m_attr)
        #    if m2m_attr[:-4] == 'geoname':
        #        model = Geoname
        #        kwargs = {}
        #        kwargs['ext_res_type'] = {
        #            'type' : 'location_type',
        #            'name' : 'name'
        #        }
        #        kwargs['name'] = 'name'
        #    elif m2m_attr[:-4] == 'politician':
        #        model = Politician
        #        kwargs = {}
        #        #GET cityreps from locations ids
        #        if form.cleaned_data['geoname_set']:
        #            cityreps_ids = form.cleaned_data.get('geoname_set')
        #        else:
        #            cityreps_ids = [long(obj.external_resource.ext_res_id)
        #                for obj in action.geonames]

        #        # here we check that the threshold arrived is equal to
        #        # the the sum of the thrershold delta of all the politicians
        #        # the metho dwill raise exceptions if necessary
        #        #kwargs['charge_ids'] = self.get_politicians_charge_ids(
        #        #    cityreps_ids,
        #        #    m2m_value,
        #        #    get_lookup(MAP_MODEL_SET_TO_CHANNEL['cityrep'])
        #        #)
        #        if type(m2m_value) != list:
        #            m2m_value = [int(elem) for elem in m2m_value.strip('|').split('|')]

        #        m2m_value_copy = [elem for elem in m2m_value]
        #        kwargs['politicians_jsons'] = self.check_threshold(
        #            cityreps_ids,
        #            m2m_value_copy,
        #            total_threshold
        #        )
        #        kwargs['id_prefix'] = 'content_'
        #    elif m2m_attr[:-4] == 'media':
        #        kwargs = {}
        #        model = Media

        #    if len(m2m_value) != 0:
        #        """ Here we have to check if there are ExternalResource
        #        objects with pk equal to the provided ids.
        #        If there are ids that do not match with any ExternalResource
        #        object pk, than create them.
        #        If the ExternalResource which pks match with some ids was
        #        created too time ago, then check the openpolis Json to see
        #        if there had been some changes.
        #
        #        Finally check if there are Geoname objects linked to the found
        #        ExternalResource objects. If not, create them.
        #
        #        """
        #        # Values can be overlapping or non overlapping
        #        m2m_values_old = getattr(action, m2m_attr).all()

        #        m2m_values_new = self.get_m2m_values(
        #            m2m_attr,
        #            m2m_value,
        #            model,
        #            #ext_res_type={
        #            #    'type' : 'location_type',
        #            #    'name' : 'name'
        #            #}
        #            **kwargs
        #        )

        #        to_add, to_remove = self.update_values(m2m_values_old,
        #            m2m_values_new
        #        )

        #        getattr(action, m2m_attr).add(*to_add)
        #        getattr(action, m2m_attr).remove(*to_remove)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#19
0
    def form_valid(self, form):
        """Edit askbot question --> then set action relations"""

        action = self.get_object()
        
        self.request.user.assert_can_edit_action(action)

        question = action.question 

        title = form.cleaned_data['title']
        #theese tags will be replaced to the old ones
        tagnames = form.cleaned_data['tags']
        text = form.cleaned_data['text']
        total_threshold = int(form.cleaned_data['threshold'])

        self.request.user.edit_question(
            question = question,
            title = title,
            body_text = text,
            revision_comment = None,
            tags = tagnames,
            wiki = False, 
            edit_anonymously = False,
        )   


        new_categories = form.cleaned_data['category_set']
        old_categories = action.categories
        to_add, to_remove = self.update_values(old_categories, 
            new_categories
        )
        action.category_set.add(*to_add)
        action.category_set.remove(*to_remove)

        geoname_data = form.cleaned_data['geoname_set']
        old_geonames = action.geonames
        new_geonames = self.get_or_create_geonames(geoname_data)
        to_add, to_remove = self.update_values(old_geonames, 
            new_geonames
        )
        action.geoname_set.add(*to_add)
        action.geoname_set.remove(*to_remove)

        politician_data = form.cleaned_data['politician_set']
        old_politicians = action.politicians
        new_politicians = self.get_or_create_politicians(politician_data)
        to_add, to_remove = self.update_values(old_politicians, 
            new_politicians
        )
        action.politician_set.add(*to_add)
        action.politician_set.remove(*to_remove)
        
        medias = form.cleaned_data['media_set']
        #TODO: Matteo 
        #old_medias = action.medias
        #new_medias = []
        #to_add, to_remove = self.update_values(old_medias, 
        #    new_medias
        #)
        #action.media_set.add(*to_add)
        #action.media_set.remove(*to_remove)

        #for m2m_attr in (
        #    'geoname_set', 
        #    'politician_set',
        #    'media_set'
        #):
        #    #Theese attributes should contain Json data
        #    m2m_value = form.cleaned_data.get(m2m_attr)
        #    if m2m_attr[:-4] == 'geoname':
        #        model = Geoname
        #        kwargs = {}
        #        kwargs['ext_res_type'] = {
        #            'type' : 'location_type',
        #            'name' : 'name'
        #        }
        #        kwargs['name'] = 'name'
        #    elif m2m_attr[:-4] == 'politician':
        #        model = Politician
        #        kwargs = {}
        #        #GET cityreps from locations ids
        #        if form.cleaned_data['geoname_set']:
        #            cityreps_ids = form.cleaned_data.get('geoname_set')
        #        else:
        #            cityreps_ids = [long(obj.external_resource.ext_res_id) 
        #                for obj in action.geonames]

        #        # here we check that the threshold arrived is equal to
        #        # the the sum of the thrershold delta of all the politicians
        #        # the metho dwill raise exceptions if necessary
        #        #kwargs['charge_ids'] = self.get_politicians_charge_ids(
        #        #    cityreps_ids,
        #        #    m2m_value,
        #        #    get_lookup(MAP_MODEL_SET_TO_CHANNEL['cityrep'])
        #        #)
        #        if type(m2m_value) != list:
        #            m2m_value = [int(elem) for elem in m2m_value.strip('|').split('|')]

        #        m2m_value_copy = [elem for elem in m2m_value]
        #        kwargs['politicians_jsons'] = self.check_threshold(
        #            cityreps_ids,
        #            m2m_value_copy,
        #            total_threshold
        #        )
        #        kwargs['id_prefix'] = 'content_'
        #    elif m2m_attr[:-4] == 'media':
        #        kwargs = {}
        #        model = Media

        #    if len(m2m_value) != 0:
        #        """ Here we have to check if there are ExternalResource
        #        objects with pk equal to the provided ids.
        #        If there are ids that do not match with any ExternalResource
        #        object pk, than create them. 
        #        If the ExternalResource which pks match with some ids was
        #        created too time ago, then check the openpolis Json to see
        #        if there had been some changes.
        #        
        #        Finally check if there are Geoname objects linked to the found
        #        ExternalResource objects. If not, create them.
        #        
        #        """
        #        # Values can be overlapping or non overlapping
        #        m2m_values_old = getattr(action, m2m_attr).all()

        #        m2m_values_new = self.get_m2m_values(
        #            m2m_attr,
        #            m2m_value,
        #            model,
        #            #ext_res_type={
        #            #    'type' : 'location_type',
        #            #    'name' : 'name'
        #            #}
        #            **kwargs
        #        )

        #        to_add, to_remove = self.update_values(m2m_values_old, 
        #            m2m_values_new
        #        )

        #        getattr(action, m2m_attr).add(*to_add)
        #        getattr(action, m2m_attr).remove(*to_remove)
    
        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
示例#20
0
    def form_valid(self, form):

        form.save()
        success_url = GAS.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)