コード例 #1
0
    def post(self, request, fingerprint=None):

        if request.user.is_authenticated():

            try:
                fp = Fingerprint.valid().get(fingerprint_hash=fingerprint)

                comment = Comment(content_object=fp,
                                  site=Site.objects.get_current(),
                                  user=request.user,
                                  user_name=(request.user.get_full_name()
                                             or request.user.email),
                                  user_email=request.user.email,
                                  user_url="",
                                  comment=request.POST['comment'],
                                  ip_address=request.META.get(
                                      "REMOTE_ADDR", None))
                comment.save()

                return Response({'comment': CommentSerializer(comment).data},
                                status=status.HTTP_200_OK)

            except Fingerprint.DoesNotExist:
                pass

        return Response({}, status=status.HTTP_403_FORBIDDEN)
コード例 #2
0
    def handle(self, *args, **options):
        if len(args) == 1:

            with zipfile.ZipFile(args[0],"r") as zip:
                meta = json.loads(zip.read('metadata.json'),object_hook=json_util.object_hook)
                fdict = json.loads(zip.read('fingerprint.json'),object_hook=json_util.object_hook)

                new_fingerprint = Fingerprint()
                new_hash =None

                level = self.__checkFeasibility(meta, fdict)

                if level == AS_IS:
                    self.stdout.write('-- Hash/fingerprint_id are free, import as is on exported file.\n')

                    new_fingerprint.__dict__.update(fdict)

                    new_fingerprint.save()

                    self.__import(zip, args[0], new_fingerprint)

                elif level == NEW_IDS:
                    self.stdout.write('-- Hash/fingerprint_id are occupied, importing with a new id.\n')
                    new_hash = generate_hash()

                    fdict['fingerprint_hash'] = new_hash
                    del fdict['id']
                    new_fingerprint.__dict__.update(fdict)

                    new_fingerprint.save()

                    self.__addShares(meta, new_fingerprint)

                    self.__import(zip, args[0], new_fingerprint, replacing=True)

                else: # impossible
                    self.stdout.write('-- ERROR: Impossible to import fingerprint, the questionnaire doesnt exist, or doesnt match the slug.')


        else:
            self.stdout.write('-- USAGE: \n    '+
                'python manage.py fingerprint_import <path_file>'+
                '\n\n')
コード例 #3
0
    def get(self, request, *args, **kw):
        self.__subscribed = []
        self.__mlt_fused = {}

        if request.user.is_authenticated():

            ordered = cache.get('recommendations_' + str(request.user.id))

            if ordered == None:
                maxx = 100
                subscriptions = FingerprintSubscription.active().filter(
                    user=request.user)

                # first we generate the list of already subscribed databases, since they wont appear on suggestions
                for subscription in subscriptions:
                    self.__subscribed.append(
                        subscription.fingerprint.fingerprint_hash)

                c = CoreEngine()
                for subscription in subscriptions:
                    fingerprint = subscription.fingerprint
                    this_mlt = c.more_like_this(fingerprint.fingerprint_hash,
                                                fingerprint.questionnaire.slug,
                                                maxx=maxx)

                    self.__merge(this_mlt)

                ordered = sorted(self.__mlt_fused.values(),
                                 reverse=True,
                                 key=lambda x: x['score'])[:10]

                for entry in ordered:
                    try:
                        fingerprint = Fingerprint.valid().get(
                            fingerprint_hash=entry['id'])
                    except Fingerprint.DoesNotExist:
                        continue

                    entry['name'] = fingerprint.findName()

                    entry[
                        'href'] = 'fingerprint/' + fingerprint.fingerprint_hash + '/1/'

                cache.set('recommendations_' + str(request.user.id), ordered,
                          720)

            response = Response({'mlt': ordered}, status=status.HTTP_200_OK)

        else:
            response = Response({}, status=status.HTTP_403_FORBIDDEN)

        return response
