Ejemplo n.º 1
0
class Pokemon(models.Model):
    name = models.CharField(max_length=255, null=True, blank=True)
    national_id = models.IntegerField(null=True, blank=True)
    evolutions = models.CharField(max_length=255, null=True, blank=True)
    catch_rate = models.IntegerField(null=True, blank=True)
    species = models.CharField(max_length=255, null=True, blank=True)
    hp = models.IntegerField(null=True, blank=True)
    attack = models.IntegerField(null=True, blank=True)
    defense = models.IntegerField(null=True, blank=True)
    sp_atk = models.IntegerField(null=True, blank=True)
    sp_def = models.IntegerField(null=True, blank=True)
    speed = models.IntegerField(null=True, blank=True)
    total = models.IntegerField(null=True, blank=True)
    # ev_yield - the ev yield for this pokemon.
    exp = models.IntegerField(null=True, blank=True)
    growth_rate = models.CharField(max_length=255, null=True, blank=True)
    weight = models.FloatField(null=True, blank=True)
    height = models.IntegerField(null=True, blank=True)
    happiness = models.IntegerField(null=True, blank=True)
    type = models.ForeignKey('main.Type', null=True)
    votes = VotableManager()
    slug = models.SlugField()

    def __unicode__(self):
        return self.name
Ejemplo n.º 2
0
class Comment(models.Model):
    user = models.ForeignKey(AUTH_USER_MODEL)
    content = models.TextField()
    create_at = models.DateTimeField(auto_now_add=True)
    update_at = models.DateTimeField(auto_now=True)

    votes = VotableManager()
Ejemplo n.º 3
0
class Sin(models.Model):
    UNISEX = 'US'
    MALE = 'M'
    FEMALE = 'F'
    GAY_MALE = 'GM'
    GAY_FEMALE = 'GF'
    TRANS_MALE = 'TM'
    TRANS_FEMALE = 'TF'

    LANGUAGE_CHOICES = settings.LANGUAGES

    TARGET_SEX = ((UNISEX, _('Unisex')), (MALE, _('Male')), (FEMALE,
                                                             _('Female')))

    text = models.CharField(max_length=255)
    cost = models.IntegerField(default=1)
    language = models.CharField(choices=LANGUAGE_CHOICES,
                                max_length=2,
                                default=settings.LANGUAGE_CODE)
    target_sex = models.CharField(choices=TARGET_SEX,
                                  default=UNISEX,
                                  max_length=2)
    sinners = models.ManyToManyField('Sinner', blank=True, editable=False)
    votes = VotableManager()

    def get_sinners_count(self):
        return self.sinners.count()

    def __str__(self):
        return "{}:{}:{}".format(self.text[:16], self.language, self.cost)
Ejemplo n.º 4
0
class Documentstorage(VoteModel, models.Model):
    hash = models.CharField(max_length=255, blank=True, null=True)
    datasource = models.IntegerField()
    datasources_type = models.IntegerField(blank=True, null=True)
    url = models.CharField(max_length=320)
    title = models.TextField()
    date = models.DateTimeField()
    author = models.TextField(blank=True, null=True)
    abstract = models.TextField(blank=True, null=True)
    text = models.TextField(blank=True, null=True)
    language = models.IntegerField(blank=True, null=True, default=None)
    filepath = models.CharField(max_length=320)
    slug = models.CharField(max_length=320)
    votes = VotableManager()

    class Meta:
        managed = True
        db_table = 'documentstorage'

    def get_total_votes(self):
        total = self.votes.count()
        return int(total)

    def generate_absolute_url(self):
        url = "/document/" + self.slug
        return url
Ejemplo n.º 5
0
class Comment(models.Model):
    user_id = models.BigIntegerField()
    content = models.TextField()
    num_vote = models.IntegerField(default=0)
    create_at = models.DateTimeField(auto_now_add=True)
    update_at = models.DateTimeField(auto_now=True)

    votes = VotableManager()
Ejemplo n.º 6
0
class CustomVoteComment(models.Model):
    user_id = models.BigIntegerField()
    content = models.TextField()
    num_vote = models.PositiveIntegerField(default=0)
    create_at = models.DateTimeField(auto_now_add=True)
    update_at = models.DateTimeField(auto_now=True)

    custom_votes = VotableManager(extra_field='num_vote')
