Пример #1
0
    def __init__(self, issue, person, creator, *args, **kwargs):
        
        self.request = get_current_request()
        
        self.issue = issue
        self.person = person
        self.creator = creator
        #self.other_person = issue.random_unpositioned_other_person
        
#        print 'person:',self.person
#        print 'creator:',self.creator
        self.position = self.issue.get_last_position(self.person, self.creator)
        self.positionable = self.issue.positionable(self.request.user)
        self.IM_WAIT_DAYS_BEFORE_REANSWER = settings.IM_WAIT_DAYS_BEFORE_REANSWER
        self.positioned = self.issue.positioned(self.person, self.creator)
        self.choice_counts = self.issue.get_choice_counts()
        
        pt = models.Priviledge.get_current()
        if not self.request.user.is_authenticated():
            # Show buttons which will trigger login/registration form.
            self.allow_answer = True
        elif self.person == self.creator or self.person is None:
            self.allow_answer = pt.can.answer_issue_for_themself
        else:
            self.allow_answer = pt.can.answer_issue_for_other
        
        self.buttons_fixed_buttom = self.allow_answer and int(self.request.COOKIES.get(c.COOKIE_BUTTONS_FLOAT, 1))
        
        super(IssueResponseForm, self).__init__(*args, **kwargs)
Пример #2
0
    def __init__(self, issue, person, creator, *args, **kwargs):

        self.request = get_current_request()

        self.issue = issue
        self.person = person
        self.creator = creator
        #self.other_person = issue.random_unpositioned_other_person

        #        print 'person:',self.person
        #        print 'creator:',self.creator
        self.position = self.issue.get_last_position(self.person, self.creator)
        self.positionable = self.issue.positionable(self.request.user)
        self.IM_WAIT_DAYS_BEFORE_REANSWER = settings.IM_WAIT_DAYS_BEFORE_REANSWER
        self.positioned = self.issue.positioned(self.person, self.creator)
        self.choice_counts = self.issue.get_choice_counts()

        pt = models.Priviledge.get_current()
        if not self.request.user.is_authenticated():
            # Show buttons which will trigger login/registration form.
            self.allow_answer = True
        elif self.person == self.creator or self.person is None:
            self.allow_answer = pt.can.answer_issue_for_themself
        else:
            self.allow_answer = pt.can.answer_issue_for_other

        self.buttons_fixed_buttom = self.allow_answer and int(
            self.request.COOKIES.get(c.COOKIE_BUTTONS_FLOAT, 1))

        super(IssueResponseForm, self).__init__(*args, **kwargs)
Пример #3
0
def get_ssl_cn():
    # Get the Common Name of the SSL client certificate.
    # If there's no CN, there is no valid client SSL certificate
    # and SSL authorization cannot be used.
    # In that case, throw an exception - this should only be used
    # if SSL is set up properly
    http_request = get_current_request()
    try:
        cn = http_request.META['SSL_CLIENT_S_DN_CN']
        return cn
    except KeyError:
        raise RuntimeError(_('SSL configuration error: No client certificate'))
Пример #4
0
    def _authorized(*args, **kw):
        # TODO: perform some sort of cryptographic UN-wrapping.
        if settings.SSL_AUTHENTICATION:
            # SSL Authentication is on.
            # This will only work if Apache is configured correctly,
            # and the client has presented a valid certificate recognized
            # by the server's CA.
            http_request = get_current_request()

            client_id = get_ssl_cn()
            auth_code = args[0]
            if sha1_hash(client_id) == auth_code:
                return function(*args, **kw)
            else:
                raise RuntimeError(_('Authorization failed'))
        else:
            # No SSL, simple password validation
            id, pw = args[0].split('@')

            if is_valid_login(id, pw):
                return function(*args, **kw)
            else:
                raise RuntimeError(_('Authorization failed'))
Пример #5
0
    def add(self, action, changes, model, user=None, object_id=None):
        if not getattr(settings, "DJANGO_HISTORY_TRACK", True):
            return
        request = get_current_request()
        if not user:
            if request:
                user = request.user
        user_id = user.pk if user else None
        model_ct = ContentType.objects.get_for_model(model)
        model_id = model_ct.pk
        object_id = object_id or model.pk

        # exclusion / none -checks
        excludes = get_setting("EXCLUDE_CHANGES")
        if excludes:
            excludes_for_model = excludes.get("{0}.{1}".format(model_ct.app_label, model_ct.model))
            if excludes_for_model:
                for k, v in copy.deepcopy(changes).iteritems():
                    if k in excludes_for_model.get("fields", []):
                        del changes[k]
        if not changes:
            return

        # for FKs, get old/new information
        fields = model._meta.local_fields

        def get_item(model, pk):
            value = None
            if isinstance(pk, models.Model):
                pk = copy.deepcopy(pk.pk)
            try:
                value = unicode(model.objects.get(pk=pk))
            except Exception, e:
                if settings.DEBUG:
                    print e
            return value
Пример #6
0
def normalize_url(url):
    if url.startswith("/"):
        request = get_current_request()
        return "%s://%s%s" % (request.is_secure() and "https" or "http", request.hostname, url)
    return url