コード例 #4
0
    def get(self, request, *args, **kw):

        if request.user.is_authenticated():
            list_viewed = []

            try:
                eprofile = EmifProfile.objects.get(user=request.user)
            except EmifProfile.DoesNotExist:
                print "-- ERROR: Couldn't get emif profile for user"

            most_hit = Hit.objects.filter(user=request.user).values(
                'user', 'hitcount__object_pk').annotate(
                    total_hits=Count('hitcount')).order_by('-total_hits')

            i = 0

            for hit in most_hit:
                try:
                    this_fingerprint = Fingerprint.valid().get(
                        id=hit['hitcount__object_pk'])

                    if eprofile.restricted:
                        try:
                            allowed = RestrictedUserDbs.objects.get(
                                user=request.user,
                                fingerprint=this_fingerprint)
                        except RestrictedUserDbs.DoesNotExist:
                            restricted = RestrictedGroup.hashes(request.user)

                            if this_fingerprint.fingerprint_hash not in RestrictedGroup.hashes(
                                    request.user):
                                continue

                    list_viewed.append({
                        'hash': this_fingerprint.fingerprint_hash,
                        'name': this_fingerprint.findName(),
                        'count': hit['total_hits']
                    })
                    i += 1
                    if i == 10:
                        break

                except Fingerprint.DoesNotExist:
                    print "-- Error on hitcount for fingerprint with id " + hit[
                        'hitcount__object_pk']

            response = Response({'mostviewed': list_viewed},
                                status=status.HTTP_200_OK)

        else:
            response = Response({}, status=status.HTTP_403_FORBIDDEN)
        return response
コード例 #5
0
    def get(self, request, fingerprint=None):
        f = None
        if request.user.is_authenticated():
            try:
                f = Fingerprint.valid().get(fingerprint_hash=fingerprint)

            except Fingerprint.DoesNotExist:
                return Response({}, status=status.HTTP_403_FORBIDDEN)

            return Response({'fingerprint': FingerprintSerializer(f).data},
                            status=status.HTTP_200_OK)

        return Response({}, status=status.HTTP_403_FORBIDDEN)
コード例 #6
0
def syncDbs():
    print "-- Starting syncing databases newsletters, this will set a subscript"

    fingerprints = Fingerprint.valid()

    for fingerprint in fingerprints:

        fingerprint.save() # syncs owner, creates objects as necessary via signals

        for shared in fingerprint.shared.all():
            fingerprint.setSubscription(shared, True) # sync shared owners already existing

    print "-- Finished !!"
コード例 #7
0
    def get(self, request, fingerprint=None):

        if request.user.is_authenticated():
            try:
                fp = Fingerprint.valid().get(fingerprint_hash=fingerprint)
                pubs = getListPublications(fp)

                return Response({'publications': pubs},
                                status=status.HTTP_200_OK)

            except Fingerprint.DoesNotExist:
                pass

        return Response({}, status=status.HTTP_403_FORBIDDEN)
コード例 #8
0
def syncDbs():
    print "-- Starting syncing databases newsletters, this will set a subscript"

    fingerprints = Fingerprint.valid()

    for fingerprint in fingerprints:

        fingerprint.save(
        )  # syncs owner, creates objects as necessary via signals

        for shared in fingerprint.shared.all():
            fingerprint.setSubscription(
                shared, True)  # sync shared owners already existing

    print "-- Finished !!"
コード例 #9
0
def validate_fingerprint(user, fingerprintID):
    """
    Verify if fingerprint belongs to given user
    :param user:
    :param fingerprintID:
    """
    try:
        fp = Fingerprint.valid().get(fingerprint_hash=fingerprintID)

        if user in fp.unique_users():
            return True

    except Fingerprint.DoesNotExist:
        pass

    return False