Ejemplo n.º 7
0
class Post(models.Model):
    submitter = models.ForeignKey(User)
    date_submitted = models.DateTimeField(auto_now_add=True)
    score = models.IntegerField(default=0)
    text = models.TextField(max_length=200)

    votes = VotableManager()

    def __str__(self):
        return '{}: {}'.format(self.submitter, self.date_submitted)
Ejemplo n.º 8
0
class VoteModel(models.Model):
    vote_score = models.DecimalField(default=0,
                                     decimal_places=8,
                                     max_digits=16,
                                     db_index=True)
    num_vote_up = models.PositiveIntegerField(default=0, db_index=True)
    num_vote_down = models.PositiveIntegerField(default=0, db_index=True)
    votes = VotableManager()

    class Meta:
        abstract = True

    def save(self, *args, **kwargs):
        self.vote_score = self.calculate_vote_score
        super(VoteModel, self).save(*args, **kwargs)

    @property
    def calculate_vote_score(self):
        votes = self.num_vote_down + self.num_vote_up
        if votes == 0:
            return 0

        #confidence level
        z = 1.44  #1.44 = 85%, 1.96 = 95%
        p = float(self.num_vote_up) / votes

        left = p + 1 / (2 * votes) * z * z
        right = z * sqrt(p * (1 - p) / votes + z * z / (4 * votes * votes))
        under = 1 + 1 / votes * z * z

        result = (left - right) / under
        return round(Decimal.from_float(result), 8)

    @property
    def is_voted_up(self):
        try:
            return self._is_voted_up
        except AttributeError:
            return False

    @is_voted_up.setter
    def is_voted_up(self, value):
        self._is_voted_up = value

    @property
    def is_voted_down(self):
        try:
            return self._is_voted_down
        except AttributeError:
            return False

    @is_voted_down.setter
    def is_voted_down(self, value):
        self._is_voted_down = value
Ejemplo n.º 9
0
class CommentManga(models.Model):
    comment = models.TextField()
    user = models.ForeignKey('Members', null=True, blank=True)
    manga = models.ForeignKey('Manga', null=True, blank=True)
    added = models.DateTimeField(auto_now=True, null=True, blank=True)
    edited = models.DateTimeField(null=True, blank=True)
    votes = VotableManager()

    class Meta:
        ordering = ['-edited', '-added']

    def __unicode__(self):
        return ('{}-{}'.format(self.user, self.comment[:20]))
Ejemplo n.º 10
0
class Publications(models.Model):
    votes = VotableManager(blank=True)
    document_id = models.TextField(blank=True)
    project_title = models.TextField(blank=True)
    department_name = models.TextField(blank=True)
    name_1 = models.TextField(blank=True)
    designation_1 = models.TextField(blank=True)
    email_1 = models.TextField(blank=True)
    address_1 = models.TextField(blank=True)
    phone_1 = models.TextField(blank=True)
    fax_1 = models.TextField(blank=True)
    mobile_1 = models.TextField(blank=True)
    name_2 = models.TextField(blank=True)
    designation_2 = models.TextField(blank=True)
    email_2 = models.TextField(blank=True)
    address_2 = models.TextField(blank=True)
    phone_2 = models.TextField(blank=True)
    fax_2 = models.TextField(blank=True)
    mobile_2 = models.TextField(blank=True)
    category = models.TextField(blank=True)
    nature = models.TextField(blank=True)
    description = models.TextField(blank=True)
    date = models.TextField(blank=True)
    url = models.TextField(blank=True)
    business_model = models.TextField(blank=True)
    no_process = models.TextField(blank=True)
    beneficiary_1 = models.TextField(blank=True)
    beneficiary_2 = models.TextField(blank=True)
    beneficiary_3 = models.TextField(blank=True)
    transaction = models.TextField(blank=True)
    benefit_1 = models.TextField(blank=True)
    benefit_2 = models.TextField(blank=True)
    benefit_3 = models.TextField(blank=True)
    process_1 = models.TextField(blank=True)
    process_2 = models.TextField(blank=True)
    process_3 = models.TextField(blank=True)
    database = models.TextField(blank=True)
    operating = models.TextField(blank=True)
    web_server = models.TextField(blank=True)
    prime_agency = models.TextField(blank=True)
    network_arrangement = models.TextField(blank=True)
    datacenter = models.TextField(blank=True)
    csc = models.TextField(blank=True)
    formal_document = models.TextField(blank=True)
    implementation = models.TextField(blank=True)
    no_training = models.TextField(blank=True)
    sector = models.TextField(blank=True)
    sub_sector = models.TextField(blank=True)
    state = models.TextField(blank=True)
    attachment = models.FileField(upload_to='%Y/%m/%d', blank=True)