コード例 #10
0
    def handle(self, *args, **options):
        if len(args) == 1:

            with zipfile.ZipFile(args[0], "r") as zip:
                meta = json.loads(zip.read('metadata.json'),
                                  object_hook=json_util.object_hook)
                fdict = json.loads(zip.read('fingerprint.json'),
                                   object_hook=json_util.object_hook)

                new_fingerprint = Fingerprint()
                new_hash = None

                level = self.__checkFeasibility(meta, fdict)

                if level == AS_IS:
                    self.stdout.write(
                        '-- Hash/fingerprint_id are free, import as is on exported file.\n'
                    )

                    new_fingerprint.__dict__.update(fdict)

                    new_fingerprint.save()

                    self.__import(zip, args[0], new_fingerprint)

                elif level == NEW_IDS:
                    self.stdout.write(
                        '-- Hash/fingerprint_id are occupied, importing with a new id.\n'
                    )
                    new_hash = generate_hash()

                    fdict['fingerprint_hash'] = new_hash
                    del fdict['id']
                    new_fingerprint.__dict__.update(fdict)

                    new_fingerprint.save()

                    self.__addShares(meta, new_fingerprint)

                    self.__import(zip,
                                  args[0],
                                  new_fingerprint,
                                  replacing=True)

                else:  # impossible
                    self.stdout.write(
                        '-- ERROR: Impossible to import fingerprint, the questionnaire doesnt exist, or doesnt match the slug.'
                    )

        else:
            self.stdout.write(
                '-- USAGE: \n    ' +
                'python manage.py fingerprint_import <path_file>' + '\n\n')
コード例 #11
0
ファイル: api.py プロジェクト: bastiao/catalogue
    def get(self, request, *args, **kw):

        if request.user.is_authenticated():
            list_viewed = []

            try:
                eprofile = EmifProfile.objects.get(user=request.user)
            except EmifProfile.DoesNotExist:
                print "-- ERROR: Couldn't get emif profile for user"

            most_hit = Hit.objects.filter(user=request.user).values('user','hitcount__object_pk').annotate(total_hits=Count('hitcount')).order_by('-total_hits')

            i=0

            for hit in most_hit:
                try:
                    this_fingerprint = Fingerprint.valid().get(id=hit['hitcount__object_pk'])

                    if eprofile.restricted:
                        try:
                            allowed = RestrictedUserDbs.objects.get(user=request.user, fingerprint=this_fingerprint)
                        except RestrictedUserDbs.DoesNotExist:
                            restricted = RestrictedGroup.hashes(request.user)

                            if this_fingerprint.fingerprint_hash not in RestrictedGroup.hashes(request.user):
                                continue

                    list_viewed.append(
                        {
                            'hash': this_fingerprint.fingerprint_hash,
                            'name': this_fingerprint.findName(),
                            'count': hit['total_hits']
                        })
                    i+=1
                    if i == 10:
                        break

                except Fingerprint.DoesNotExist:
                    print "-- Error on hitcount for fingerprint with id "+hit['hitcount__object_pk']

            response = Response({'mostviewed': list_viewed}, status=status.HTTP_200_OK)

        else:
            response = Response({}, status=status.HTTP_403_FORBIDDEN)
        return response
コード例 #12
0
    def get(self, request, fingerprint=None):

        if request.user.is_authenticated():
            try:
                fp = Fingerprint.valid().get(fingerprint_hash=fingerprint)

                comments = Comment.objects.filter(
                    content_type__pk=ContentType.objects.get_for_model(fp).id,
                    object_pk=fp.id).order_by('-id')

                return Response(
                    {'comments': CommentSerializer(comments, many=True).data},
                    status=status.HTTP_200_OK)

            except Fingerprint.DoesNotExist:
                pass

        return Response({}, status=status.HTTP_403_FORBIDDEN)
コード例 #13
0
    def get(self, request, quest_slug=None):

        if request.user.is_authenticated():
            q = None
            if quest_slug:
                try:
                    q = Questionnaire.objects.get(slug=quest_slug)
                except Questionnaire.DoesNotExist:
                    return Response({}, status=status.HTTP_403_FORBIDDEN)

            fingerprints = FingerprintSerializer(Fingerprint.valid(
                questionnaire=q, owner=request.user),
                                                 many=True)

            return Response({'fingerprints': fingerprints.data},
                            status=status.HTTP_200_OK)

        return Response({}, status=status.HTTP_403_FORBIDDEN)