Ejemplo n.º 11
0
class Startup(models.Model):
    name = models.CharField(max_length=30)
    slug = models.SlugField(blank=True) #unique=True
    # founders = models.CharField(max_length=100, default=True)
    # investors = models.CharField(max_length=200, default=True)
    # # total_funding = models.DecimalField(max_digits=50, decimal_places=1, default=0)
    # latest_funding = models.DecimalField(max_digits=50, decimal_places=1, default=0)
    description = models.TextField()
    votes = VotableManager()


    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('startup_edit', kwargs={'pk': self.pk})
Ejemplo n.º 12
0
class Post(models.Model):
    title = models.CharField(max_length=200)
    body = models.TextField()
    parent = models.ForeignKey("Post",
                               blank=True,
                               null=True,
                               related_name="replies")
    owner = models.ForeignKey("accounts.Account")

    tags = tagulous.models.TagField(force_lowercase=True)
    votes = VotableManager()

    ordinal = models.IntegerField(default=0)

    completed = models.BooleanField(default=False)

    date_created = models.DateTimeField(auto_now_add=True)
    date_modified = models.DateTimeField(auto_now=True)

    objects = PostManager()

    def __str__(self):
        return self.title

    class Meta:
        ordering = ['ordinal']

    @models.permalink
    def get_absolute_url(self):
        return ('post_detail', (), {'pk': self.id})

    @property
    def vote_count(self):
        return self.votes.count()

    @property
    def reply_count(self):
        return Post.objects.filter(parent=self).count()

    def next_ordinal(self):
        if self.replies.count() > 0:
            return self.replies.order_by('-ordinal')[0].ordinal + 1
        else:
            return 0
Ejemplo n.º 13
0
class Designer(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True)
    username = models.CharField(max_length=25, unique=True)
    display_name = models.CharField(max_length=25)
    twitter = models.CharField(max_length=15)
    bio = models.TextField(max_length=145, blank=True, default="")
    avatar = models.ImageField(upload_to='img',
                               default='img/default_profile_pic.jpg')
    votes = VotableManager()
    available = models.BooleanField(default=False)
    thumbnail_price = models.FloatField(null=True)
    channel_art_price = models.FloatField(null=True)
    monthly = models.BooleanField(default=False)
    promoted = models.BooleanField(default=False)
    date_joined = models.DateTimeField(default=timezone.now)
    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)
    is_designer = models.BooleanField(default=True)

    objects = UserManager()

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = ["display_name", "username"]

    def __str__(self):
        return "@{}".format(self.username)

    def get_short_name(self):
        return self.display_name

    def get_long_name(self):
        return "{} (@{})".format(self.display_name, self.username)

    def is_available(self):
        if self.available:
            return '{} is available to work.'.format(self.display_name)
        else:
            return '{} is not available to work.'.format(self.display_name)

    def is_monthly(self):
        if self.monthly:
            return '{} does monthly deals.'.format(self.display_name)
        else:
            return '{} does not do monthly deals.'.format(self.display_name)
Ejemplo n.º 14
0
class Question(models.Model):
    topics = models.ManyToManyField('questions.Topic',
                                    related_name="questions")
    title = models.CharField(max_length=50)
    body = models.CharField(max_length=200)
    author = models.ForeignKey(User, default="")
    slug = models.SlugField(default="")
    created_at = models.DateTimeField(default=timezone.now)
    votes = VotableManager()

    # Compute the nicely printable string representation of an object.
    def __str__(self):
        return self.title

    # Calculate the URL for an object. Return a string, which can be used to refer to the object over HTTP
    def get_absolute_url(self):
        return reverse("question", kwargs={"pk": self.id})

    def votes_count(self):
        return self.votes_count()
Ejemplo n.º 15
0
class Option(models.Model):
    title = models.CharField(max_length=1000, default='')
    avator = models.ImageField(upload_to='option/%Y/%m/')
    abstract = models.TextField()
    author = models.CharField(max_length=50, default='')
    description = models.CharField(max_length=1000)
    pub_time = models.DateField()
    content = UEditorField(default="",
                           toolbars="full",
                           imagePath="ueditor/images/%(year)s/%(month)s/",
                           filePath="ueditor/file/%(year)s/%(month)s/")
    votes = VotableManager()
    building = models.ForeignKey(Building)

    def __str__(self):
        return self.title

    def count_vote(self):
        return self.votes.count()

    count_vote.allow_tags = True
    count_vote.short_description = '投票数'
Ejemplo n.º 16
0
class Post(VoteModel, models.Model):
    votes = VotableManager()
    user = models.ForeignKey(User,
                             on_delete=models.CASCADE,
                             related_name='post')
    picture = models.ImageField(upload_to='pictures/', blank=True)
    caption = models.TextField(max_length=140)
    upvote_count = models.PositiveIntegerField(default=0)
    downvote_count = models.PositiveIntegerField(default=0)
    pub_date = models.DateTimeField(auto_now_add=True)

    # comments = models.ManyToManyField('Review', related_name="comments")

    class Meta:
        ordering = ['pub_date']

    def save_post(self):
        self.save()

    @classmethod
    def display_users_posts(cls, id):
        posts = cls.objects.filter(user_id=id)
        return posts

    @classmethod
    def display_posts(cls):
        posts = cls.objects.all()
        return posts

    @property
    def image_url(self):
        if self.image and hasattr(self.image, 'url'):
            return self.image.url

    @classmethod
    def get_single_post(cls, pk):
        post = cls.objects.get(pk=pk)
        # upvote = post.votes.up(id=id)
        return post
Ejemplo n.º 17
0
class VoteModel(models.Model):
    vote_score = models.IntegerField(default=0, db_index=True)
    num_vote_up = models.PositiveIntegerField(default=0, db_index=True)
    num_vote_down = models.PositiveIntegerField(default=0, db_index=True)
    votes = VotableManager()

    class Meta:
        abstract = True

    def save(self, *args, **kwargs):
        self.vote_score = self.calculate_vote_score
        super(VoteModel, self).save(*args, **kwargs)

    @property
    def calculate_vote_score(self):
        return self.num_vote_up - self.num_vote_down

    @property
    def is_voted_up(self):
        try:
            return self._is_voted_up
        except AttributeError:
            return False

    @is_voted_up.setter
    def is_voted_up(self, value):
        self._is_voted_up = value

    @property
    def is_voted_down(self):
        try:
            return self._is_voted_down
        except AttributeError:
            return False

    @is_voted_down.setter
    def is_voted_down(self, value):
        self._is_voted_down = value
Ejemplo n.º 18
0
class Restaurant(models.Model):
    # The identifier field is used for to detect and prevent duplicated
    # during the import process
    identifier = models.CharField(max_length=256)
    name = models.CharField(max_length=256)
    address = models.CharField(max_length=512, blank=True, null=True)
    telephone = models.CharField(max_length=128, blank=True, null=True)
    website = models.URLField(blank=True, null=True)
    picture = models.ImageField(blank=True, null=True)
    active = models.BooleanField(blank=True, default=True)
    description = models.TextField(blank=True, null=True)
    created = models.DateTimeField(auto_now_add=True, editable=False)
    rating = models.FloatField(blank=True, null=True)
    votes = VotableManager()

    class Meta:
        ordering = ['id']

    def __unicode__(self):
        return u'%s (%s)' % (slugify(self.name), self.id)

    def votes_count(self):
        return self.votes.count()