コード例 #14
0
ファイル: api.py プロジェクト: bastiao/catalogue
    def get(self, request, *args, **kw):
        self.__subscribed = []
        self.__mlt_fused = {}

        if request.user.is_authenticated():

            ordered = cache.get('recommendations_'+str(request.user.id))

            if ordered == None:
                maxx = 100
                subscriptions = FingerprintSubscription.active().filter(user=request.user)

                # first we generate the list of already subscribed databases, since they wont appear on suggestions
                for subscription in subscriptions:
                    self.__subscribed.append(subscription.fingerprint.fingerprint_hash)

                c = CoreEngine()
                for subscription in subscriptions:
                    fingerprint = subscription.fingerprint
                    this_mlt = c.more_like_this(fingerprint.fingerprint_hash, fingerprint.questionnaire.slug, maxx=maxx)

                    self.__merge(this_mlt)

                ordered = sorted(self.__mlt_fused.values(), reverse=True, key=lambda x:x['score'])[:10]

                for entry in ordered:
                    try:
                        fingerprint = Fingerprint.valid().get(fingerprint_hash=entry['id'])
                    except Fingerprint.DoesNotExist:
                        continue

                    entry['name'] = fingerprint.findName()

                    entry['href'] = 'fingerprint/'+fingerprint.fingerprint_hash+'/1/'

                cache.set('recommendations_'+str(request.user.id), ordered, 720)


            response = Response({'mlt': ordered}, status=status.HTTP_200_OK)

        else:
            response = Response({}, status=status.HTTP_403_FORBIDDEN)

        return response
コード例 #15
0
def generate_newsmessages():
    # Operations
    print "start generating weekly newsletters messages"

    if not config.newsletter:
        print 'Ignored, newsletter is disabled'

    elif settings.DEBUG == False:
        fingerprints = Fingerprint.valid()

        newsletters = Newsletter.objects.all().exclude(
            slug='emif-catalogue-newsletter')

        for fingerprint in fingerprints:
            try:
                print "Generating for " + fingerprint.fingerprint_hash
                newsletter = newsletters.get(slug=fingerprint.fingerprint_hash)

                report = generateWeekReport(fingerprint, newsletter)

                putWeekReport(report, newsletter)

            except Newsletter.DoesNotExist:
                print "-- Error: Found hash not existent on newsletters: " + fingerprint.fingerprint_hash

        print "ends generation"

        print "start sending emails"

        aggregate_emails()

        print "finished sending emails"

        print "--"
        return 0
    else:
        print 'Aborted since we are on DEBUG mode'
コード例 #16
0
ファイル: tasks.py プロジェクト: bastiao/catalogue
def generate_newsmessages():
    # Operations
    print "start generating weekly newsletters messages"

    if not config.newsletter:
        print 'Ignored, newsletter is disabled'

    elif settings.DEBUG == False:
        fingerprints = Fingerprint.valid()

        newsletters = Newsletter.objects.all().exclude(slug='emif-catalogue-newsletter')

        for fingerprint in fingerprints:
            try:
                print "Generating for "+fingerprint.fingerprint_hash
                newsletter = newsletters.get(slug=fingerprint.fingerprint_hash)

                report = generateWeekReport(fingerprint, newsletter)

                putWeekReport(report, newsletter)

            except Newsletter.DoesNotExist:
                print "-- Error: Found hash not existent on newsletters: "+fingerprint.fingerprint_hash

        print "ends generation"

        print "start sending emails"

        aggregate_emails()

        print "finished sending emails"

        print "--"
        return 0
    else:
        print 'Aborted since we are on DEBUG mode'
コード例 #17
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from fingerprint.models import Fingerprint
from searchengine.search_indexes import CoreEngine
import sys

print '\nbegin import of fingerprint hashes to database...\n'

c = CoreEngine()
results = c.search_fingerprint('*:*')
for result in results:
	fingerprint_id = result['id']
	print fingerprint_id
	if not fingerprint_id.startswith("questionaire_"):
		try:
			fp = Fingerprint(fingerprint_hash=fingerprint_id)
			fp.save()
		except:
			print fingerprint_id + ' already in DB'

print '\nend!'
コード例 #18
0
    def handle(self, *args, **options):
        Fingerprint.index_all()

        self.stdout.write('-- Finished indexing all fingerprints in SOLR.\n')
コード例 #19
0
ファイル: index_all.py プロジェクト: bioinformatics-ua/montra
    def handle(self, *args, **options):
        Fingerprint.index_all()

        self.stdout.write('-- Finished indexing all fingerprints in SOLR.\n')