Ejemplo n.º 19
0
class Asset(models.Model):
    class Meta:
        verbose_name = _("asset")
        verbose_name_plural = _("assets")

    author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_("author"))
    application = models.ForeignKey('Application', on_delete=models.CASCADE, verbose_name=_("application"))
    component = models.ForeignKey('Component', on_delete=models.CASCADE, null=True, verbose_name=_("component"))
    license = models.ForeignKey('License', on_delete=models.SET_NULL, null=True, blank=False, verbose_name=_("license"))
    original_author = models.CharField(max_length=255, null=True, blank=True, verbose_name=_("original author"))
    creation_date = models.DateTimeField(null=True, blank=True, verbose_name=_("Originally created"))
    title = models.CharField(max_length=255, verbose_name=_("title"))
    notes = models.TextField(null=True, verbose_name=_("description"))
    image = models.ImageField(upload_to=get_thumbnail_path, verbose_name=_("thumbnail"), null=True, blank=True)
    big_image = models.ImageField(upload_to=get_big_image_path, verbose_name=_("larger image"), null=True, blank=True)
    data = models.FileField(upload_to=get_data_path, verbose_name=_("data file"))
    url = models.URLField(null=True, blank=True, verbose_name=_("URL"))
    pub_date = models.DateTimeField(verbose_name=_("date published"))
    version = VersionField(null=True, blank=True, number_bits=[8,8,8,8], verbose_name=_("asset version"))
    app_version_min = VersionField(verbose_name=_("Minimum compatible application version"), null=True, blank=True, number_bits=[8,8,8,8])
    app_version_max = VersionField(verbose_name=_("Maximum compatible application version"), null=True, blank=True, number_bits=[8,8,8,8])
    tags = TaggableManager(blank=True, verbose_name=_("tags"))
    num_votes = models.PositiveIntegerField(default=0)
    votes = VotableManager(extra_field='num_votes')

    def clean(self):
        if self.component and self.data and not self.component.is_filename_allowed(self.data.name):
            raise ValidationError(_("It is not allowed to upload files of this type for this component"))

        if self.component and not self.component.big_image_allowed:
            if self.big_image:
                raise ValidationError(_("It is not allowed to upload big images for this component"))

        if self.component and self.component.thumbnail_mandatory:
            if not self.image and not (self.component and self.component.thumbnailer_name):
                raise ValidationError(_("You should upload thumbnail file"))

        super(Asset, self).clean()

    def save(self, *args, **kwargs):
        if self.data and not self.image and self.component:
            thumbnailer = self.component.thumbnailer()
            auto_thumbnail = None
            if thumbnailer:
                auto_thumbnail = thumbnailer.make_thumbnail(self.data)
            elif self.big_image:
                auto_thumbnail = thumbnail_from_big_image(self.big_image, size=self.component.max_thumbnail_size)
            if auto_thumbnail:
                # pass save=False because otherwise it would call save() recursively
                self.image.save("auto_thumbnail.png", auto_thumbnail, save=False)

        super(Asset,self).save(*args, **kwargs)

    def get_tags(self):
        return ", ".join([tag.name for tag in self.tags.all()])

    def get_app_versions(self):
        if not self.app_version_min and not self.app_version_max:
            return pgettext_lazy("application version", "any")
        if self.app_version_min and not self.app_version_max:
            return pgettext_lazy("application version", ">= {}").format(self.app_version_min)
        if not self.app_version_min and self.app_version_max:
            return pgettext_lazy("application version", "<= {}").format(self.app_version_max)
        return pgettext_lazy("application version", ">= {0} and <= {1}").format(self.app_version_min, self.app_version_max)

    def get_filename(self):
        return basename(self.data.name)

    def get_comments_count(self):
        ct = ContentType.objects.get_for_model(Asset)
        return Comment.objects.filter(content_type=ct, object_pk=self.pk).count()

    def __str__(self):
        result = ""
        if self.application:
            result += str(self.application) + " "
        if self.component:
            result += self.component.title + " "
        result += self.title
        return result.encode('utf-8')

    def __unicode__(self):
        result = ""
        if self.application:
            result += str(self.application) + " "
        if self.component:
            result += self.component.title + " "
        result += self.title
        return result
Ejemplo n.º 20
0
from __future__ import absolute_import
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.contrib import messages
from django.db import transaction
from django.http import Http404
from .forms import UserForm, ProfileForm, PostForm, ProfilePicForm, NewCommentsForm
from .models import Posts, Like, Profile, Follow, Comments
import datetime as dt
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from vote.managers import VotableManager

votes = VotableManager()


def about(request):
    return render(request, 'registration/aboutus.html')


@login_required(login_url='/accounts/register/')
def index(request):
    current_user = request.user
    post = Posts.get_posts()

    # follow other users
    return render(request, 'index.html', {"post": post, "user": current_user})

Ejemplo n.º 21
0
class HasVotes(models.Model):
    votes = VotableManager()